View Javadoc

1   /*
2    * Copyright 2010 - org.tinyjee.maven
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *        http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  
17  package org.tinyjee.maven.dim;
18  
19  /**
20   * Defines the signature of the include macro.
21   *
22   * @author Juergen_Kellerer, 2010-09-06
23   * @version 1.1
24   */
25  public interface IncludeMacroSignature {
26  	/**
27  	 * Sets the content to include using a source path, source URL or the fully qualified java class name.
28  	 * <p/>
29  	 * Examples: <code><pre>
30  	 * source=path/to/file
31  	 * source=my.package.MyClass
32  	 * source=/absolute/path/to/file
33  	 * source=http://somehost/someservice#.xml
34  	 * source=classpath:/bundled/template.vm
35  	 * </pre></code>
36  	 * <p/>
37  	 * Relative source paths are resolved against multiple base locations including <b>site</b>, <b>java (test)source</b> and
38  	 * <b>resource</b> directories. Non existing absolute paths starting with the project's base directory are stripped and retried
39  	 * using the relative paths resolver.
40  	 * <br/>
41  	 * When remote content is specified using URLs with schemes like <b>http</b> or <b>ftp</b>, the content is downloaded
42  	 * using a network connection and cached locally for the time of a single build (= subsequent requests to the same remote
43  	 * source will not download the source again).
44  	 * <p/>
45  	 * Executing the goal "{@code initialize}" within the maven build enables the following additional syntax for referencing a
46  	 * module file location: <code><pre>
47  	 * [artifactId]:path/to/file
48  	 * [groupId:artifactId]:path/to/file
49  	 * [top]:path/to/file/in/project/root
50  	 * </pre></code>
51  	 * <p/>
52  	 * Finally sources can also be loaded from the module's or the site building <b>classpath</b> using "{@code classpath:/path/to/file}".
53  	 * <br/>
54  	 * The classpath is constructed out of the module <code>sources</code> and <code>test-sources</code> folder with the parent
55  	 * classloader being defined by the dependency list of the <code>maven-site-plugin</code>.
56  	 * When the goal "{@code initialize}" is executed the classpath includes all dependencies that are defined inside
57  	 * the <code>pom.xml</code>.
58  	 */
59  	String PARAM_SOURCE = "source";
60  
61  	/**
62  	 * Sets a class to use as dynamic source for content, request parameters or both.
63  	 * <p/>
64  	 * A class that is set using this parameter must implement the interface <code>java.util.Map</code>
65  	 * (or derive from a Map implementation like <code>java.util.HashMap</code>).
66  	 * All entries of this map are treated as if they had been specified as request parameters,
67  	 * on the macro call (therefore all parameters except 'source-class' can be set dynamically).
68  	 * <p/>
69  	 * The source class may choose to use one of the 4 constructor signatures: <code>Default</code>,
70  	 * <code>Constructor(java.io.File basePath)</code>, <code>Constructor(java.util.Map requestProperties)</code>
71  	 * or <code>Constructor(java.io.File basePath, java.util.Map requestProperties)</code>.
72  	 * <p/>
73  	 * The default behaviour of a source class should be to provide properties for a velocity template that is specified by
74  	 * either setting the "source" key to a bundled template or require the user to set the parameter when using the macro with
75  	 * this class.<br/>
76  	 * Alternatively it can also directly provide the content to include (instead of loading the template specified with
77  	 * <code>"source"</code>). To do so the map key <code>"source-content"</code> must either return a <code>String</code> or
78  	 * <code>Map&lt;Integer, List&lt;String&gt;&gt;</code> (firstLine=>lines) containing the content to include.
79  	 * <p/>
80  	 * The classpath that is used to load the class is similar to the classpath used when loading sources.
81  	 * (see <code>"source"</code> parameter for more information)
82  	 * <p/>
83  	 * Simple Example:<code><pre>
84  	 * package my.package;
85  	 * public class MySource extends HashMap&lt;String, Object&gt; {
86  	 *     public MySource(java.io.File basePath, java.util.Map requestProperties) {
87  	 *         putAll(requestProperties);
88  	 *         put("verbatim", false);
89  	 *         put("source-content", "&lt;b&gt;Hello World!&lt;/b&gt;");
90  	 *     }
91  	 * }
92  	 * </pre></code>
93  	 * Macro Call:<code><pre>
94  	 * %{include|source-class=my.package.MySource}
95  	 * </pre></code>
96  	 */
97  	String PARAM_SOURCE_CLASS = "source-class";
98  
99  	/**
100 	 * Sets the source content inline with the macro call. (This feature may become more useful when
101 	 * <a href="http://jira.codehaus.org/browse/DOXIA-445">DOXIA-445</a> gets implemented. Voting for it may help.)
102 	 * <p/>
103 	 * The purpose of this parameter is to allow the inline definition of templates used to render output of source classes.
104 	 * Unless specified, "<code>source-is-template</code>" is set to "<code>true</code>" when this parameter is set with the
105 	 * macro call (it is not implicitly set when the parameter was set by a source class).
106 	 * <p/>
107 	 * Example: Including the main java doc comment of a class (using the JavaSourceLoader extension)<code><pre>
108 	 * %{include|source-content=$comment|source-java=my.package.MyClass}
109 	 * </pre></code>
110 	 */
111 	String PARAM_SOURCE_CONTENT = "source-content";
112 
113 	/**
114 	 * Sets the source path using <code>java.io.File</code> instead of evaluating it against URL
115 	 * or File paths.
116 	 * <p/>
117 	 * Under normal conditions it's easier to set the <code>"source"</code> parameter instead.
118 	 * However there may be occasions where it's necessary to force that the path is treated
119 	 * as a file path.
120 	 */
121 	String PARAM_FILE = "file";
122 
123 	/**
124 	 * Toggles whether the source content is treated as a Velocity template.
125 	 * (<i>Default: auto (= true if file extension ends with ".vm")</i>)
126 	 */
127 	String PARAM_SOURCE_IS_TEMPLATE = "source-is-template";
128 
129 	/**
130 	 * Sets the content type of the source.
131 	 * (<i>Default: auto (= detected by file extensions ".apt", ".fml", ".xdoc")</i>)
132 	 * <p/>
133 	 * Setting this property has no effect for verbatim content. With non-verbatim
134 	 * content this information is used to select a doxia parser that transcodes the
135 	 * the content when including it into the site. Using a parser allows to use <i>xdoc</i>
136 	 * templates inside <i>apt</i> documents and vice versa.
137 	 * <p/>
138 	 * Values that will select a parser are "<b>apt</b>", "<b>fml</b>", "<b>xdoc</b>",
139 	 * any other values will have no effect.
140 	 */
141 	String PARAM_SOURCE_CONTENT_TYPE = "source-content-type";
142 
143 	/**
144 	 * Defines the charset to use when loading the source content.
145 	 * (<i>Default: context specific</i>, used to be <i>"UTF-8" in pre 1-1-alpha</i>)
146 	 * <p/>
147 	 * When no charset is specified the following actions apply:<ul>
148 	 * <li>If auto detection is enabled, the detected charset is used.</li>
149 	 * <li>If source is using the HTTP protocol, any given charset is used.</li>
150 	 * <li>The build charset is used when the goal {@code initialize} was executed.</li>
151 	 * <li>The systems default charset is used if nothing else is defined.</li>
152 	 * </ul>
153 	 */
154 	String PARAM_CHARSET = "charset";
155 
156 	/**
157 	 * Toggles whether charset detection is used when loading source content.
158 	 * (<i>Default: true</i>)
159 	 * <p/>
160 	 * This value can have multiple values:<ul>
161 	 * <li>false: Disable any auto detection.</li>
162 	 * <li>true: Enable auto detection, externally specified charsets override detected values.</li>
163 	 * <li>force: Use auto detection result even if confidence is low.</li>
164 	 * </ul>
165 	 */
166 	String PARAM_CHARSET_AUTODETECT = "charset-autodetect";
167 
168 	/**
169 	 * Toggles whether the content is verbatim (included as source) or non-verbatim (included
170 	 * as markup and interpreted).
171 	 * (<i>Default: auto</i>)
172 	 */
173 	String PARAM_VERBATIM = "verbatim";
174 
175 	/**
176 	 * Sets the snippet-id to use for extracting snippets out of the specified source.
177 	 * <p/>
178 	 * Snippets are processed on a line by line basis and multiple snippets with the same
179 	 * name may appear in one file. In order to define a section using a snippet id,
180 	 * surround a block with:<br/>
181 	 * <code>
182 	 * // START SNIPPET: snippet-id<br/>
183 	 * ... code to include ...<br/>
184 	 * // END SNIPPET: snippet-id<br/>
185 	 * </code>
186 	 * <p/>
187 	 * Note: From version 1.1 this parameter is deprecated, use {@code snippet} instead.
188 	 * Calls like "{@code %{include|id=SnippetId|..}}" translate to {@code %{include|snippet=#SnippetId|..}}
189 	 */
190 	@Deprecated
191 	String PARAM_SNIPPET_ID = "id";
192 
193 	/**
194 	 * Sets one or more comma separated expression to select the content snippets to include.
195 	 * <p/>
196 	 * Snippet selection allows to define what content is included or excluded from the loaded or generated source.
197 	 * This operation is always the last thing to happen before including and highlighting content and can therefore be
198 	 * combined with any other options that the macro offers.
199 	 * <p/>
200 	 * The general format of this parameter is "{@code prefix:expression1, prefix:expression2}, .." to <b>include</b>
201 	 * matching content and "{@code !prefix:expression1, !prefix:expression2}, .." to <b>exclude</b> matching content.
202 	 * <p/>
203 	 * <span id="START-SNIPPET: snippet-selection-examples">
204 	 * <b>Examples</b>:<ul>
205 	 * <li>Include snippet by ID: '{@code snippet=#SnippetId}'</li>
206 	 * <li>Exclude all snippet id definitions: '{@code snippet=!snippet-ids}'</li>
207 	 * <li>Include by ID, exclude any definitions: '{@code snippet=#SnippetId, !snippet-ids}'</li>
208 	 * <li>'grep' like syntax: '{@code snippet=grep:Token,!grep:NotToken}'</li>
209 	 * <li>'<a href="http://download.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html">Regular Expression</a>'
210 	 * syntax: '{@code snippet=re:([0-9,.;\s]+)$}' (all lines ending with numeric expressions)</li>
211 	 * <li>'<a href="http://www.w3.org/TR/xpath/">XPath</a>' syntax: '{@code snippet=xp:/html/head/title}'</li>
212 	 * <li>'AOP'-like syntax: '{@code snippet=aj:..InnerClass, !aj:..toString()}'</li>
213 	 * <li>'Token &amp; Brace' syntax: '<code>snippet=tb:"json-key"{, !tb:"inner-array"[</code>'</li>
214 	 * <li>Line range: '{@code snippet=lines:50-100}'</li>
215 	 * </ul>
216 	 * </span><span id="END-SNIPPET: snippet-selection-examples"/>
217 	 * <p/>
218 	 * Some snippet selectors (e.g. XPath or AOP) require that the source content is well formed (XML/JSON or Java in this example)
219 	 * and may fail if applied to other content.
220 	 * <br/>
221 	 * A complete overview on available expressions can be seen by looking after implementations of
222 	 * {@link org.tinyjee.maven.dim.spi.SnippetSelector}.
223 	 *
224 	 * @since 1.1-alpha
225 	 */
226 	String PARAM_SNIPPET = "snippet";
227 
228 	/**
229 	 * Optional parameter that can be used to grow snippet selections by the given amount of lines.
230 	 *
231 	 * @since 1.1-alpha
232 	 */
233 	String PARAM_SNIPPET_GROW_OFFSET = "snippet-grow-offset";
234 
235 	/**
236 	 * Optional parameter that can be used to grow the start of snippet selections by the given amount of lines.
237 	 *
238 	 * @since 1.1-alpha
239 	 */
240 	String PARAM_SNIPPET_START_OFFSET = "snippet-start-offset";
241 
242 	/**
243 	 * Optional parameter that can be used to grow the end of snippet selections by the given amount of lines.
244 	 *
245 	 * @since 1.1-alpha
246 	 */
247 	String PARAM_SNIPPET_END_OFFSET = "snippet-end-offset";
248 
249 	/**
250 	 * Optional boolean parameter that toggles whether growing is applied to exclusions as well.
251 	 * (<i>Default: false</i>)
252 	 *
253 	 * @since 1.1-alpha
254 	 */
255 	String PARAM_SNIPPET_GROW_EXCLUDES = "snippet-grow-excludes";
256 
257 	/**
258 	 * Toggles whether the gutter including line numbers is shown for verbatim content.
259 	 * (<i>Default: true</i>)
260 	 */
261 	String PARAM_SHOW_GUTTER = "show-gutter";
262 
263 	/**
264 	 * Sets the line number to use for the first line (if gutter is shown).
265 	 * (<i>Default: auto</i>)
266 	 */
267 	String PARAM_SET_FIRST_LINE = "set-first-line";
268 
269 	/**
270 	 * Pads all line numbers by the specified amount of zeros (if gutter is shown).
271 	 */
272 	String PARAM_PAD_LINE_NUMBERS = "pad-line-numbers";
273 
274 	/**
275 	 * Sets a list of lines to highlight inside verbatim content.
276 	 * <p/>
277 	 * Lines can be specified as a comma separated list of line numbers, as a range
278 	 * using x-y or as a mixture of the 2.<br/>
279 	 * Example usage: <code>highlight=1,5,10,20-25</code>
280 	 * <p/>
281 	 * As of version <i>1.1-beta</i> this option is deprecated and was replaced by "{@code highlight-lines}".
282 	 * The example usage from above translates to "{@code highlight-lines=lines:1,5,10,20-25}"
283 	 */
284 	@Deprecated
285 	String PARAM_HIGHLIGHT = "highlight";
286 
287 	/**
288 	 * Defines lines to highlight inside verbatim content using the same selection logic as used within the "{@code snippet}" parameter.
289 	 * Selected lines are highlighted by the use of a background color.
290 	 * <p/>
291 	 * Examples:<ul>
292 	 * <li>"{@code highlight-lines=grep:org.tinyjee.dim+3}"</li>
293 	 * <li>"{@code highlight-lines=xp://license}"</li>
294 	 * <li>"{@code highlight-lines=lines:1,5,10,20-25}"</li>
295 	 * </ul>
296 	 *
297 	 * @since 1.1-beta
298 	 */
299 	String PARAM_HIGHLIGHT_LINES = "highlight-lines";
300 
301 	/**
302 	 * Sets the highlighter (brush) to use when highlighting verbatim content.
303 	 * (<i>Default: auto ; uses source content or extension to detect</i>)
304 	 * <p/>
305 	 * DIM bundles the brushes <b>bat</b>, <b>properties</b>, <b>clojure</b> and <b>velocity</b> in
306 	 * <b>addition</b> to what is available by <b>default</b> inside the syntax highlighting library.
307 	 * A set of known brushes includes: <b>java</b>, <b>js</b>, <b>jsp</b>, <b>cpp</b>, <b>csharp</b>,
308 	 * <b>sql</b>, <b>xml</b>, <b>html</b>, etc. Check the documentation of SyntaxHighlighter to get a complete list.
309 	 * <p/>
310 	 * Highlighting of verbatim content can be disabled by setting this property to <b>none</b>.
311 	 * <p/>
312 	 * Specifying the highlight type as "<code>html/[brushname]</code>" allows to highlight HTML with embedded scripts.
313 	 * A common use case is "<code>html/js</code>" which highlights any HTML-like code with embedded javascript (Note: files with
314 	 * an extension of ".xhtml" or ".html" default to this highlighting type).
315 	 */
316 	String PARAM_HIGHLIGHT_TYPE = "highlight-type";
317 
318 	/**
319 	 * Sets the highlighting color theme to use.
320 	 * (<i>Default: default</i>)
321 	 * <p/>
322 	 * Possible values: "<code>default</code>", "<code>django</code>", "<code>eclipse</code>",
323 	 * "<code>emacs</code>", "<code>fadeToGrey</code>", "<code>MDUltra</code>",
324 	 * "<code>midnight</code>", "<code>RDark</code>".
325 	 * (See: <a href="http://alexgorbatchev.com/SyntaxHighlighter/manual/themes/">
326 	 * http://alexgorbatchev.com/SyntaxHighlighter/manual/themes/</a>)
327 	 * <br/>
328 	 * The theme can be set only once per page. The first highlighted inclusion will set the theme for all others.
329 	 */
330 	String PARAM_HIGHLIGHT_THEME = "highlight-theme";
331 
332 	/**
333 	 * Forces the re-loading of source content when set to <code>true</code>.
334 	 * <p/>
335 	 * Content is cached for the lifetime of the build to avoid double
336 	 * downloads of remote resources.
337 	 */
338 	String PARAM_NO_CACHE = "no-cache";
339 
340 	/**
341 	 * Sets the path of the site source directory.
342 	 * <p/>
343 	 * Setting this property is not required if the site directory uses standard paths or is located directly below the
344 	 * module's base directory.
345 	 * <p/>
346 	 * As of version <b>1.1-beta</b> this option is deprecated and was replaced by running the "initialize" goal
347 	 * using the macro as build plugin.
348 	 */
349 	@Deprecated
350 	String PARAM_SITE_DIRECTORY = "site-directory";
351 }