You are viewing a plain text version of this content. The canonical link for it is here.
Posted to doxia-commits@maven.apache.org by jv...@apache.org on 2007/03/17 15:48:35 UTC
svn commit: r519333 - in
/maven/doxia/trunk/doxia-modules/doxia-module-xhtml: ./ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/maven/ src/main/java/org/apache/maven/doxia/
src/main/java/org/apache/m...
Author: jvanzyl
Date: Sat Mar 17 07:48:33 2007
New Revision: 519333
URL: http://svn.apache.org/viewvc?view=rev&rev=519333
Log:
o separate xhtml module
Added:
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/pom.xml (with props)
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/AbstractXhtmlSink.java (with props)
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/SinkDescriptorReader.java (with props)
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/StringsMap.java (with props)
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java (with props)
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java (with props)
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/decoration/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/decoration/render/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/decoration/render/RenderingContext.java (with props)
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlParserTest.java (with props)
maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java (with props)
Added: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/pom.xml
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-modules/doxia-module-xhtml/pom.xml?view=auto&rev=519333
==============================================================================
--- maven/doxia/trunk/doxia-modules/doxia-module-xhtml/pom.xml (added)
+++ maven/doxia/trunk/doxia-modules/doxia-module-xhtml/pom.xml Sat Mar 17 07:48:33 2007
@@ -0,0 +1,21 @@
+<?xml version="1.0"?><project>
+ <parent>
+ <artifactId>doxia-modules</artifactId>
+ <groupId>org.apache.maven.doxia</groupId>
+ <version>1.0-alpha-9-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.doxia</groupId>
+ <artifactId>doxia-module-xhtml</artifactId>
+ <name>doxia-module-xhtml</name>
+ <version>1.0-SNAPSHOT</version>
+ <url>http://maven.apache.org</url>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Propchange: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/pom.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/AbstractXhtmlSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/AbstractXhtmlSink.java?view=auto&rev=519333
==============================================================================
--- maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/AbstractXhtmlSink.java (added)
+++ maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/AbstractXhtmlSink.java Sat Mar 17 07:48:33 2007
@@ -0,0 +1,31 @@
+package org.apache.maven.doxia.module.xhtml;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.doxia.sink.SinkAdapter;
+
+/**
+ * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
+ * @version $Id:AbstractXhtmlSink.java 348605 2005-11-24 12:02:44 +1100 (Thu, 24 Nov 2005) brett $
+ */
+public abstract class AbstractXhtmlSink
+ extends SinkAdapter
+{
+}
Propchange: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/AbstractXhtmlSink.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/AbstractXhtmlSink.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/SinkDescriptorReader.java
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/SinkDescriptorReader.java?view=auto&rev=519333
==============================================================================
--- maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/SinkDescriptorReader.java (added)
+++ maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/SinkDescriptorReader.java Sat Mar 17 07:48:33 2007
@@ -0,0 +1,405 @@
+package org.apache.maven.doxia.module.xhtml;
+
+/*
+ * 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.
+ */
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
+ * @version $Id:SinkDescriptorReader.java 348605 2005-11-24 12:02:44 +1100 (Thu, 24 Nov 2005) brett $
+ */
+public class SinkDescriptorReader
+{
+ private static final String EOL = System.getProperty( "line.separator" );
+
+ public Map read( Reader reader )
+ throws IOException
+ {
+ Map directives = new HashMap();
+
+ BufferedReader br = new BufferedReader( reader );
+
+ String line;
+
+ String directive = null;
+
+ StringBuffer directiveBody = new StringBuffer();
+
+ while ( ( line = br.readLine() ) != null )
+ {
+ line = line.trim();
+
+ if ( line.startsWith( "//" ) || line.startsWith( "{" ) || line.length() == 0 )
+ {
+ continue;
+ }
+ else if ( line.startsWith( "*" ) )
+ {
+ directive = line.substring( 1 );
+
+ int index = directive.indexOf( "{" );
+ if ( index >= 0 )
+ {
+ if ( index < directive.length() )
+ {
+ line = directive.substring( index + 1 );
+ }
+ directive = directive.substring( 0, index ).trim();
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ if ( line.endsWith( "}" ) )
+ {
+ int index = 0;
+ while ( index >= 0 && index < line.length() - 1 )
+ {
+ index = line.indexOf( "${", index );
+ if ( index >= 0 )
+ {
+ index = line.indexOf( "}", index );
+ }
+ }
+
+ if ( index <= 0 )
+ {
+ directiveBody.append( line.substring( 0, line.length() - 1 ) );
+
+ directives.put( directive, directiveBody.toString() );
+
+ directiveBody = new StringBuffer();
+ }
+ else
+ {
+ directiveBody.append( line ).append( EOL );
+ }
+ }
+ else
+ {
+ directiveBody.append( line ).append( EOL );
+ }
+ }
+
+ return directives;
+ }
+
+ public void head()
+ {
+ }
+
+ public void head_()
+ {
+ }
+
+ public void body()
+ {
+ }
+
+ public void body_()
+ {
+ }
+
+ public void section1()
+ {
+ }
+
+ public void section1_()
+ {
+ }
+
+ public void section2()
+ {
+ }
+
+ public void section2_()
+ {
+ }
+
+ public void section3()
+ {
+ }
+
+ public void section3_()
+ {
+ }
+
+ public void section4()
+ {
+ }
+
+ public void section4_()
+ {
+ }
+
+ public void section5()
+ {
+ }
+
+ public void section5_()
+ {
+ }
+
+ public void list()
+ {
+ }
+
+ public void list_()
+ {
+ }
+
+ public void listItem()
+ {
+ }
+
+ public void listItem_()
+ {
+ }
+
+ public void numberedList( int numbering )
+ {
+ }
+
+ public void numberedList_()
+ {
+ }
+
+ public void numberedListItem()
+ {
+ }
+
+ public void numberedListItem_()
+ {
+ }
+
+ public void definitionList()
+ {
+ }
+
+ public void definitionList_()
+ {
+ }
+
+ public void definitionListItem()
+ {
+ }
+
+ public void definitionListItem_()
+ {
+ }
+
+ public void definition()
+ {
+ }
+
+ public void definition_()
+ {
+ }
+
+ public void figure()
+ {
+ }
+
+ public void figure_()
+ {
+ }
+
+ public void table()
+ {
+ }
+
+ public void table_()
+ {
+ }
+
+ public void tableRows( int[] justification, boolean grid )
+ {
+ }
+
+ public void tableRows_()
+ {
+ }
+
+ public void tableRow()
+ {
+ }
+
+ public void tableRow_()
+ {
+ }
+
+ public void title()
+ {
+ }
+
+ public void title_()
+ {
+ }
+
+ public void author()
+ {
+ }
+
+ public void author_()
+ {
+ }
+
+ public void date()
+ {
+ }
+
+ public void date_()
+ {
+ }
+
+ public void sectionTitle()
+ {
+ }
+
+ public void sectionTitle_()
+ {
+ }
+
+ public void paragraph()
+ {
+ }
+
+ public void paragraph_()
+ {
+ }
+
+ public void verbatim( boolean boxed )
+ {
+ }
+
+ public void verbatim_()
+ {
+ }
+
+ public void definedTerm()
+ {
+ }
+
+ public void definedTerm_()
+ {
+ }
+
+ public void figureCaption()
+ {
+ }
+
+ public void figureCaption_()
+ {
+ }
+
+ public void tableCell()
+ {
+ }
+
+ public void tableCell_()
+ {
+ }
+
+ public void tableHeaderCell()
+ {
+ }
+
+ public void tableHeaderCell_()
+ {
+ }
+
+ public void tableCaption()
+ {
+ }
+
+ public void tableCaption_()
+ {
+ }
+
+ public void figureGraphics( String name )
+ {
+ }
+
+ public void horizontalRule()
+ {
+ }
+
+ public void pageBreak()
+ {
+ }
+
+ public void anchor( String name )
+ {
+ }
+
+ public void anchor_()
+ {
+ }
+
+ public void link( String name )
+ {
+ }
+
+ public void link_()
+ {
+ }
+
+ public void italic()
+ {
+ }
+
+ public void italic_()
+ {
+ }
+
+ public void bold()
+ {
+ }
+
+ public void bold_()
+ {
+ }
+
+ public void monospaced()
+ {
+ }
+
+ public void monospaced_()
+ {
+ }
+
+ public void lineBreak()
+ {
+ }
+
+ public void nonBreakingSpace()
+ {
+ }
+
+ public void text( String text )
+ {
+ }
+}
Propchange: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/SinkDescriptorReader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/SinkDescriptorReader.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/StringsMap.java
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/StringsMap.java?view=auto&rev=519333
==============================================================================
--- maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/StringsMap.java (added)
+++ maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/StringsMap.java Sat Mar 17 07:48:33 2007
@@ -0,0 +1,43 @@
+package org.apache.maven.doxia.module.xhtml;
+
+/*
+ * 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.
+ */
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
+ * @version $Id:StringsMap.java 348605 2005-11-24 12:02:44 +1100 (Thu, 24 Nov 2005) brett $
+ */
+public class StringsMap
+ extends HashMap
+{
+ private Map map;
+
+ public StringsMap( Map map )
+ {
+ this.map = map;
+ }
+
+ public String get( String key )
+ {
+ return (String) map.get( key );
+ }
+}
Propchange: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/StringsMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/StringsMap.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java?view=auto&rev=519333
==============================================================================
--- maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java (added)
+++ maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java Sat Mar 17 07:48:33 2007
@@ -0,0 +1,495 @@
+package org.apache.maven.doxia.module.xhtml;
+
+/*
+ * 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.
+ */
+
+import java.io.Reader;
+import java.util.Stack;
+
+import org.apache.maven.doxia.parser.ParseException;
+import org.apache.maven.doxia.parser.Parser;
+import org.apache.maven.doxia.sink.Sink;
+import org.codehaus.plexus.util.xml.pull.MXParser;
+import org.codehaus.plexus.util.xml.pull.XmlPullParser;
+
+/**
+ * Parse an xdoc model and emit events into the specified doxia
+ * Sink.
+ *
+ * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
+ * @version $Id:XhtmlParser.java 348605 2005-11-24 12:02:44 +1100 (Thu, 24 Nov 2005) brett $
+ */
+public class XhtmlParser
+ implements Parser
+{
+ /**
+ * This stack is needed to keep track of the different link and anchor-types
+ * which utilize the same element
+ */
+ private Stack linktypes = new Stack();
+
+ /**
+ * This stack is needed to keep track of the section nesting. Each time
+ * a lower section heading is encounted, this stack raises, each time a
+ * higher section heading is encountered, this stack lowers.
+ */
+ private Stack sections = new Stack();
+
+ /**
+ * Indicates the last a-tag denoted a link
+ */
+ private static final String LINK = "link";
+
+ /**
+ * Indicates the last a-tag denoted an anchor
+ */
+ private static final String ANCHOR = "anchor";
+
+ public void parse( Reader reader, Sink sink )
+ throws ParseException
+ {
+ try
+ {
+ XmlPullParser parser = new MXParser();
+
+ parser.setInput( reader );
+
+ parseXdoc( parser, sink );
+ }
+ catch ( Exception ex )
+ {
+ throw new ParseException( "Error parsing the model.", ex );
+ }
+ }
+
+ public void parseXdoc( XmlPullParser parser, Sink sink )
+ throws Exception
+ {
+ int eventType = parser.getEventType();
+
+ while ( eventType != XmlPullParser.END_DOCUMENT )
+ {
+ if ( eventType == XmlPullParser.START_TAG )
+ {
+ if ( parser.getName().equals( "title" ) )
+ {
+ sink.title();
+ }
+ /*
+ * The ADDRESS element may be used by authors to supply contact information
+ * for a model or a major part of a model such as a form. This element
+ * often appears at the beginning or end of a model.
+ */
+ else if ( parser.getName().equals( "address" ) )
+ {
+ sink.author();
+ }
+ else if ( parser.getName().equals( "body" ) )
+ {
+ sink.body();
+ }
+ else if ( parser.getName().equals( "h1" ) || parser.getName().equals( "h2" ) ||
+ parser.getName().equals( "h3" ) || parser.getName().equals( "h4" ) ||
+ parser.getName().equals( "h5" ) )
+ {
+ this.closeSubordinatedSections( parser.getName(), sink );
+ this.startSection( this.sections.size(), sink );
+ this.startSectionTitle( this.sections.size(), sink );
+ this.sections.push( parser.getName() );
+
+ }
+ else if ( parser.getName().equals( "p" ) )
+ {
+ sink.paragraph();
+ }
+ /*
+ * The PRE element tells visual user agents that the enclosed text is
+ * "preformatted". When handling preformatted text, visual user agents:
+ * - May leave white space intact.
+ * - May render text with a fixed-pitch font.
+ * - May disable automatic word wrap.
+ * - Must not disable bidirectional processing.
+ * Non-visual user agents are not required to respect extra white space
+ * in the content of a PRE element.
+ */
+ else if ( parser.getName().equals( "pre" ) )
+ {
+ sink.verbatim( true );
+ }
+ else if ( ( parser.getName().equals( "code" ) ) || ( parser.getName().equals( "samp" ) ) ||
+ ( parser.getName().equals( "tt" ) ) )
+ {
+ sink.monospaced();
+ }
+ else if ( parser.getName().equals( "ul" ) )
+ {
+ sink.list();
+ }
+ else if ( parser.getName().equals( "ol" ) )
+ {
+ sink.numberedList( Sink.NUMBERING_DECIMAL );
+ }
+ else if ( parser.getName().equals( "li" ) )
+ {
+ sink.listItem();
+ }
+ else if ( parser.getName().equals( "head" ) )
+ {
+ sink.head();
+ }
+ else if ( ( parser.getName().equals( "b" ) ) || ( parser.getName().equals( "strong" ) ) )
+ {
+ sink.bold();
+ }
+ else if ( ( parser.getName().equals( "i" ) ) || ( parser.getName().equals( "em" ) ) )
+ {
+ sink.italic();
+ }
+ else if ( parser.getName().equals( "a" ) )
+ {
+ String href = parser.getAttributeValue( null, "href" );
+ String name = parser.getAttributeValue( null, "name" );
+ String id = parser.getAttributeValue( null, "id" );
+ if ( href != null )
+ {
+ sink.link( href );
+ this.linktypes.push( XhtmlParser.LINK );
+ }
+ else if ( name != null )
+ {
+ sink.anchor( name );
+ this.linktypes.push( XhtmlParser.ANCHOR );
+ }
+ else if ( id != null )
+ {
+ sink.anchor( id );
+ this.linktypes.push( XhtmlParser.ANCHOR );
+ }
+ }
+ else if ( parser.getName().equals( "br" ) )
+ {
+ sink.lineBreak();
+ }
+ else if ( parser.getName().equals( "hr" ) )
+ {
+ sink.horizontalRule();
+ }
+ else if ( parser.getName().equals( "img" ) )
+ {
+ sink.figure();
+ String src = parser.getAttributeValue( null, "src" );
+ String title = parser.getAttributeValue( null, "title" );
+ String alt = parser.getAttributeValue( null, "alt" );
+ if ( src != null )
+ {
+ sink.figureGraphics( src );
+ }
+ if ( title != null )
+ {
+ sink.figureCaption();
+ text( sink, title );
+ sink.figureCaption_();
+ }
+ else if ( alt != null )
+ {
+ sink.figureCaption();
+ text( sink, alt );
+ sink.figureCaption_();
+ }
+ sink.figure_();
+ }
+ // ----------------------------------------------------------------------
+ // Tables
+ // ----------------------------------------------------------------------
+
+ else if ( parser.getName().equals( "table" ) )
+ {
+ sink.table();
+ }
+ else if ( parser.getName().equals( "tr" ) )
+ {
+ sink.tableRow();
+ }
+ else if ( parser.getName().equals( "th" ) )
+ {
+ sink.tableCell();
+ }
+ else if ( parser.getName().equals( "td" ) )
+ {
+ sink.tableCell();
+ }
+
+ }
+ else if ( eventType == XmlPullParser.END_TAG )
+ {
+ if ( parser.getName().equals( "title" ) )
+ {
+ sink.title_();
+ }
+ else if ( parser.getName().equals( "address" ) )
+ {
+ sink.author_();
+ }
+ else if ( parser.getName().equals( "body" ) )
+ {
+ //close all sections that are still open
+ closeSubordinatedSections( "h0", sink );
+ sink.body_();
+ }
+ else if ( parser.getName().equals( "h1" ) || parser.getName().equals( "h2" ) ||
+ parser.getName().equals( "h3" ) || parser.getName().equals( "h4" ) ||
+ parser.getName().equals( "h5" ) )
+ {
+ this.closeSectionTitle( this.sections.size() - 1, sink );
+ }
+ else if ( parser.getName().equals( "p" ) )
+ {
+ sink.paragraph_();
+ }
+ else if ( parser.getName().equals( "pre" ) )
+ {
+ sink.verbatim_();
+ }
+ else if ( ( parser.getName().equals( "code" ) ) || ( parser.getName().equals( "samp" ) ) ||
+ ( parser.getName().equals( "tt" ) ) )
+ {
+ sink.monospaced_();
+ }
+ else if ( parser.getName().equals( "ul" ) )
+ {
+ sink.list_();
+ }
+ else if ( parser.getName().equals( "ol" ) )
+ {
+ sink.numberedList_();
+ }
+ else if ( parser.getName().equals( "li" ) )
+ {
+ sink.listItem_();
+ }
+ else if ( parser.getName().equals( "head" ) )
+ {
+ sink.head_();
+ }
+ else if ( ( parser.getName().equals( "b" ) ) || ( parser.getName().equals( "strong" ) ) )
+ {
+ sink.bold_();
+ }
+ else if ( ( parser.getName().equals( "i" ) ) || ( parser.getName().equals( "em" ) ) )
+ {
+ sink.italic_();
+ }
+ else if ( parser.getName().equals( "a" ) )
+ {
+ String linktype = (String) this.linktypes.pop();
+ //the equals operation is ok here, because we always use the class constant
+ if ( linktype == XhtmlParser.LINK )
+ {
+ sink.link_();
+ }
+ else
+ {
+ sink.anchor_();
+ }
+ }
+ // ----------------------------------------------------------------------
+ // Tables
+ // ----------------------------------------------------------------------
+
+ else if ( parser.getName().equals( "table" ) )
+ {
+ sink.table_();
+ }
+ else if ( parser.getName().equals( "tr" ) )
+ {
+ sink.tableRow_();
+ }
+ else if ( parser.getName().equals( "th" ) )
+ {
+ sink.tableCell_();
+ }
+ else if ( parser.getName().equals( "td" ) )
+ {
+ sink.tableCell_();
+ }
+
+ }
+ else if ( eventType == XmlPullParser.TEXT )
+ {
+ text( sink, parser.getText() );
+ }
+
+ eventType = parser.next();
+ }
+ }
+
+ /**
+ * Sends the text to the sink, utilizing the nonBreakingspace of the sink.
+ * @param sink
+ * @param text
+ */
+ private static void text( Sink sink, String text )
+ {
+ if( text.startsWith( " " ) )
+ {
+ sink.nonBreakingSpace();
+ }
+ String[] s = text.split( " " );
+ for( int i = 0; i < s.length; i++ )
+ {
+ sink.text( s[i] );
+ if( i + 1 < s.length )
+ {
+ sink.nonBreakingSpace();
+ }
+ }
+ if( text.endsWith( " " ) )
+ {
+ sink.nonBreakingSpace();
+ }
+ }
+
+ private void closeSubordinatedSections( String level, Sink sink )
+ {
+ if ( this.sections.size() > 0 )
+ {
+ String heading = (String) this.sections.peek();
+ int otherlevel = Integer.parseInt( heading.substring( 1 ) );
+ int mylevel = Integer.parseInt( level.substring( 1 ) );
+ if ( otherlevel >= mylevel )
+ {
+ closeSection( this.sections.size(), sink );
+ closeSubordinatedSections( level, sink );
+ }
+ }
+ }
+
+ /**
+ * Close a section of the specified level.
+ *
+ * @param level level of the section to close
+ * @param sink the sink to write to
+ */
+ private void closeSection( int level, Sink sink )
+ {
+ this.sections.pop();
+ switch ( level )
+ {
+ case 1:
+ sink.section1_();
+ break;
+ case 2:
+ sink.section2_();
+ break;
+ case 3:
+ sink.section3_();
+ break;
+ case 4:
+ sink.section4_();
+ break;
+ case 5:
+ sink.section5_();
+ break;
+ }
+ }
+
+ /**
+ * Starts a new section of the specified level
+ *
+ * @param level level of the new section
+ * @param sink the sink to write to
+ */
+ private void startSection( int level, Sink sink )
+ {
+ switch ( level )
+ {
+ case 0:
+ sink.section1();
+ break;
+ case 1:
+ sink.section2();
+ break;
+ case 2:
+ sink.section3();
+ break;
+ case 3:
+ sink.section4();
+ break;
+ case 4:
+ sink.section5();
+ break;
+ }
+ }
+
+ /**
+ * Closes the title of a section
+ *
+ * @param level level of the section
+ * @param sink the sink to write to
+ */
+ private void closeSectionTitle( int level, Sink sink )
+ {
+ switch ( level )
+ {
+ case 0:
+ sink.sectionTitle1_();
+ break;
+ case 1:
+ sink.sectionTitle2_();
+ break;
+ case 2:
+ sink.sectionTitle3_();
+ break;
+ case 3:
+ sink.sectionTitle4_();
+ break;
+ case 4:
+ sink.sectionTitle5_();
+ break;
+ }
+ }
+
+ /**
+ * Starts the title of a new section
+ *
+ * @param level level of the new section
+ * @param sink the sink to write to
+ */
+ private void startSectionTitle( int level, Sink sink )
+ {
+ switch ( level )
+ {
+ case 0:
+ sink.sectionTitle1();
+ break;
+ case 1:
+ sink.sectionTitle2();
+ break;
+ case 2:
+ sink.sectionTitle3();
+ break;
+ case 3:
+ sink.sectionTitle4();
+ break;
+ case 4:
+ sink.sectionTitle5();
+ break;
+ }
+ }
+}
Propchange: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java?view=auto&rev=519333
==============================================================================
--- maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java (added)
+++ maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java Sat Mar 17 07:48:33 2007
@@ -0,0 +1,857 @@
+package org.apache.maven.doxia.module.xhtml;
+
+/*
+ * 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.
+ */
+
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.util.Map;
+
+import org.apache.maven.doxia.module.HtmlTools;
+import org.apache.maven.doxia.module.xhtml.decoration.render.RenderingContext;
+import org.apache.maven.doxia.parser.Parser;
+import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.doxia.sink.StructureSink;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * A doxia sink which produces xhtml
+ *
+ * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
+ */
+public class XhtmlSink
+ extends AbstractXhtmlSink
+{
+ private static final String EOL = System.getProperty( "line.separator" );
+
+ private StringBuffer buffer = new StringBuffer();
+
+ private boolean headFlag;
+
+ private boolean itemFlag;
+
+ private boolean verbatimFlag;
+
+ private int cellCount;
+
+ private PrintWriter writer;
+
+ private StringsMap directives;
+
+ private RenderingContext renderingContext;
+
+ private int[] cellJustif;
+
+ public XhtmlSink( Writer writer, RenderingContext renderingContext, Map directives )
+ {
+ this.writer = new PrintWriter( writer );
+
+ this.directives = new StringsMap( directives );
+
+ this.renderingContext = renderingContext;
+ }
+
+ protected StringBuffer getBuffer()
+ {
+ return buffer;
+ }
+
+ protected void setHeadFlag( boolean headFlag )
+ {
+ this.headFlag = headFlag;
+ }
+
+ protected void resetState()
+ {
+ headFlag = false;
+ resetBuffer();
+ itemFlag = false;
+ verbatimFlag = false;
+ cellCount = 0;
+ }
+
+ protected void resetBuffer()
+ {
+ buffer = new StringBuffer();
+ }
+
+ public void head()
+ {
+ directive( "head()" );
+
+ resetState();
+
+ headFlag = true;
+ }
+
+ public void head_()
+ {
+ headFlag = false;
+
+ directive( "head_()" );
+ }
+
+ public void title()
+ {
+ write( "<title>" );
+ }
+
+ public void title_()
+ {
+ write( buffer.toString() );
+
+ write( "</title>" );
+
+ resetBuffer();
+ }
+
+ public void author_()
+ {
+ if ( buffer.length() > 0 )
+ {
+ write( "<meta name=\"author\" content=\"" );
+ write( buffer.toString() );
+ write( "\" />" + EOL );
+ resetBuffer();
+ }
+ }
+
+ public void date_()
+ {
+ if ( buffer.length() > 0 )
+ {
+ write( "<meta name=\"date\" content=\"" );
+ write( buffer.toString() );
+ write( "\" />" + EOL );
+ resetBuffer();
+ }
+ }
+
+ public void body()
+ {
+ String body = directiveValue( "body()" );
+
+ write( body );
+ }
+
+ public void body_()
+ {
+ String body = directiveValue( "body_()" );
+
+ write( body );
+
+ resetState();
+ }
+
+ // ----------------------------------------------------------------------
+ // Sections
+ // ----------------------------------------------------------------------
+
+ public void section1()
+ {
+ write( "<div class=\"section\">" );
+ }
+
+ public void section2()
+ {
+ write( "<div class=\"section\">" );
+ }
+
+ public void section3()
+ {
+ write( "<div class=\"section\">" );
+ }
+
+ public void section4()
+ {
+ write( "<div class=\"section\">" );
+ }
+
+ public void section5()
+ {
+ write( "<div class=\"section\">" );
+ }
+
+ public void section1_()
+ {
+ write( "</div>" );
+ }
+
+ public void section2_()
+ {
+ write( "</div>" );
+ }
+
+ public void section3_()
+ {
+ write( "</div>" );
+ }
+
+ public void section4_()
+ {
+ write( "</div>" );
+ }
+
+ public void section5_()
+ {
+ write( "</div>" );
+ }
+
+ public void sectionTitle1()
+ {
+ write( "<h2>" );
+ }
+
+ public void sectionTitle1_()
+ {
+ write( "</h2>" );
+ }
+
+ public void sectionTitle2()
+ {
+ write( "<h3>" );
+ }
+
+ public void sectionTitle2_()
+ {
+ write( "</h3>" );
+ }
+
+ public void sectionTitle3()
+ {
+ write( "<h4>" );
+ }
+
+ public void sectionTitle3_()
+ {
+ write( "</h4>" );
+ }
+
+ public void sectionTitle4()
+ {
+ write( "<h5>" );
+ }
+
+ public void sectionTitle4_()
+ {
+ write( "</h5>" );
+ }
+
+ public void sectionTitle5()
+ {
+ write( "<h6>" );
+ }
+
+ public void sectionTitle5_()
+ {
+ write( "</h6>" );
+ }
+
+ // ----------------------------------------------------------------------
+ //
+ // ----------------------------------------------------------------------
+
+ public void list()
+ {
+ write( "<ul>" );
+ }
+
+ public void list_()
+ {
+ write( "</ul>" );
+ itemFlag = false;
+ }
+
+ public void listItem()
+ {
+ write( "<li>" );
+ itemFlag = true;
+ // What follows is at least a paragraph.
+ }
+
+ public void listItem_()
+ {
+ write( "</li>" );
+ }
+
+ public void numberedList( int numbering )
+ {
+ write( "<ol type=\"" );
+ switch ( numbering )
+ {
+ case Sink.NUMBERING_LOWER_ALPHA:
+ write( "a" );
+ break;
+ case Sink.NUMBERING_UPPER_ALPHA:
+ write( "A" );
+ break;
+ case Sink.NUMBERING_LOWER_ROMAN:
+ write( "i" );
+ break;
+ case Sink.NUMBERING_UPPER_ROMAN:
+ write( "I" );
+ break;
+ case Sink.NUMBERING_DECIMAL:
+ default:
+ write( "1" );
+ }
+ write( "\">" );
+ }
+
+ public void numberedList_()
+ {
+ write( "</ol>" );
+ itemFlag = false;
+ }
+
+ public void numberedListItem()
+ {
+ write( "<li>" );
+ itemFlag = true;
+ // What follows is at least a paragraph.
+ }
+
+ public void numberedListItem_()
+ {
+ write( "</li>" );
+ }
+
+ public void definitionList()
+ {
+ write( "<dl>" );
+ }
+
+ public void definitionList_()
+ {
+ write( "</dl>" );
+ itemFlag = false;
+ }
+
+ public void definedTerm()
+ {
+ write( "<dt>" );
+ }
+
+ public void definedTerm_()
+ {
+ write( "</dt>" );
+ }
+
+ public void definition()
+ {
+ write( "<dd>" );
+ itemFlag = true;
+ // What follows is at least a paragraph.
+ }
+
+ public void definition_()
+ {
+ write( "</dd>" );
+ }
+
+ public void paragraph()
+ {
+ if ( !itemFlag )
+ {
+ write( "<p>" );
+ }
+ }
+
+ public void paragraph_()
+ {
+ if ( itemFlag )
+ {
+ itemFlag = false;
+ }
+ else
+ {
+ write( "</p>" );
+ }
+ }
+
+ public void verbatim( boolean boxed )
+ {
+ verbatimFlag = true;
+
+ write( "<div class=\"source\"><pre>" );
+ }
+
+ public void verbatim_()
+ {
+ write( "</pre></div>" );
+
+ verbatimFlag = false;
+
+ }
+
+ public void horizontalRule()
+ {
+ write( "<hr />" );
+ }
+
+ public void table()
+ {
+ write( "<table class=\"bodyTable\">" );
+ }
+
+ public void table_()
+ {
+ write( "</table>" );
+ }
+
+ public void tableRows( int[] justification, boolean grid )
+ {
+ write( "<tbody>" );
+
+ cellJustif = justification;
+ }
+
+ public void tableRows_()
+ {
+ write( "</tbody>" );
+
+ cellJustif = null;
+ }
+
+ private int rowMarker = 0;
+
+ //TODO: could probably make this more flexible but really i would just like a standard xhtml structure.
+ public void tableRow()
+ {
+ if ( rowMarker == 0 )
+ {
+ write( "<tr class=\"a\">" );
+
+ rowMarker = 1;
+ }
+ else
+ {
+ write( "<tr class=\"b\">" );
+
+ rowMarker = 0;
+ }
+
+ cellCount = 0;
+ }
+
+ public void tableRow_()
+ {
+ write( "</tr>" );
+
+ cellCount = 0;
+ }
+
+ public void tableCell()
+ {
+ tableCell( false );
+ }
+
+ public void tableHeaderCell()
+ {
+ tableCell( true );
+ }
+
+ public void tableCell( boolean headerRow )
+ {
+ String justif = null;
+
+ if ( cellJustif != null )
+ {
+ switch ( cellJustif[cellCount] )
+ {
+ case Parser.JUSTIFY_LEFT:
+ justif = "left";
+ break;
+ case Parser.JUSTIFY_RIGHT:
+ justif = "right";
+ break;
+ case Parser.JUSTIFY_CENTER:
+ justif = "center";
+ break;
+ }
+ }
+
+ if ( headerRow )
+ {
+ write( "<th" );
+ }
+ else
+ {
+ write( "<td" );
+ }
+
+ if ( justif != null )
+ {
+ write( " align=\"" + justif + "\"" );
+ }
+
+ write( ">" );
+ }
+
+ public void tableCell( String width )
+ {
+ tableCell( false, width );
+ }
+
+ public void tableHeaderCell( String width )
+ {
+ tableCell( true, width );
+ }
+
+ public void tableCell( boolean headerRow, String width )
+ {
+ String justif = null;
+
+ if ( cellJustif != null )
+ {
+ switch ( cellJustif[cellCount] )
+ {
+ case Parser.JUSTIFY_LEFT:
+ justif = "left";
+ break;
+ case Parser.JUSTIFY_RIGHT:
+ justif = "right";
+ break;
+ case Parser.JUSTIFY_CENTER:
+ justif = "center";
+ break;
+ }
+ }
+
+ String cellWidth = "width=\"" + width + "\"";
+
+ if ( headerRow )
+ {
+ write( "<th " );
+ }
+ else
+ {
+ write( "<td " );
+ }
+
+ if ( justif != null )
+ {
+ write( " align=\"" + justif + "\"" );
+ }
+
+ write( cellWidth + " >" );
+ }
+
+ public void tableCell_()
+ {
+ tableCell_( false );
+ }
+
+ public void tableHeaderCell_()
+ {
+ tableCell_( true );
+ }
+
+ public void tableCell_( boolean headerRow )
+ {
+ if ( headerRow )
+ {
+ write( "</th>" );
+ }
+ else
+ {
+ write( "</td>" );
+ }
+
+ ++cellCount;
+ }
+
+ public void tableCaption()
+ {
+ write( "<caption>" );
+ }
+
+ public void tableCaption_()
+ {
+ write( "</caption>" );
+ }
+
+ /**
+ * @see org.apache.maven.doxia.sink.SinkAdapter#figure()
+ */
+ public void figure()
+ {
+ write( "<img" );
+ }
+
+ /**
+ * @see org.apache.maven.doxia.sink.SinkAdapter#figure_()
+ */
+ public void figure_()
+ {
+ write( " />" );
+ }
+
+ /**
+ * @see org.apache.maven.doxia.sink.SinkAdapter#figureCaption()
+ */
+ public void figureCaption()
+ {
+ write( " alt=\"" );
+ }
+
+ /**
+ * @see org.apache.maven.doxia.sink.SinkAdapter#figureCaption_()
+ */
+ public void figureCaption_()
+ {
+ write( "\"" );
+ }
+
+ /**
+ * @see org.apache.maven.doxia.sink.SinkAdapter#figureGraphics(java.lang.String)
+ */
+ public void figureGraphics( String name )
+ {
+ write( " src=\"" + name + "\"" );
+ }
+
+ public void anchor( String name )
+ {
+ if ( !headFlag )
+ {
+ String id = HtmlTools.encodeId( name );
+ write( "<a name=\"" + id + "\">" );
+ }
+ }
+
+ public void anchor_()
+ {
+ if ( !headFlag )
+ {
+ write( "</a>" );
+ }
+ }
+
+ public void link( String name )
+ {
+ if ( !headFlag )
+ {
+ if ( isExternalLink( name ) )
+ {
+ write( "<a href=\"" + HtmlTools.escapeHTML( name ) + "\" class=\"externalLink\">" );
+ }
+ else
+ {
+ write( "<a href=\"" + HtmlTools.escapeHTML( name ) + "\">" );
+ }
+ }
+ }
+
+ public void link( String name, String target )
+ {
+ if ( !headFlag )
+ {
+ if ( isExternalLink( name ) )
+ {
+ write( "<a href=\"" + HtmlTools.escapeHTML( name ) + "\" class=\"externalLink\" target=\"" + target +
+ "\">" );
+ }
+ else
+ {
+ write( "<a href=\"" + HtmlTools.escapeHTML( name ) + "\" target=\"" + target + "\">" );
+ }
+ }
+ }
+
+ private static boolean isExternalLink( String href )
+ {
+ return href.toLowerCase().startsWith( "http" ) || href.toLowerCase().startsWith( "https" );
+ }
+
+ public void link_()
+ {
+ if ( !headFlag )
+ {
+ write( "</a>" );
+ }
+ }
+
+ public void italic()
+ {
+ if ( !headFlag )
+ {
+ write( "<i>" );
+ }
+ }
+
+ public void italic_()
+ {
+ if ( !headFlag )
+ {
+ write( "</i>" );
+ }
+ }
+
+ public void bold()
+ {
+ if ( !headFlag )
+ {
+ write( "<b>" );
+ }
+ }
+
+ public void bold_()
+ {
+ if ( !headFlag )
+ {
+ write( "</b>" );
+ }
+ }
+
+ public void monospaced()
+ {
+ if ( !headFlag )
+ {
+ write( "<tt>" );
+ }
+ }
+
+ public void monospaced_()
+ {
+ if ( !headFlag )
+ {
+ write( "</tt>" );
+ }
+ }
+
+ public void lineBreak()
+ {
+ if ( headFlag )
+ {
+ buffer.append( EOL );
+ }
+ else
+ {
+ write( "<br />" );
+ }
+ }
+
+ public void nonBreakingSpace()
+ {
+ if ( headFlag )
+ {
+ buffer.append( ' ' );
+ }
+ else
+ {
+ write( " " );
+ }
+ }
+
+ public void text( String text )
+ {
+ if ( headFlag )
+ {
+ buffer.append( text );
+ }
+ else
+ {
+ if ( verbatimFlag )
+ {
+ verbatimContent( text );
+ }
+ else
+ {
+ content( text );
+ }
+ }
+ }
+
+ public void rawText( String text )
+ {
+ write( text );
+ }
+
+ // ----------------------------------------------------------------------
+ //
+ // ----------------------------------------------------------------------
+
+ protected void write( String text )
+ {
+ String relativePathToBasedir = renderingContext.getRelativePath();
+
+ if ( relativePathToBasedir != null )
+ {
+ text = StringUtils.replace( text, "$relativePath", relativePathToBasedir );
+ }
+ else
+ {
+ text = StringUtils.replace( text, "$relativePath", "." );
+ }
+
+ writer.write( text );
+ }
+
+ protected String directiveValue( String key )
+ {
+ return directives.get( key );
+ }
+
+ protected void directive( String key )
+ {
+ write( directives.get( key ) );
+ }
+
+ protected void content( String text )
+ {
+ write( escapeHTML( text ) );
+ }
+
+ protected void verbatimContent( String text )
+
+ {
+ write( escapeHTML( text ) );
+ }
+
+ public static String escapeHTML( String text )
+ {
+ return HtmlTools.escapeHTML( text );
+ }
+
+ public static String encodeFragment( String text )
+ {
+ return encodeURL( StructureSink.linkToKey( text ) );
+ }
+
+ public static String encodeURL( String text )
+ {
+ return HtmlTools.encodeURL( text );
+ }
+
+ public void flush()
+ {
+ writer.flush();
+ }
+
+ public void close()
+ {
+ writer.close();
+ }
+
+ public RenderingContext getRenderingContext()
+ {
+ return renderingContext;
+ }
+}
Propchange: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/decoration/render/RenderingContext.java
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/decoration/render/RenderingContext.java?view=auto&rev=519333
==============================================================================
--- maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/decoration/render/RenderingContext.java (added)
+++ maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/decoration/render/RenderingContext.java Sat Mar 17 07:48:33 2007
@@ -0,0 +1,84 @@
+package org.apache.maven.doxia.module.xhtml.decoration.render;
+
+/*
+ * 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.
+ */
+
+import org.codehaus.plexus.util.PathTool;
+
+import java.io.File;
+
+/**
+ * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
+ * @version $Id:RenderingContext.java 348605 2005-11-24 12:02:44 +1100 (Thu, 24 Nov 2005) brett $
+ */
+public class RenderingContext
+{
+ private final File basedir;
+
+ private final String inputName;
+
+ private final String outputName;
+
+ private final String parserId;
+
+ private final String relativePath;
+
+ public RenderingContext( File basedir, String document )
+ {
+ this( basedir, document, null );
+ }
+
+ public RenderingContext( File basedir, String document, String parserId )
+ {
+ this.basedir = basedir;
+
+ this.outputName = document.substring( 0, document.lastIndexOf( "." ) ).replace( '\\', '/' ) + ".html";
+
+ this.relativePath = PathTool.getRelativePath( basedir.getPath(), new File( basedir, document ).getPath() );
+
+ this.inputName = document;
+
+ this.parserId = parserId;
+ }
+
+ public File getBasedir()
+ {
+ return basedir;
+ }
+
+ public String getInputName()
+ {
+ return inputName;
+ }
+
+ public String getOutputName()
+ {
+ return outputName;
+ }
+
+ public String getParserId()
+ {
+ return parserId;
+ }
+
+ public String getRelativePath()
+ {
+ return relativePath;
+ }
+}
Propchange: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/decoration/render/RenderingContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/decoration/render/RenderingContext.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlParserTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlParserTest.java?view=auto&rev=519333
==============================================================================
--- maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlParserTest.java (added)
+++ maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlParserTest.java Sat Mar 17 07:48:33 2007
@@ -0,0 +1,58 @@
+package org.apache.maven.doxia.module.xhtml;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.doxia.WellformednessCheckingSink;
+import org.apache.maven.doxia.parser.AbstractParserTestCase;
+import org.apache.maven.doxia.parser.Parser;
+
+import java.io.FileReader;
+import java.io.Reader;
+
+/**
+ * @author <a href="mailto:lars@trieloff.net">Lars Trieloff</a>
+ * @version $Id$
+ */
+public class XhtmlParserTest
+ extends AbstractParserTestCase
+{
+ protected Parser getParser()
+ {
+ return new XhtmlParser();
+ }
+
+ protected String getDocument()
+ {
+ return "src/test/site/xhtml/fun.html";
+ }
+
+ public void testParser()
+ throws Exception
+ {
+ //use the new wellformedness checking sink.
+ WellformednessCheckingSink sink = new WellformednessCheckingSink();
+
+ Reader reader = new FileReader( getTestFile( getBasedir(), getDocument() ) );
+
+ getParser().parse( reader, sink );
+
+ assertTrue( "Input not wellformed, offending element: " + sink.getOffender(), sink.isWellformed() );
+ }
+}
Propchange: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlParserTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlParserTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java?view=auto&rev=519333
==============================================================================
--- maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java (added)
+++ maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java Sat Mar 17 07:48:33 2007
@@ -0,0 +1,62 @@
+package org.apache.maven.doxia.module.xhtml;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.doxia.module.xhtml.decoration.render.RenderingContext;
+import org.apache.maven.doxia.sink.AbstractSinkTestCase;
+import org.apache.maven.doxia.sink.Sink;
+
+import java.io.File;
+import java.io.FileReader;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
+ * @version $Id:XhtmlSinkTest.java 348605 2005-11-24 12:02:44 +1100 (Thu, 24 Nov 2005) brett $
+ */
+public class XhtmlSinkTest
+ extends AbstractSinkTestCase
+{
+ protected String outputExtension()
+ {
+ return "xhtml";
+ }
+
+ // START SNIPPET: foo
+
+ protected Sink createSink()
+ throws Exception
+ {
+ String apt = "test.apt";
+
+ RenderingContext renderingContext =
+ new RenderingContext( getBasedirFile(), new File( getBasedirFile(), apt ).getPath(), "apt" );
+
+ FileReader reader = new FileReader( new File( getBasedirFile(), "src/test/resources/codehaus.dst" ) );
+
+ SinkDescriptorReader sdr = new SinkDescriptorReader();
+
+ Map directives = sdr.read( reader );
+
+ return new XhtmlSink( getTestWriter(), renderingContext, directives );
+ }
+
+ // END SNIPPET: foo
+}
Propchange: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"