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  package org.apache.maven.doxia.siterenderer;
20  
21  import java.io.File;
22  import java.util.ArrayList;
23  import java.util.Collections;
24  import java.util.Date;
25  import java.util.List;
26  import java.util.Locale;
27  import java.util.Map;
28  
29  import org.apache.maven.artifact.Artifact;
30  import org.apache.maven.doxia.parser.Parser;
31  import org.apache.maven.doxia.site.SiteModel;
32  import org.apache.maven.doxia.site.skin.SkinModel;
33  import org.codehaus.plexus.util.ReaderFactory;
34  import org.codehaus.plexus.util.WriterFactory;
35  
36  /**
37   * Context for a site rendering.
38   *
39   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
40   */
41  public class SiteRenderingContext {
42  
43      public static class SiteDirectory {
44          private File path;
45          private boolean editable;
46  
47          public SiteDirectory(File path, boolean editable) {
48              this.path = path;
49              this.editable = editable;
50          }
51  
52          public File getPath() {
53              return path;
54          }
55  
56          public boolean isEditable() {
57              return editable;
58          }
59      }
60  
61      private String inputEncoding = ReaderFactory.FILE_ENCODING;
62  
63      private String outputEncoding = WriterFactory.UTF_8;
64  
65      private String templateName;
66  
67      private ClassLoader templateClassLoader;
68  
69      private Map<String, ?> templateProperties;
70  
71      private Locale locale = Locale.ROOT;
72  
73      private List<Locale> siteLocales = new ArrayList<>();
74  
75      private SiteModel siteModel;
76  
77      private String defaultTitle;
78  
79      private Artifact skin;
80  
81      private SkinModel skinModel;
82  
83      private File rootDirectory;
84  
85      private List<SiteDirectory> siteDirectories = new ArrayList<>();
86  
87      private Map<String, String> moduleExcludes;
88  
89      private boolean validate;
90  
91      private Date publishDate;
92  
93      private File processedContentOutput;
94  
95      private ParserConfigurator parserConfigurator;
96  
97      /**
98       * If input documents should be validated before parsing.
99       * By default no validation is performed.
100      *
101      * @return true if validation is switched on.
102      * @since 1.1.3
103      */
104     public boolean isValidate() {
105         return validate;
106     }
107 
108     /**
109      * Switch on/off validation.
110      *
111      * @param validate true to switch on validation.
112      * @since 1.1.3
113      */
114     public void setValidate(boolean validate) {
115         this.validate = validate;
116     }
117 
118     /**
119      * <p>Getter for the field <code>templateName</code>.</p>
120      *
121      * @return a {@link java.lang.String} object.
122      */
123     public String getTemplateName() {
124         return templateName;
125     }
126 
127     /**
128      * <p>Getter for the field <code>templateClassLoader</code>.</p>
129      *
130      * @return a {@link java.lang.ClassLoader} object.
131      */
132     public ClassLoader getTemplateClassLoader() {
133         return templateClassLoader;
134     }
135 
136     /**
137      * <p>Setter for the field <code>templateClassLoader</code>.</p>
138      *
139      * @param templateClassLoader a {@link java.lang.ClassLoader} object.
140      */
141     public void setTemplateClassLoader(ClassLoader templateClassLoader) {
142         this.templateClassLoader = templateClassLoader;
143     }
144 
145     /**
146      * <p>Getter for the field <code>templateProperties</code>.</p>
147      *
148      * @return a {@link java.util.Map} object.
149      */
150     public Map<String, ?> getTemplateProperties() {
151         return templateProperties;
152     }
153 
154     /**
155      * <p>Setter for the field <code>templateProperties</code>.</p>
156      *
157      * @param templateProperties a {@link java.util.Map} object.
158      */
159     public void setTemplateProperties(Map<String, ?> templateProperties) {
160         this.templateProperties = Collections.unmodifiableMap(templateProperties);
161     }
162 
163     /**
164      * <p>Getter for the field <code>locale</code>.</p>
165      *
166      * @return a {@link java.util.Locale} object.
167      */
168     public Locale getLocale() {
169         return locale;
170     }
171 
172     /**
173      * <p>Setter for the field <code>locale</code>.</p>
174      *
175      * @param locale a {@link java.util.Locale} object.
176      */
177     public void setLocale(Locale locale) {
178         this.locale = locale;
179     }
180 
181     /**
182      * <p>Getter for the field <code>siteLocales</code> -
183      * a list of locales available for this site context.</p>
184      *
185      * @return a {@link java.util.List} object with {@link java.util.Locale} objects.
186      */
187     public List<Locale> getSiteLocales() {
188         return siteLocales;
189     }
190 
191     /**
192      * <p>Adds passed locales to the list of site locales.</p>
193      *
194      * @param locales List of {@link java.util.Locale} objects to add to the site locales list.
195      */
196     public void addSiteLocales(List<Locale> locales) {
197         siteLocales.addAll(locales);
198     }
199 
200     /**
201      * <p>Getter for the field <code>siteModel</code>.</p>
202      *
203      * @return a {@link org.apache.maven.doxia.site.SiteModel} object.
204      */
205     public SiteModel getSiteModel() {
206         return siteModel;
207     }
208 
209     /**
210      * <p>Setter for the field <code>siteModel</code>.</p>
211      *
212      * @param siteModel a {@link org.apache.maven.doxia.site.SiteModel} object.
213      */
214     public void setSiteModel(SiteModel siteModel) {
215         this.siteModel = siteModel;
216     }
217 
218     /**
219      * <p>Setter for the field <code>defaultTitle</code>.</p>
220      *
221      * @param defaultTitle a {@link java.lang.String} object.
222      */
223     public void setDefaultTitle(String defaultTitle) {
224         this.defaultTitle = defaultTitle;
225     }
226 
227     /**
228      * <p>Getter for the field <code>defaultTitle</code>.</p>
229      *
230      * @return a {@link java.lang.String} object.
231      */
232     public String getDefaultTitle() {
233         return defaultTitle;
234     }
235 
236     /**
237      * <p>Getter for the field <code>skin</code>.</p>
238      *
239      * @return a {@link Artifact} object.
240      */
241     public Artifact getSkin() {
242         return skin;
243     }
244 
245     /**
246      * <p>Setter for the field <code>skinJarFile</code>.</p>
247      *
248      * @param skin an {@link Artifact} object.
249      */
250     public void setSkin(Artifact skin) {
251         this.skin = skin;
252     }
253 
254     /**
255      * <p>Getter for the field <code>skinModel</code>.</p>
256      *
257      * @return a {@link SkinModel} object.
258      */
259     public SkinModel getSkinModel() {
260         return skinModel;
261     }
262 
263     /**
264      * <p>Setter for the field <code>skinModel</code>.</p>
265      *
266      * @param skinModel a {@link SkinModel} object.
267      */
268     public void setSkinModel(SkinModel skinModel) {
269         this.skinModel = skinModel;
270     }
271 
272     /**
273      * <p>Setter for the field <code>templateName</code>.</p>
274      *
275      * @param templateName a {@link java.lang.String} object.
276      */
277     public void setTemplateName(String templateName) {
278         this.templateName = templateName;
279     }
280 
281     /**
282      * @deprecated use {@link #addSiteDirectory(SiteDirectory)}
283      */
284     @Deprecated
285     public void addSiteDirectory(File siteDirectory) {
286         addSiteDirectory(new SiteDirectory(siteDirectory, true));
287     }
288 
289     /**
290      * Add a site directory, expected to have a Doxia Site layout, ie one directory per Doxia parser module containing
291      * files with parser extension. Typical values are <code>src/site</code> or <code>target/generated-site</code>.
292      *
293      * @param siteDirectory a {@link SiteDirectory} object.
294      * @since 2.0.0
295      */
296     public void addSiteDirectory(SiteDirectory siteDirectory) {
297         this.siteDirectories.add(siteDirectory);
298     }
299 
300     /**
301      * <p>Getter for the field <code>siteDirectories</code>.</p>
302      *
303      * @return List of site directories.
304      */
305     public List<SiteDirectory> getSiteDirectories() {
306         return siteDirectories;
307     }
308 
309     /**
310      * <p>Getter for the field <code>moduleExcludes</code>.</p>
311      *
312      * @return a map defining exclude patterns (comma separated) by parser id.
313      */
314     public Map<String, String> getModuleExcludes() {
315         return moduleExcludes;
316     }
317 
318     /**
319      * <p>Setter for the field <code>moduleExcludes</code>.</p>
320      *
321      * @param moduleExcludes a {@link java.util.Map} object.
322      */
323     public void setModuleExcludes(Map<String, String> moduleExcludes) {
324         this.moduleExcludes = moduleExcludes;
325     }
326 
327     /**
328      * <p>Getter for the field <code>inputEncoding</code>.</p>
329      *
330      * @return a {@link java.lang.String} object.
331      */
332     public String getInputEncoding() {
333         return inputEncoding;
334     }
335 
336     /**
337      * <p>Setter for the field <code>inputEncoding</code>.</p>
338      *
339      * @param inputEncoding a {@link java.lang.String} object.
340      */
341     public void setInputEncoding(String inputEncoding) {
342         this.inputEncoding = inputEncoding;
343     }
344 
345     /**
346      * <p>Getter for the field <code>outputEncoding</code>.</p>
347      *
348      * @return a {@link java.lang.String} object.
349      */
350     public String getOutputEncoding() {
351         return outputEncoding;
352     }
353 
354     /**
355      * <p>Setter for the field <code>outputEncoding</code>.</p>
356      *
357      * @param outputEncoding a {@link java.lang.String} object.
358      */
359     public void setOutputEncoding(String outputEncoding) {
360         this.outputEncoding = outputEncoding;
361     }
362 
363     /**
364      * <p>If you want to specify a specific publish date instead of the current date.</p>
365      *
366      * @return the publish date, can be {@code null}
367      */
368     public Date getPublishDate() {
369         return publishDate;
370     }
371 
372     /**
373      * <p>Specify a specific publish date instead of the current date.</p>
374      *
375      * @param publishDate the publish date
376      */
377     public void setPublishDate(Date publishDate) {
378         this.publishDate = publishDate;
379     }
380 
381     /**
382      * Directory where to save content after Velocity processing (<code>*.vm</code>), but before parsing it with Doxia.
383      *
384      * @return not null if the documents are to be saved
385      * @since 1.7
386      */
387     public File getProcessedContentOutput() {
388         return processedContentOutput;
389     }
390 
391     /**
392      * Where to (eventually) save content after Velocity processing (<code>*.vm</code>), but before parsing it with
393      * Doxia?
394      *
395      * @param processedContentOutput not null if the documents are to be saved
396      * @since 1.7
397      */
398     public void setProcessedContentOutput(File processedContentOutput) {
399         this.processedContentOutput = processedContentOutput;
400     }
401 
402     /**
403      * Root directory, to calculate relative path to every site directories.
404      * Corresponds to the <code>pom.xml</code> directory for Maven build.
405      *
406      * @return the root directory
407      * @since 1.8
408      */
409     public File getRootDirectory() {
410         return rootDirectory;
411     }
412 
413     /**
414      * Set the root directory.
415      *
416      * @param rootDirectory the root directory
417      * @since 1.8
418      */
419     public void setRootDirectory(File rootDirectory) {
420         this.rootDirectory = rootDirectory;
421     }
422 
423     /**
424      * Return the configurator for {@link Parser parsers}.
425      * @return the parser configurator (may be {@code null} in which case the default configuration is applied)
426      * @since 2.0.0
427      */
428     public ParserConfigurator getParserConfigurator() {
429         return parserConfigurator;
430     }
431 
432     /**
433      * Set the configurator to use for {@link Parser parsers}.
434      * @param parserConfigurator the configurator
435      * @since 2.0.0
436      */
437     public void setParserConfigurator(ParserConfigurator parserConfigurator) {
438         this.parserConfigurator = parserConfigurator;
439     }
440 }