View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.internal.config;
21  
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  
25  import java.io.Serializable;
26  import java.util.ArrayList;
27  import java.util.Collection;
28  import java.util.HashMap;
29  import java.util.List;
30  import java.util.Map;
31  
32  public class RenderersConfigImpl implements RenderersConfig, Serializable {
33  
34    private static final long serialVersionUID = 1L;
35  
36    private static final Logger LOG = LoggerFactory.getLogger(RenderersConfigImpl.class);
37  
38    private Map<String, RendererConfig> rendererMap = new HashMap<String, RendererConfig>();
39  
40    private boolean merged = false;
41  
42    public boolean isMerged() {
43      return merged;
44    }
45  
46    public void setMerged(boolean merged) {
47      this.merged = merged;
48    }
49  
50    public List<RendererConfig> getRendererConfigs() {
51      final ArrayList<RendererConfig> result = new ArrayList<RendererConfig>();
52      result.addAll(rendererMap.values());
53      return result;
54    }
55  
56    public void addRenderer(RendererConfig rendererConfig) {
57      final String name = rendererConfig.getName();
58      if (rendererMap.containsKey(name)) {
59        rendererMap.get(name).merge(rendererConfig);
60      } else {
61        rendererMap.put(name, rendererConfig);
62      }
63    }
64  
65    public boolean isMarkupSupported(String rendererName, String markup) {
66      if (LOG.isDebugEnabled()) {
67        LOG.debug("Calling isMarkupSupported('{}', '{}')", rendererName, markup);
68      }
69      RendererConfig rendererConfig = rendererMap.get(rendererName);
70      if (rendererConfig != null) {
71        return rendererConfig.contains(markup);
72      } else {
73        LOG.error("Calling isMarkupSupported('{}', '{}'), but no configuration found.", rendererName, markup);
74        return false;
75      }
76    }
77  
78    public void merge(RenderersConfig renderersConfig, boolean override) {
79      Collection<RendererConfig> renderers = renderersConfig.getRendererConfigs();
80      for (RendererConfig rendererConfig : renderers) {
81        addRenderer(rendererConfig);
82      }
83    }
84  
85    public String toString() {
86      return rendererMap.toString();
87    }
88  }