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