Author: ltheussl Date: Sat Mar 5 20:36:14 2011 New Revision: 1078346 URL: http://svn.apache.org/viewvc?rev=1078346&view=rev Log: split up developer docs, add docs about using the sink API
Added: maven/doxia/site/src/site/apt/developers/macros.apt maven/doxia/site/src/site/apt/developers/modules.apt maven/doxia/site/src/site/apt/developers/sink.apt Modified: maven/doxia/site/src/site/apt/developers/index.apt maven/doxia/site/src/site/apt/modules/index.apt maven/doxia/site/src/site/pdf.xml maven/doxia/site/src/site/site.xml Modified: maven/doxia/site/src/site/apt/developers/index.apt URL: http://svn.apache.org/viewvc/maven/doxia/site/src/site/apt/developers/index.apt?rev=1078346&r1=1078345&r2=1078346&view=diff ============================================================================== --- maven/doxia/site/src/site/apt/developers/index.apt (original) +++ maven/doxia/site/src/site/apt/developers/index.apt Sat Mar 5 20:36:14 2011 @@ -30,196 +30,11 @@ Doxia Developers Centre This documentation centre is for those that are developing Doxia modules or macro. -%{toc|section=1|fromDepth=2|toDepth=2} + Currently you can find information on the following topics: -* {Create a New Doxia Module} + * {{{./modules.html}Creating Doxia Modules}} - First, you need to create a POM with <doxia-modules> as parent: + * {{{./macros.html}Creating Doxia Macros}} -+---- -<project> - <parent> - <groupId>org.apache.maven.doxia</groupId> - <artifactId>doxia-modules</artifactId> - <version>1.0</version> <!-- Latest release --> - </parent> - <modelVersion>4.0.0</modelVersion> - <artifactId>doxia-module-my</artifactId> - <name>Doxia :: MY Module</name> - - ... -</project> -+---- - - Secondly, you should implement some Doxia classes: - - * <MyParser> class - -+---- -import org.apache.maven.doxia.parser.AbstractParser; - -/** - * @plexus.component role="org.apache.maven.doxia.parser.Parser" role-hint="my" - */ -public class MyParser - extends AbstractParser -{ -... -} -+---- - - * <MyParseException> class (optional) - -+---- -import org.apache.maven.doxia.parser.ParseException; - -public class MyParseException - extends ParseException -{ -... -} -+---- - - * <MySiteModule> class (optional, will be used by doxia-sitetools) - -+---- -import org.apache.maven.doxia.module.site.AbstractSiteModule; - -/** - * @plexus.component role="org.apache.maven.doxia.module.site.SiteModule" role-hint="my" - */ -public class MySiteModule - extends AbstractSiteModule -{ -... -} -+---- - - * <MySink> class - -+---- -import org.apache.maven.doxia.sink.SinkAdapter; - -public class MySink - extends SinkAdapter -{ -... -} -+---- - - * <MySinkFactory> class - -+---- -import org.apache.maven.doxia.sink.SinkFactory; - -/** - * @plexus.component role="org.apache.maven.doxia.sink.SinkFactory" role-hint="my" - */ -public class MySinkFactory - extends SinkFactory -{ -... -} -+---- - - [] - -* {Create a New Doxia Macro} - - You need to add the following plugin configuration to generate the correct Plexus <component.xml> file - for the project containing your macro: - -+---- -<project> - ... - <build> - ... - <plugins> - <plugin> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-maven-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>descriptor</goal> - </goals> - </execution> - </executions> - </plugin> - ... - </plugins> - ... - </build> - ... -</project> -+---- - - You should implement the <AbstractMacro> class: - -+---- -import org.apache.maven.doxia.macro.AbstractMacro; - -/** - * @plexus.component role="org.apache.maven.doxia.macro.Macro" role-hint="my" - */ -public class MyMacro - extends AbstractMacro -{ -... - public void execute( Sink sink, MacroRequest request ) - throws MacroExecutionException - { - String myValue = (String) request.getParameter( "myParam" ); -... - } -... -} -+---- - - To use it, you need to write the following markups: - - * APT - -+---- -%{my|myParam=myValue} <!-- my is the macro name defined by role-hint --> -+---- - - * XDoc - -+---- -<macro name="my"> <!-- my is the required macro name defined by role-hint --> - <param name="myParam" value="myValue"/> -</macro> -+---- - - [] - -* {Passing attributes to Sink events} - - With Doxia 1.1 a number of methods have been added to the Sink API that - allow to pass a set of attributes to many sink events. A typical use case would be: - -+---- -SinkEventAttributeSet atts = new SinkEventAttributeSet(); -atts.addAttribute( SinkEventAttributes.ALIGN, "center" ); - -sink.paragraph( atts ); -+---- - - What kind of attributes are supported depends on the event and the sink - implementation. The sink API specifies a list of suggested attribute - names that sinks are expected to recognize, and parsers are expected to use - preferably when emitting events. - - -* {References} - - * {{{../modules/index.html}Doxia Modules Guide}} + * {{{./sink.html}Using the Doxia Sink API}} - * {{{../macros/index.html}Doxia Macros Guide}} - - * {{{../doxia/apidocs/index.html}Doxia API Reference}} - - * {{{../doxia-sitetools/apidocs/index.html}Doxia Sitetools API Reference}} - - [] Added: maven/doxia/site/src/site/apt/developers/macros.apt URL: http://svn.apache.org/viewvc/maven/doxia/site/src/site/apt/developers/macros.apt?rev=1078346&view=auto ============================================================================== --- maven/doxia/site/src/site/apt/developers/macros.apt (added) +++ maven/doxia/site/src/site/apt/developers/macros.apt Sat Mar 5 20:36:14 2011 @@ -0,0 +1,109 @@ + ----- + Doxia Developers Centre + ----- + Vincent Siveton + ------ + 2008-03-02 + ------ + +~~ Licensed to the Apache Software Foundation (ASF) under one +~~ or more contributor license agreements. See the NOTICE file +~~ distributed with this work for additional information +~~ regarding copyright ownership. The ASF licenses this file +~~ to you under the Apache License, Version 2.0 (the +~~ "License"); you may not use this file except in compliance +~~ with the License. You may obtain a copy of the License at +~~ +~~ http://www.apache.org/licenses/LICENSE-2.0 +~~ +~~ Unless required by applicable law or agreed to in writing, +~~ software distributed under the License is distributed on an +~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +~~ KIND, either express or implied. See the License for the +~~ specific language governing permissions and limitations +~~ under the License. + +~~ NOTE: For help with the syntax of this file, see: +~~ http://maven.apache.org/doxia/references/apt-format.html + +Create a New Doxia Macro + + You need to add the following plugin configuration to generate the correct Plexus <component.xml> file + for the project containing your macro: + ++---- +<project> + ... + <build> + ... + <plugins> + <plugin> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-maven-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>descriptor</goal> + </goals> + </execution> + </executions> + </plugin> + ... + </plugins> + ... + </build> + ... +</project> ++---- + + You should implement the <AbstractMacro> class: + ++---- +import org.apache.maven.doxia.macro.AbstractMacro; + +/** + * @plexus.component role="org.apache.maven.doxia.macro.Macro" role-hint="my" + */ +public class MyMacro + extends AbstractMacro +{ +... + public void execute( Sink sink, MacroRequest request ) + throws MacroExecutionException + { + String myValue = (String) request.getParameter( "myParam" ); +... + } +... +} ++---- + + To use it, you need to write the following markups: + + * APT + ++---- +%{my|myParam=myValue} <!-- my is the macro name defined by role-hint --> ++---- + + * XDoc + ++---- +<macro name="my"> <!-- my is the required macro name defined by role-hint --> + <param name="myParam" value="myValue"/> +</macro> ++---- + + [] + +* {References} + + * {{{../modules/index.html}Doxia Modules Guide}} + + * {{{../macros/index.html}Doxia Macros Guide}} + + * {{{../doxia/apidocs/index.html}Doxia API Reference}} + + * {{{../doxia-sitetools/apidocs/index.html}Doxia Sitetools API Reference}} + + [] Added: maven/doxia/site/src/site/apt/developers/modules.apt URL: http://svn.apache.org/viewvc/maven/doxia/site/src/site/apt/developers/modules.apt?rev=1078346&view=auto ============================================================================== --- maven/doxia/site/src/site/apt/developers/modules.apt (added) +++ maven/doxia/site/src/site/apt/developers/modules.apt Sat Mar 5 20:36:14 2011 @@ -0,0 +1,132 @@ + ----- + Doxia Developers Centre + ----- + Vincent Siveton + ------ + 2008-03-02 + ------ + +~~ Licensed to the Apache Software Foundation (ASF) under one +~~ or more contributor license agreements. See the NOTICE file +~~ distributed with this work for additional information +~~ regarding copyright ownership. The ASF licenses this file +~~ to you under the Apache License, Version 2.0 (the +~~ "License"); you may not use this file except in compliance +~~ with the License. You may obtain a copy of the License at +~~ +~~ http://www.apache.org/licenses/LICENSE-2.0 +~~ +~~ Unless required by applicable law or agreed to in writing, +~~ software distributed under the License is distributed on an +~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +~~ KIND, either express or implied. See the License for the +~~ specific language governing permissions and limitations +~~ under the License. + +~~ NOTE: For help with the syntax of this file, see: +~~ http://maven.apache.org/doxia/references/apt-format.html + +Create a New Doxia Module + + First, you need to create a POM with <doxia-modules> as parent: + ++---- +<project> + <parent> + <groupId>org.apache.maven.doxia</groupId> + <artifactId>doxia-modules</artifactId> + <version>1.0</version> <!-- Latest release --> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>doxia-module-my</artifactId> + <name>Doxia :: MY Module</name> + + ... +</project> ++---- + + Secondly, you should implement some Doxia classes: + + * <MyParser> class + ++---- +import org.apache.maven.doxia.parser.AbstractParser; + +/** + * @plexus.component role="org.apache.maven.doxia.parser.Parser" role-hint="my" + */ +public class MyParser + extends AbstractParser +{ +... +} ++---- + + * <MyParseException> class (optional) + ++---- +import org.apache.maven.doxia.parser.ParseException; + +public class MyParseException + extends ParseException +{ +... +} ++---- + + * <MySiteModule> class (optional, will be used by doxia-sitetools) + ++---- +import org.apache.maven.doxia.module.site.AbstractSiteModule; + +/** + * @plexus.component role="org.apache.maven.doxia.module.site.SiteModule" role-hint="my" + */ +public class MySiteModule + extends AbstractSiteModule +{ +... +} ++---- + + * <MySink> class + ++---- +import org.apache.maven.doxia.sink.SinkAdapter; + +public class MySink + extends SinkAdapter +{ +... +} ++---- + + * <MySinkFactory> class + ++---- +import org.apache.maven.doxia.sink.SinkFactory; + +/** + * @plexus.component role="org.apache.maven.doxia.sink.SinkFactory" role-hint="my" + */ +public class MySinkFactory + extends SinkFactory +{ +... +} ++---- + + [] + + +* {References} + + * {{{../modules/index.html}Doxia Modules Guide}} + + * {{{../macros/index.html}Doxia Macros Guide}} + + * {{{../doxia/apidocs/index.html}Doxia API Reference}} + + * {{{../doxia-sitetools/apidocs/index.html}Doxia Sitetools API Reference}} + + [] Added: maven/doxia/site/src/site/apt/developers/sink.apt URL: http://svn.apache.org/viewvc/maven/doxia/site/src/site/apt/developers/sink.apt?rev=1078346&view=auto ============================================================================== --- maven/doxia/site/src/site/apt/developers/sink.apt (added) +++ maven/doxia/site/src/site/apt/developers/sink.apt Sat Mar 5 20:36:14 2011 @@ -0,0 +1,210 @@ + ----- + Doxia Developers Centre + ----- + Vincent Siveton + ------ + 2008-03-02 + ------ + +~~ Licensed to the Apache Software Foundation (ASF) under one +~~ or more contributor license agreements. See the NOTICE file +~~ distributed with this work for additional information +~~ regarding copyright ownership. The ASF licenses this file +~~ to you under the Apache License, Version 2.0 (the +~~ "License"); you may not use this file except in compliance +~~ with the License. You may obtain a copy of the License at +~~ +~~ http://www.apache.org/licenses/LICENSE-2.0 +~~ +~~ Unless required by applicable law or agreed to in writing, +~~ software distributed under the License is distributed on an +~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +~~ KIND, either express or implied. See the License for the +~~ specific language governing permissions and limitations +~~ under the License. + +~~ NOTE: For help with the syntax of this file, see: +~~ http://maven.apache.org/doxia/references/apt-format.html + +Using the Doxia Sink API + +%{toc|section=1|fromDepth=2|toDepth=2} + +* {Transforming documents} + + Doxia can be used to transform an arbitrary input document to any supported output format. + The following snippet shows how to use a Doxia <Parser> to transform an apt file to html: + ++---- + File userDir = new File( System.getProperty ( "user.dir" ) ); + File inputFile = new File( userDir, "test.apt" ); + File outputFile = new File( userDir, "test.html" ); + + SinkFactory sinkFactory = (SinkFactory) lookup( SinkFactory.ROLE, "html" ); // Plexus lookup + + Sink sink = sinkFactory.createSink( outputFile.getParentFile(), outputFile.getName() ) ); + + Parser parser = (AptParser) lookup( Parser.ROLE, "apt" ); // Plexus lookup + + Reader reader = ReaderFactory.newReader( inputFile, "UTF-8" ); + + parser.parse( reader, sink ); ++---- + + It is recommended that you use {{{http://plexus.codehaus.org/}Plexus}} to look up the parser. In principle + you could instantiate the parser directly ( <<<Parser parser = new AptParser();>>> ) + but then some special features like macros will not be available. + + You could also use the {{{http://maven.apache.org/doxia/doxia-tools/doxia-converter/index.html}Doxia Converter Tool}} + to parse a given file/dir to another file/dir. + + +* {Generating documents} + + The snippet below gives a simple example of how + to generate a document using the Doxia Sink API. + ++---- + /** + * Generate a simple document and emit it + * into the specified sink. The sink is flushed but not closed. + * + * @param sink The sink to receive the events. + */ + public static void generate( Sink sink ) + { + sink.head(); + + sink.title(); + sink.text( "Title" ); + sink.title_(); + + sink.author(); + sink.text( "Author" ); + sink.author_(); + + sink.date(); + sink.text( "Date" ); + sink.date_(); + + sink.head_(); + + + sink.body(); + + sink.paragraph(); + sink.text( "A paragraph of text." ); + sink.paragraph_(); + + sink.section1(); + sink.sectionTitle1(); + sink.text( "Section title" ); + sink.sectionTitle1_(); + + sink.paragraph(); + sink.text( "Paragraph in section." ); + sink.paragraph_(); + + sink.section1_(); + + sink.body_(); + + sink.flush(); + } ++---- + + A more complete example that also shows the 'canonical' order of events to use when generating + a document, can be found in the Doxia + {{{./doxia/doxia-core/xref-test/org/apache/maven/doxia/sink/SinkTestDocument.html}SinkTestDocument}} + class. + + +* {Passing attributes to Sink events} + + With Doxia 1.1 a number of methods have been added to the Sink API that + allow to pass a set of attributes to many sink events. A typical use case would be: + ++---- +SinkEventAttributeSet atts = new SinkEventAttributeSet(); +atts.addAttribute( SinkEventAttributes.ALIGN, "center" ); + +sink.paragraph( atts ); ++---- + + What kind of attributes are supported depends on the event and the sink + implementation. The sink API specifies a list of suggested attribute + names that sinks are expected to recognize, and parsers are expected to use + preferably when emitting events. + + +* {Avoid sink.rawText!} + + In <<Doxia 1.0>> it was a common practice to use sink.rawText() to generate elements that + were not supported by the Sink API. For example, the following snippet could be used + to generate a styled HTML \<div\> block: + ++---- +sink.RawText( "<div style=\"cool\">" ); +sink.text( "A text with a cool style." ); +sink.rawText( "</div>" ); ++---- + + This has a major drawback however: it only works if the receiving Sink is a HTML Sink. + In other words, the above method will not work for target documents in any other format than HTML + (think of the FO Sink to generate a pdf, or a LaTeX sink,...). + + In <<Doxia 1.1>> a new method unknown() was added to the Sink API that can be used to emit + an arbitrary event without making special assumptions about the receiving Sink. + Depending on the parameters, a Sink may decide whether or not to process the event, + emit it as raw text, as a comment, log it, etc. + + The correct way to generate the above \<div\> block is now: + ++---- +SinkEventAttributeSet atts = new SinkEventAttributeSet(); +atts.addAttribute( SinkEventAttributes.STYLE, "cool" ); + +sink.unknown( "div", new Object[]{new Integer( HtmlMarkup.TAG_TYPE_START )}, atts ); +sink.text( "A text with a cool style." ); +sink.unknown( "div", new Object[]{new Integer( HtmlMarkup.TAG_TYPE_END )}, null ); ++---- + + Read the javadocs of the unknown() method in the + {{{./doxia/doxia-sink-api/apidocs/org/apache/maven/doxia/sink/Sink.html}Sink}} interface and the + {{{./doxia/doxia-core/apidocs/org/apache/maven/doxia/sink/XhtmlBaseSink.html}XhtmlbaseSink}} + for information on the method parameters. + Note that an arbitrary sink may be expected to ignore the unknown event completely! + + <<In general, the rawText method should be avoided alltogether when emitting events into an arbitrary Sink.>> + + +* {How to inject javascript code into HTML} + + Related to the above, here is the correct way of injecting a javascript snippet into a Sink: + ++---- +// the javascript code is emitted within a commented CDATA section +// so we have to start with a newline and comment the CDATA closing in the end +// note that the sink will replace the newline by the system EOL +String javascriptCode = "\n function javascriptFunction() {...} \n //"; + +SinkEventAttributeSet atts = new SinkEventAttributeSet(); +atts.addAttribute( SinkEventAttributes.TYPE, "text/javascript" ); + +sink.unknown( "script", new Object[]{new Integer( HtmlMarkup.TAG_TYPE_START )}, atts ); +sink.unknown( "cdata", new Object[]{new Integer( HtmlMarkup.CDATA_TYPE ), javascriptCode }, null ); +sink.unknown( "script", new Object[]{new Integer( HtmlMarkup.TAG_TYPE_END )}, null ); ++---- + + +* {References} + + * {{{../modules/index.html}Doxia Modules Guide}} + + * {{{../macros/index.html}Doxia Macros Guide}} + + * {{{../doxia/apidocs/index.html}Doxia API Reference}} + + * {{{../doxia-sitetools/apidocs/index.html}Doxia Sitetools API Reference}} + + [] Modified: maven/doxia/site/src/site/apt/modules/index.apt URL: http://svn.apache.org/viewvc/maven/doxia/site/src/site/apt/modules/index.apt?rev=1078346&r1=1078345&r2=1078346&view=diff ============================================================================== --- maven/doxia/site/src/site/apt/modules/index.apt (original) +++ maven/doxia/site/src/site/apt/modules/index.apt Sat Mar 5 20:36:14 2011 @@ -33,7 +33,6 @@ Doxia Modules Guide is just a collection of reference links for the individual formats. %{toc|section=1|fromDepth=2|toDepth=2} -%{toc|section=2|fromDepth=1|toDepth=1} * {APT} @@ -168,30 +167,3 @@ Doxia Modules Guide * {{{http://www.w3.org/TR/xhtml1/}XHTML 1.0 Specification}} [] - -{Using A Doxia Module} - - The following snippet shows how to use a Doxia <Parser> to transform an apt file to html: - -+---- - File userDir = new File( System.getProperty ( "user.dir" ) ); - File inputFile = new File( userDir, "test.apt" ); - File outputFile = new File( userDir, "test.html" ); - - SinkFactory sinkFactory = (SinkFactory) lookup( SinkFactory.ROLE, "html" ); // Plexus lookup - - Sink sink = sinkFactory.createSink( outputFile.getParentFile(), outputFile.getName() ) ); - - Parser parser = (AptParser) lookup( Parser.ROLE, "apt" ); // Plexus lookup - - Reader reader = ReaderFactory.newReader( inputFile, "UTF-8" ); - - parser.parse( reader, sink ); -+---- - - It is recommended that you use {{{http://plexus.codehaus.org/}Plexus}} to look up the parser. In principle - you could instantiate the parser directly ( <<<Parser parser = new AptParser();>>> ) - but then some special features like macros will not be available. - - You could also use the {{{http://maven.apache.org/doxia/doxia-tools/doxia-converter/index.html}Doxia Converter Tool}} - to parse a given file/dir to another file/dir. Modified: maven/doxia/site/src/site/pdf.xml URL: http://svn.apache.org/viewvc/maven/doxia/site/src/site/pdf.xml?rev=1078346&r1=1078345&r2=1078346&view=diff ============================================================================== --- maven/doxia/site/src/site/pdf.xml (original) +++ maven/doxia/site/src/site/pdf.xml Sat Mar 5 20:36:14 2011 @@ -51,6 +51,9 @@ <item name="Doxia Macros Guide" ref="macros/index.html"/> <item name="Writing Books" ref="book/index.html"/> <item name="Developer Centre" ref="developers/index.html"/> + <item name="Create a Doxia Module" ref="developers/modules.html"/> + <item name="Create a Doxia Macro" ref="developers/macros.html"/> + <item name="Using the Sink API" ref="developers/sink.html"/> <item name="Integration With Maven" ref="developers/maven-integration.html"/> <!-- MSITE-333: remove double-amp when fixed --> <item name="Issues &amp; Gotchas" ref="issues/index.html"/> Modified: maven/doxia/site/src/site/site.xml URL: http://svn.apache.org/viewvc/maven/doxia/site/src/site/site.xml?rev=1078346&r1=1078345&r2=1078346&view=diff ============================================================================== --- maven/doxia/site/src/site/site.xml (original) +++ maven/doxia/site/src/site/site.xml Sat Mar 5 20:36:14 2011 @@ -69,7 +69,11 @@ under the License. </menu> <menu name="Developer Docs"> - <item name="Developer Centre" href="developers/index.html"/> + <item name="Developer Centre" href="developers/index.html" collapse="true"> + <item name="Create a Doxia Module" href="developers/modules.html"/> + <item name="Create a Doxia Macro" href="developers/macros.html"/> + <item name="Using the Sink API" href="developers/sink.html"/> + </item> <item name="Doxia 1.1.x" href="doxia/index.html"/> <item name="Doxia Sitetools 1.1.x" href="doxia-sitetools/index.html"/> <item name="Doxia 1.0.x" href="doxia-1.0.x/index.html"/>