View Javadoc
1   package org.apache.maven.doxia.siterenderer;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.util.ArrayList;
24  import java.util.Collections;
25  import java.util.Date;
26  import java.util.List;
27  import java.util.Locale;
28  import java.util.Map;
29  
30  import org.apache.maven.artifact.Artifact;
31  import org.apache.maven.doxia.site.decoration.DecorationModel;
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      private String inputEncoding = ReaderFactory.FILE_ENCODING;
44  
45      private String outputEncoding = WriterFactory.UTF_8;
46  
47      private String templateName;
48  
49      private ClassLoader templateClassLoader;
50  
51      private Map<String, ?> templateProperties;
52  
53      private Locale locale = Locale.getDefault();
54  
55      private List<Locale> siteLocales = new ArrayList<Locale>();
56  
57      private DecorationModel decoration;
58  
59      private String defaultWindowTitle;
60  
61      private Artifact skin;
62  
63      private SkinModel skinModel;
64  
65      private boolean usingDefaultTemplate;
66  
67      private File rootDirectory;
68  
69      private List<File> siteDirectories = new ArrayList<File>();
70  
71      private Map<String, String> moduleExcludes;
72  
73      private List<ExtraDoxiaModuleReference> modules = new ArrayList<ExtraDoxiaModuleReference>();
74  
75      private boolean validate;
76  
77      private Date publishDate;
78  
79      private File processedContentOutput;
80  
81      /**
82       * If input documents should be validated before parsing.
83       * By default no validation is performed.
84       *
85       * @return true if validation is switched on.
86       * @since 1.1.3
87       */
88      public boolean isValidate()
89      {
90          return validate;
91      }
92  
93      /**
94       * Switch on/off validation.
95       *
96       * @param validate true to switch on validation.
97       * @since 1.1.3
98       */
99      public void setValidate( boolean validate )
100     {
101         this.validate = validate;
102     }
103 
104     /**
105      * <p>Getter for the field <code>templateName</code>.</p>
106      *
107      * @return a {@link java.lang.String} object.
108      */
109     public String getTemplateName()
110     {
111         return templateName;
112     }
113 
114     /**
115      * <p>Getter for the field <code>templateClassLoader</code>.</p>
116      *
117      * @return a {@link java.lang.ClassLoader} object.
118      */
119     public ClassLoader getTemplateClassLoader()
120     {
121         return templateClassLoader;
122     }
123 
124     /**
125      * <p>Setter for the field <code>templateClassLoader</code>.</p>
126      *
127      * @param templateClassLoader a {@link java.lang.ClassLoader} object.
128      */
129     public void setTemplateClassLoader( ClassLoader templateClassLoader )
130     {
131         this.templateClassLoader = templateClassLoader;
132     }
133 
134     /**
135      * <p>Getter for the field <code>templateProperties</code>.</p>
136      *
137      * @return a {@link java.util.Map} object.
138      */
139     public Map<String, ?> getTemplateProperties()
140     {
141         return templateProperties;
142     }
143 
144     /**
145      * <p>Setter for the field <code>templateProperties</code>.</p>
146      *
147      * @param templateProperties a {@link java.util.Map} object.
148      */
149     public void setTemplateProperties( Map<String, ?> templateProperties )
150     {
151         this.templateProperties = Collections.unmodifiableMap( templateProperties );
152     }
153 
154     /**
155      * <p>Getter for the field <code>locale</code>.</p>
156      *
157      * @return a {@link java.util.Locale} object.
158      */
159     public Locale getLocale()
160     {
161         return locale;
162     }
163 
164     /**
165      * <p>Setter for the field <code>locale</code>.</p>
166      *
167      * @param locale a {@link java.util.Locale} object.
168      */
169     public void setLocale( Locale locale )
170     {
171         this.locale = locale;
172     }
173 
174    /**
175      * <p>Getter for the field <code>siteLocales</code> -
176      * a list of locales available for this site context.</p>
177      *
178      * @return a {@link java.util.List} object with {@link java.util.Locale} objects.
179      */
180     public List<Locale> getSiteLocales()
181     {
182         return siteLocales;
183     }
184 
185    /**
186     * <p>Adds passed locales to the list of site locales.</p>
187     *
188     * @param locales List of {@link java.util.Locale} objects to add to the site locales list.
189     */
190     public void addSiteLocales( List<Locale> locales )
191     {
192         siteLocales.addAll( locales );
193     }
194 
195     /**
196      * <p>Getter for the field <code>decoration</code>.</p>
197      *
198      * @return a {@link org.apache.maven.doxia.site.decoration.DecorationModel} object.
199      */
200     public DecorationModel getDecoration()
201     {
202         return decoration;
203     }
204 
205     /**
206      * <p>Setter for the field <code>decoration</code>.</p>
207      *
208      * @param decoration a {@link org.apache.maven.doxia.site.decoration.DecorationModel} object.
209      */
210     public void setDecoration( DecorationModel decoration )
211     {
212         this.decoration = decoration;
213     }
214 
215     /**
216      * <p>Setter for the field <code>defaultWindowTitle</code>.</p>
217      *
218      * @param defaultWindowTitle a {@link java.lang.String} object.
219      */
220     public void setDefaultWindowTitle( String defaultWindowTitle )
221     {
222         this.defaultWindowTitle = defaultWindowTitle;
223     }
224 
225     /**
226      * <p>Getter for the field <code>defaultWindowTitle</code>.</p>
227      *
228      * @return a {@link java.lang.String} object.
229      */
230     public String getDefaultWindowTitle()
231     {
232         return defaultWindowTitle;
233     }
234 
235     /**
236      * <p>Getter for the field <code>skin</code>.</p>
237      *
238      * @return a {@link Artifact} object.
239      */
240     public Artifact getSkin()
241     {
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     {
252         this.skin = skin;
253     }
254 
255     /**
256      * <p>Getter for the field <code>skinModel</code>.</p>
257      *
258      * @return a {@link SkinModel} object.
259      */
260     public SkinModel getSkinModel()
261     {
262         return skinModel;
263     }
264 
265     /**
266      * <p>Setter for the field <code>skinModel</code>.</p>
267      *
268      * @param skinModel a {@link SkinModel} object.
269      */
270     public void setSkinModel( SkinModel skinModel )
271     {
272         this.skinModel = skinModel;
273     }
274 
275     /**
276      * <p>Setter for the field <code>templateName</code>.</p>
277      *
278      * @param templateName a {@link java.lang.String} object.
279      */
280     public void setTemplateName( String templateName )
281     {
282         this.templateName = templateName;
283     }
284 
285     /**
286      * <p>Setter for the field <code>usingDefaultTemplate</code>.</p>
287      *
288      * @param usingDefaultTemplate a boolean.
289      */
290     public void setUsingDefaultTemplate( boolean usingDefaultTemplate )
291     {
292         this.usingDefaultTemplate = usingDefaultTemplate;
293     }
294 
295     /**
296      * <p>isUsingDefaultTemplate.</p>
297      *
298      * @return a boolean.
299      */
300     public boolean isUsingDefaultTemplate()
301     {
302         return usingDefaultTemplate;
303     }
304 
305     /**
306      * Add a site directory, expected to have a Doxia Site layout, ie one directory per Doxia parser module containing
307      * files with parser extension. Typical values are <code>src/site</code> or <code>target/generated-site</code>.
308      *
309      * @param siteDirectory a {@link java.io.File} object.
310      */
311     public void addSiteDirectory( File siteDirectory )
312     {
313         this.siteDirectories.add( siteDirectory );
314     }
315 
316     /**
317      * Add a extra-module source directory: used for Maven 1.x <code>${basedir}/xdocs</code> layout, which contains
318      * <code>xdoc</code> and <code>fml</code>.
319      *
320      * @param moduleBasedir The base directory for module's source files.
321      * @param moduleParserId module's Doxia parser id.
322      */
323     public void addModuleDirectory( File moduleBasedir, String moduleParserId )
324     {
325         this.modules.add( new ExtraDoxiaModuleReference( moduleParserId, moduleBasedir ) );
326     }
327 
328     /**
329      * <p>Getter for the field <code>siteDirectories</code>.</p>
330      *
331      * @return List of site directories files.
332      */
333     public List<File> getSiteDirectories()
334     {
335         return siteDirectories;
336     }
337 
338     /**
339      * <p>Getter for the field <code>modules</code>.</p>
340      *
341      * @return a {@link java.util.List} object.
342      */
343     public List<ExtraDoxiaModuleReference> getModules()
344     {
345         return modules;
346     }
347 
348     /**
349      * <p>Getter for the field <code>moduleExcludes</code>.</p>
350      *
351      * @return a map defining exclude patterns (comma separated) by parser id.
352      */
353     public Map<String, String> getModuleExcludes()
354     {
355         return moduleExcludes;
356     }
357 
358     /**
359      * <p>Setter for the field <code>moduleExcludes</code>.</p>
360      *
361      * @param moduleExcludes a {@link java.util.Map} object.
362      */
363     public void setModuleExcludes( Map<String, String> moduleExcludes )
364     {
365         this.moduleExcludes = moduleExcludes;
366     }
367 
368     /**
369      * <p>Getter for the field <code>inputEncoding</code>.</p>
370      *
371      * @return a {@link java.lang.String} object.
372      */
373     public String getInputEncoding()
374     {
375         return inputEncoding;
376     }
377 
378     /**
379      * <p>Setter for the field <code>inputEncoding</code>.</p>
380      *
381      * @param inputEncoding a {@link java.lang.String} object.
382      */
383     public void setInputEncoding( String inputEncoding )
384     {
385         this.inputEncoding = inputEncoding;
386     }
387 
388     /**
389      * <p>Getter for the field <code>outputEncoding</code>.</p>
390      *
391      * @return a {@link java.lang.String} object.
392      */
393     public String getOutputEncoding()
394     {
395         return outputEncoding;
396     }
397 
398     /**
399      * <p>Setter for the field <code>outputEncoding</code>.</p>
400      *
401      * @param outputEncoding a {@link java.lang.String} object.
402      */
403     public void setOutputEncoding( String outputEncoding )
404     {
405         this.outputEncoding = outputEncoding;
406     }
407 
408     /**
409      * <p>If you want to specify a specific publish date instead of the current date.</p>
410      * 
411      * @return the publish date, can be {@code null}
412      */
413     public Date getPublishDate()
414     {
415         return publishDate;
416     }
417 
418     /**
419      * <p>Specify a specific publish date instead of the current date.</p>
420      * 
421      * @param publishDate the publish date
422      */
423     public void setPublishDate( Date publishDate )
424     {
425         this.publishDate = publishDate;
426     }
427 
428     /**
429      * Directory where to save content after Velocity processing (<code>*.vm</code>), but before parsing it with Doxia.
430      * 
431      * @return not null if the documents are to be saved
432      * @since 1.7
433      */
434     public File getProcessedContentOutput()
435     {
436         return processedContentOutput;
437     }
438 
439     /**
440      * Where to (eventually) save content after Velocity processing (<code>*.vm</code>), but before parsing it with
441      * Doxia?
442      * 
443      * @param processedContentOutput not null if the documents are to be saved
444      * @since 1.7
445      */
446     public void setProcessedContentOutput( File processedContentOutput )
447     {
448         this.processedContentOutput = processedContentOutput;
449     }
450 
451     /**
452      * Root directory, to calculate relative path to every site directories.
453      * Corresponds to the <code>pom.xml</code> directory for Maven build.
454      *
455      * @return the root directory
456      * @since 1.8
457      */
458     public File getRootDirectory()
459     {
460         return rootDirectory;
461     }
462 
463     /**
464      * Set the root directory.
465      *
466      * @param rootDirectory
467      * @since 1.8
468      */
469     public void setRootDirectory( File rootDirectory )
470     {
471         this.rootDirectory = rootDirectory;
472     }
473 }