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