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