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.apache.myfaces.tobago.context.ThemeImpl;
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  
26  import java.net.URL;
27  import java.util.ArrayList;
28  import java.util.HashMap;
29  import java.util.List;
30  import java.util.Map;
31  import java.util.Properties;
32  
33  public class TobagoConfigFragment {
34  
35    private static final Logger LOG = LoggerFactory.getLogger(TobagoConfigFragment.class);
36  
37    private String name;
38    private List<String> before;
39    private List<String> after;
40  
41    private List<String> supportedThemeNames;
42    private String defaultThemeName;
43    private List<String> resourceDirs;
44    private RenderersConfig renderersConfig;
45    private Boolean createSessionSecret;
46    private Boolean checkSessionSecret;
47    private Boolean preventFrameAttacks;
48    private ContentSecurityPolicy contentSecurityPolicy;
49    private Boolean setNosniffHeader;
50    private List<ThemeImpl> themeDefinitions;
51    private URL url;
52    private String sanitizerClass;
53    private Properties sanitizerProperties;
54    private Map<String, String> mimeTypes;
55  
56    public TobagoConfigFragment() {
57      before = new ArrayList<String>();
58      after = new ArrayList<String>();
59      supportedThemeNames = new ArrayList<String>();
60      resourceDirs = new ArrayList<String>();
61      themeDefinitions = new ArrayList<ThemeImpl>();
62      mimeTypes = new HashMap<String, String>();
63    }
64  
65    public void addSupportedThemeName(final String name) {
66      supportedThemeNames.add(name);
67    }
68  
69    public List<String> getSupportedThemeNames() {
70      return supportedThemeNames;
71    }
72  
73    public String getDefaultThemeName() {
74      return defaultThemeName;
75    }
76  
77    public void setDefaultThemeName(final String defaultThemeName) {
78      this.defaultThemeName = defaultThemeName;
79    }
80  
81    public void addResourceDir(final String resourceDir) {
82      if (!resourceDirs.contains(resourceDir)) {
83        if (LOG.isInfoEnabled()) {
84          LOG.info("adding resourceDir = '{}'", resourceDir);
85        }
86        resourceDirs.add(resourceDir);
87      }
88    }
89  
90    public List<String> getResourceDirs() {
91      return resourceDirs;
92    }
93  
94    public RenderersConfig getRenderersConfig() {
95      return renderersConfig;
96    }
97  
98    public void setRenderersConfig(final RenderersConfig renderersConfig) {
99      this.renderersConfig = renderersConfig;
100   }
101 
102   public String getName() {
103     return name;
104   }
105 
106   public void setName(final String name) {
107     this.name = name;
108   }
109 
110   public List<String> getBefore() {
111     return before;
112   }
113 
114   public void addBefore(final String name) {
115     before.add(name);
116   }
117 
118   public List<String> getAfter() {
119     return after;
120   }
121 
122   public void addAfter(final String name) {
123     after.add(name);
124   }
125 
126   public void addThemeDefinition(final ThemeImpl theme) {
127     themeDefinitions.add(theme);
128   }
129 
130   public List<ThemeImpl> getThemeDefinitions() {
131     return themeDefinitions;
132   }
133 
134   public Boolean getCreateSessionSecret() {
135     return createSessionSecret;
136   }
137 
138   public void setCreateSessionSecret(final String createSessionSecret) {
139     this.createSessionSecret = Boolean.valueOf(createSessionSecret);
140   }
141 
142   public Boolean getCheckSessionSecret() {
143     return checkSessionSecret;
144   }
145 
146   public void setCheckSessionSecret(final String checkSessionSecret) {
147     this.checkSessionSecret = Boolean.valueOf(checkSessionSecret);
148   }
149 
150   public Boolean getPreventFrameAttacks() {
151     return preventFrameAttacks;
152   }
153 
154   public void setPreventFrameAttacks(final Boolean preventFrameAttacks) {
155     this.preventFrameAttacks = preventFrameAttacks;
156   }
157 
158   public ContentSecurityPolicy getContentSecurityPolicy() {
159     return contentSecurityPolicy;
160   }
161 
162   public void setContentSecurityPolicy(final ContentSecurityPolicy contentSecurityPolicy) {
163     this.contentSecurityPolicy = contentSecurityPolicy;
164   }
165 
166   public Boolean getSetNosniffHeader() {
167     return setNosniffHeader;
168   }
169 
170   public void setSetNosniffHeader(final Boolean setNosniffHeader) {
171     this.setNosniffHeader = setNosniffHeader;
172   }
173 
174   public URL getUrl() {
175     return url;
176   }
177 
178   public void setUrl(final URL url) {
179     this.url = url;
180   }
181 
182   public String getSanitizerClass() {
183     return sanitizerClass;
184   }
185 
186   public void setSanitizerClass(String sanitizerClass) {
187     this.sanitizerClass = sanitizerClass;
188   }
189 
190   public Properties getSanitizerProperties() {
191     return sanitizerProperties;
192   }
193 
194   public void setSanitizerProperties(Properties sanitizerProperties) {
195     this.sanitizerProperties = sanitizerProperties;
196   }
197 
198   public void addMimeType(String extension, String type) {
199     this.mimeTypes.put(extension, type);
200   }
201 
202   public Map<String, String> getMimeTypes() {
203     return mimeTypes;
204   }
205 
206   @Override
207   public String toString() {
208     return name != null ? name : "(id=" + System.identityHashCode(this) + ")";
209   }
210 }