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