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