Author: vsiveton
Date: Sat Aug 4 04:01:47 2007
New Revision: 562692
URL: http://svn.apache.org/viewvc?view=rev&rev=562692
Log:
o using new abstract Parser/Sink classes
Modified:
maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlMarkup.java
maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java
maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java
Modified:
maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlMarkup.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlMarkup.java?view=diff&rev=562692&r1=562691&r2=562692
==============================================================================
---
maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlMarkup.java
(original)
+++
maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlMarkup.java
Sat Aug 4 04:01:47 2007
@@ -21,6 +21,8 @@
import javax.swing.text.html.HTML.Tag;
+import org.apache.maven.doxia.markup.XmlMarkup;
+
/**
* List of <code>Xhtml</code> markups.
* <br/>
@@ -32,35 +34,8 @@
* @since 1.0
*/
public interface XhtmlMarkup
+ extends XmlMarkup
{
- /** The vm line separator */
- /** TODO should be in a super interface */
- String EOL = System.getProperty( "line.separator" );
-
- // ----------------------------------------------------------------------
- // Markup separators
- // ----------------------------------------------------------------------
-
- /** TODO should be in a super XML interface */
-
- /** Xhtml start markup: '<' */
- String START_MARKUP = "<";
-
- /** Xhtml end markup: '>' */
- String END_MARKUP = ">";
-
- /** Xhtml quote markup: '\"' */
- String QUOTE_MARKUP = "\"";
-
- /** Xhtml slash markup: '/' */
- String SLASH_MARKUP = "/";
-
- /** Xhtml space markup: ' ' */
- String SPACE_MARKUP = " ";
-
- /** Xhtml equal markup: '=' */
- String EQUAL_MARKUP = "=";
-
// ----------------------------------------------------------------------
// Specific XHTML tags
// ----------------------------------------------------------------------
Modified:
maven/doxia/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/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java?view=diff&rev=562692&r1=562691&r2=562692
==============================================================================
---
maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java
(original)
+++
maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java
Sat Aug 4 04:01:47 2007
@@ -19,17 +19,14 @@
* under the License.
*/
-import java.io.IOException;
-import java.io.Reader;
import java.util.Stack;
import javax.swing.text.html.HTML.Attribute;
import javax.swing.text.html.HTML.Tag;
-import org.apache.maven.doxia.parser.ParseException;
-import org.apache.maven.doxia.parser.Parser;
+import org.apache.maven.doxia.macro.MacroExecutionException;
+import org.apache.maven.doxia.parser.AbstractXmlParser;
import org.apache.maven.doxia.sink.Sink;
-import org.codehaus.plexus.util.xml.pull.MXParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@@ -42,7 +39,8 @@
* @since 1.0
*/
public class XhtmlParser
- implements Parser, XhtmlMarkup
+ extends AbstractXmlParser
+ implements XhtmlMarkup
{
/**
* This stack is needed to keep track of the different link and
anchor-types
@@ -68,66 +66,8 @@
private static final String ANCHOR = "anchor";
/** [EMAIL PROTECTED] */
- public void parse( Reader reader, Sink sink )
- throws ParseException
- {
- try
- {
- XmlPullParser parser = new MXParser();
-
- parser.setInput( reader );
-
- parseXhtml( parser, sink );
- }
- catch ( XmlPullParserException ex )
- {
- throw new ParseException( "Error parsing the model!", ex );
- }
- }
-
- /**
- * @param parser
- * @param sink
- * @throws IOException if any
- * @throws XmlPullParserException if any
- */
- public void parseXhtml( XmlPullParser parser, Sink sink ) throws
XmlPullParserException
- {
- int eventType = parser.getEventType();
-
- while ( eventType != XmlPullParser.END_DOCUMENT )
- {
- if ( eventType == XmlPullParser.START_TAG )
- {
- handleStartTag( parser, sink );
- }
- else if ( eventType == XmlPullParser.END_TAG )
- {
- handleEndTag( parser, sink );
- }
- else if ( eventType == XmlPullParser.TEXT )
- {
- handleText( parser, sink );
- }
-
- try
- {
- eventType = parser.next();
- }
- catch ( IOException io )
- {
- throw new XmlPullParserException( "Error parsing the model.",
parser, io );
- }
- }
- }
-
- /**
- * Goes through the possible start tags.
- *
- * @param parser A parser.
- * @param sink the sink to receive the events.
- */
- private void handleStartTag( XmlPullParser parser, Sink sink )
+ protected void handleStartTag( XmlPullParser parser, Sink sink )
+ throws XmlPullParserException, MacroExecutionException
{
if ( parser.getName().equals( Tag.TITLE.toString() ) )
{
@@ -278,13 +218,9 @@
}
}
- /**
- * Goes through the possible end tags.
- *
- * @param parser A parser.
- * @param sink the sink to receive the events.
- */
- private void handleEndTag( XmlPullParser parser, Sink sink )
+ /** [EMAIL PROTECTED] */
+ protected void handleEndTag( XmlPullParser parser, Sink sink )
+ throws XmlPullParserException, MacroExecutionException
{
if ( parser.getName().equals( Tag.TITLE.toString() ) )
{
@@ -378,16 +314,16 @@
}
}
- /**
- * Handles text events.
- *
- * @param parser A parser.
- * @param sink the sink to receive the events.
- */
- private void handleText( XmlPullParser parser, Sink sink )
+ /** [EMAIL PROTECTED] */
+ protected void handleText( XmlPullParser parser, Sink sink )
+ throws XmlPullParserException
{
text( sink, parser.getText() );
}
+
+ // ----------------------------------------------------------------------
+ // Private methods
+ // ----------------------------------------------------------------------
/**
* Sends the text to the sink, utilizing the nonBreakingspace of the sink.
Modified:
maven/doxia/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/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java?view=diff&rev=562692&r1=562691&r2=562692
==============================================================================
---
maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java
(original)
+++
maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java
Sat Aug 4 04:01:47 2007
@@ -21,6 +21,7 @@
import org.apache.maven.doxia.module.xhtml.decoration.render.RenderingContext;
import org.apache.maven.doxia.parser.Parser;
+import org.apache.maven.doxia.sink.AbstractXmlSink;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.doxia.sink.StructureSink;
import org.apache.maven.doxia.util.HtmlTools;
@@ -28,10 +29,8 @@
import java.io.PrintWriter;
import java.io.Writer;
-import java.util.Enumeration;
import java.util.Map;
-import javax.swing.text.AttributeSet;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.html.HTML.Attribute;
@@ -41,10 +40,11 @@
* Xhtml sink implementation.
*
* @author Jason van Zyl
+ * @version $Id$
* @since 1.0
*/
public class XhtmlSink
- extends AbstractXhtmlSink
+ extends AbstractXmlSink
implements XhtmlMarkup
{
// ----------------------------------------------------------------------
@@ -906,31 +906,32 @@
*/
public void figure()
{
- write( START_MARKUP + Tag.IMG );
+ write( String.valueOf( LESS_THAN ) + Tag.IMG );
}
/** [EMAIL PROTECTED] */
public void figure_()
{
- write( SPACE_MARKUP + SLASH_MARKUP + END_MARKUP );
+ write( String.valueOf( LESS_THAN ) + String.valueOf( SLASH ) +
String.valueOf( GREATER_THAN ) );
}
/** [EMAIL PROTECTED] */
public void figureCaption()
{
- write( SPACE_MARKUP + Attribute.ALT + EQUAL_MARKUP + QUOTE_MARKUP );
+ write( String.valueOf( LESS_THAN ) + Attribute.ALT + String.valueOf(
EQUAL ) + String.valueOf( QUOTE ) );
}
/** [EMAIL PROTECTED] */
public void figureCaption_()
{
- write( QUOTE_MARKUP );
+ write( String.valueOf( QUOTE ) );
}
/** [EMAIL PROTECTED] */
public void figureGraphics( String name )
{
- write( SPACE_MARKUP + Attribute.SRC + EQUAL_MARKUP + QUOTE_MARKUP +
name + QUOTE_MARKUP );
+ write( String.valueOf( SPACE ) + Attribute.SRC + String.valueOf( EQUAL
) + String.valueOf( QUOTE ) + name
+ + String.valueOf( QUOTE ) );
}
/**
@@ -977,33 +978,34 @@
*/
public void link( String name, String target )
{
- if ( !headFlag )
+ if ( headFlag )
{
+ return;
+ }
- MutableAttributeSet att = new SimpleAttributeSet();
+ MutableAttributeSet att = new SimpleAttributeSet();
- if ( target != null )
- {
- att.addAttribute( Attribute.TARGET, target );
- }
+ if ( target != null )
+ {
+ att.addAttribute( Attribute.TARGET, target );
+ }
- if ( StructureSink.isExternalLink( name ) || isExternalHtml( name
) )
+ if ( StructureSink.isExternalLink( name ) || isExternalHtml( name ) )
+ {
+ if ( isExternalLink( name ) )
{
- if ( isExternalLink( name ) )
- {
- att.addAttribute( Attribute.CLASS, "externalLink" );
- }
+ att.addAttribute( Attribute.CLASS, "externalLink" );
+ }
- att.addAttribute( Attribute.HREF, HtmlTools.escapeHTML( name )
);
+ att.addAttribute( Attribute.HREF, HtmlTools.escapeHTML( name ) );
- writeStartTag( Tag.A, att );
- }
- else
- {
- att.addAttribute( Attribute.HREF, "#" + HtmlTools.escapeHTML(
name ) );
+ writeStartTag( Tag.A, att );
+ }
+ else
+ {
+ att.addAttribute( Attribute.HREF, "#" + HtmlTools.escapeHTML( name
) );
- writeStartTag( Tag.A, att );
- }
+ writeStartTag( Tag.A, att );
}
}
@@ -1184,13 +1186,7 @@
writer.close();
}
- // ----------------------------------------------------------------------
- //
- // ----------------------------------------------------------------------
-
- /**
- * @param text
- */
+ /** [EMAIL PROTECTED] */
protected void write( String text )
{
String relativePathToBasedir = renderingContext.getRelativePath();
@@ -1207,6 +1203,11 @@
writer.write( text );
}
+ // ----------------------------------------------------------------------
+ //
+ // ----------------------------------------------------------------------
+
+
protected void content( String text )
{
write( escapeHTML( text ) );
@@ -1258,145 +1259,5 @@
public RenderingContext getRenderingContext()
{
return renderingContext;
- }
-
- // ----------------------------------------------------------------------
- // TODO Move these in core utils
- // ----------------------------------------------------------------------
-
- /**
- * Starts a Tag, for instance:
- * <pre>
- * <tag>
- * </pre>
- *
- * @param t a non null tag
- * @see #writeStartTag(Tag, MutableAttributeSet)
- */
- private void writeStartTag ( Tag t )
- {
- writeStartTag ( t, null );
- }
-
- /**
- * Starts a Tag with attributes, for instance:
- * <pre>
- * <tag attName="attValue">
- * </pre>
- *
- * @param t a non null tag
- * @param att a set of attributes
- * @see #writeStartTag(Tag, MutableAttributeSet, boolean)
- */
- private void writeStartTag ( Tag t, MutableAttributeSet att )
- {
- writeStartTag ( t, att, false );
- }
-
- /**
- * Starts a Tag with attributes, for instance:
- * <pre>
- * <tag attName="attValue">
- * </pre>
- *
- * @param t a non null tag
- * @param att a set of attributes
- * @param isSimpleTag boolean to write as a simple tag
- */
- private void writeStartTag( Tag t, MutableAttributeSet att, boolean
isSimpleTag )
- {
- if ( t == null )
- {
- throw new IllegalArgumentException( "A tag is required" );
- }
-
- StringBuffer sb = new StringBuffer();
- sb.append( START_MARKUP );
- sb.append( t.toString() );
-
- if ( att != null )
- {
- Enumeration names = att.getAttributeNames();
-
- while ( names.hasMoreElements() )
- {
- Object key = names.nextElement();
- Object value = att.getAttribute( key );
-
- if ( value instanceof AttributeSet )
- {
- // ignored
- }
- else
- {
- sb.append( SPACE_MARKUP ).append( key.toString() ).append(
EQUAL_MARKUP ).append( QUOTE_MARKUP )
- .append( value.toString() ).append( QUOTE_MARKUP );
- }
- }
- }
-
- if ( isSimpleTag )
- {
- sb.append( SPACE_MARKUP ).append( SLASH_MARKUP );
- }
-
- sb.append( END_MARKUP );
-
- if ( isSimpleTag )
- {
- sb.append( EOL );
- }
-
- write( sb.toString() );
- }
-
- /**
- * Ends a Tag, for instance:
- * <pre>
- * </tag>
- * </pre>
- *
- * @param t a tag
- */
- private void writeEndTag( Tag t )
- {
- StringBuffer sb = new StringBuffer();
- sb.append( START_MARKUP );
- sb.append( SLASH_MARKUP );
- sb.append( t.toString() );
- sb.append( END_MARKUP );
-
- sb.append( EOL );
-
- write( sb.toString() );
- }
-
- /**
- * Starts a simple Tag, for instance:
- * <pre>
- * <tag />
- * </pre>
- *
- * @param t a non null tag
- * @see #writeSimpleTag(Tag, MutableAttributeSet)
- */
- private void writeSimpleTag ( Tag t )
- {
- writeSimpleTag ( t, null );
- }
-
- /**
- * Starts a simple Tag with attributes, for instance:
- * <pre>
- * <tag attName="attValue" />
- * </pre>
- *
- * @param t a non null tag
- * @param att a set of attributes
- * @see #writeStartTag(Tag, MutableAttributeSet, boolean)
- */
- private void writeSimpleTag ( Tag t, MutableAttributeSet att )
- {
- writeStartTag ( t, att, true );
}
}