maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vsive...@apache.org
Subject svn commit: r562690 - in /maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc: XdocMarkup.java XdocParser.java XdocSink.java
Date Sat, 04 Aug 2007 10:58:30 GMT
Author: vsiveton
Date: Sat Aug  4 03:58:29 2007
New Revision: 562690

URL: http://svn.apache.org/viewvc?view=rev&rev=562690
Log:
o using new abstract Parser/Sink classes

Modified:
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocMarkup.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocMarkup.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocMarkup.java?view=diff&rev=562690&r1=562689&r2=562690
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocMarkup.java
(original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocMarkup.java
Sat Aug  4 03:58:29 2007
@@ -21,6 +21,8 @@
 
 import javax.swing.text.html.HTML.Tag;
 
+import org.apache.maven.doxia.markup.XmlMarkup;
+
 /**
  * List of <code>Xdoc</code> markups.
  * <br/>
@@ -32,35 +34,8 @@
  * @since 1.0
  */
 public interface XdocMarkup
+    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 Xdoc tags
     // ----------------------------------------------------------------------

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java?view=diff&rev=562690&r1=562689&r2=562690
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java
(original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java
Sat Aug  4 03:58:29 2007
@@ -32,13 +32,12 @@
 import org.apache.maven.doxia.macro.MacroExecutionException;
 import org.apache.maven.doxia.macro.manager.MacroNotFoundException;
 import org.apache.maven.doxia.macro.MacroRequest;
-import org.apache.maven.doxia.parser.AbstractParser;
+import org.apache.maven.doxia.parser.AbstractXmlParser;
 import org.apache.maven.doxia.parser.ParseException;
 import org.apache.maven.doxia.sink.Sink;
 
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
-import org.codehaus.plexus.util.xml.pull.MXParser;
 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
@@ -51,7 +50,7 @@
  * @plexus.component role="org.apache.maven.doxia.parser.Parser" role-hint="xdoc"
  */
 public class XdocParser
-    extends AbstractParser
+    extends AbstractXmlParser
     implements XdocMarkup
 {
     /** The source content of the input reader. Used to pass into macros. */
@@ -76,84 +75,32 @@
     private Map macroParameters = new HashMap();
 
     /** {@inheritDoc} */
-    public void parse( Reader reader, Sink sink )
+    public void parse( Reader source, Sink sink )
         throws ParseException
     {
         try
         {
             StringWriter contentWriter = new StringWriter();
-            IOUtil.copy( reader, contentWriter );
+            IOUtil.copy( source, contentWriter );
             sourceContent = contentWriter.toString();
-
-            XmlPullParser parser = new MXParser();
-
-            parser.setInput( new StringReader( sourceContent ) );
-
-            parseXdoc( parser, sink );
-        }
-        catch ( XmlPullParserException ex )
-        {
-            throw new ParseException( "Error parsing the model!", ex );
         }
         catch ( IOException ex )
         {
-            throw new ParseException( "Error reading the input model!", ex );
+            throw new ParseException( "Error reading the input source: " + ex.getMessage(),
ex );
         }
-        catch ( MacroExecutionException ex )
+        finally
         {
-            throw new ParseException( "Macro execution failed!", ex );
+            IOUtil.close( source );
         }
-    }
 
-    /**
-     * Parse the model from the XmlPullParser into the given sink.
-     *
-     * @param parser A parser.
-     * @param sink the sink to receive the events.
-     * @throws XmlPullParserException if there's a problem parsing the model
-     * @throws MacroExecutionException if there's a problem executing a macro
-     */
-    public void parseXdoc( XmlPullParser parser, Sink sink )
-        throws XmlPullParserException, MacroExecutionException
-    {
-        int eventType = parser.getEventType();
+        Reader tmp = new StringReader( sourceContent );
 
-        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 );
-            }
-        }
+        super.parse( tmp, sink );
     }
 
-    /**
-     * Goes through the possible start tags.
-     *
-     * @param parser A parser.
-     * @param sink the sink to receive the events.
-     * @throws XmlPullParserException if there's a problem parsing the model
-     */
-    private void handleStartTag( XmlPullParser parser, Sink sink )
-        throws XmlPullParserException
+    /** {@inheritDoc} */
+    protected void handleStartTag( XmlPullParser parser, Sink sink )
+        throws XmlPullParserException, MacroExecutionException
     {
         isEmptyElement = parser.isEmptyElementTag();
 
@@ -409,18 +356,11 @@
         {
             handleRawText( sink, parser );
         }
-
     }
 
-    /**
-     * Goes through the possible end tags.
-     *
-     * @param parser A parser.
-     * @param sink the sink to receive the events.
-     * @throws MacroExecutionException if there's a problem executing a macro
-     */
-    private void handleEndTag( XmlPullParser parser, Sink sink )
-        throws MacroExecutionException
+    /** {@inheritDoc} */
+    protected void handleEndTag( XmlPullParser parser, Sink sink )
+        throws XmlPullParserException, MacroExecutionException
     {
         if ( parser.getName().equals( DOCUMENT_TAG.toString() ) )
         {
@@ -591,11 +531,11 @@
         }
         else if ( !isEmptyElement )
         {
-            sink.rawText( START_MARKUP + SLASH_MARKUP );
+            sink.rawText( String.valueOf( LESS_THAN ) + String.valueOf( SLASH ) );
 
             sink.rawText( parser.getName() );
 
-            sink.rawText( END_MARKUP );
+            sink.rawText( String.valueOf( GREATER_THAN ) );
         }
         else
         {
@@ -603,13 +543,9 @@
         }
     }
 
-    /**
-     * Handles text events.
-     *
-     * @param parser A parser.
-     * @param sink the sink to receive the events.
-     */
-    private void handleText( XmlPullParser parser, Sink sink )
+    /** {@inheritDoc} */
+    protected void handleText( XmlPullParser parser, Sink sink )
+        throws XmlPullParserException
     {
         String text = parser.getText();
 
@@ -619,6 +555,10 @@
         }
     }
 
+    // ----------------------------------------------------------------------
+    // Private methods
+    // ----------------------------------------------------------------------
+
     /**
      * Handles raw text events.
      *
@@ -627,7 +567,7 @@
      */
     private void handleRawText( Sink sink, XmlPullParser parser )
     {
-        sink.rawText( START_MARKUP );
+        sink.rawText( String.valueOf( LESS_THAN ) );
 
         sink.rawText( parser.getName() );
 
@@ -635,19 +575,19 @@
 
         for ( int i = 0; i < count; i++ )
         {
-            sink.rawText( SPACE_MARKUP );
+            sink.rawText( String.valueOf( SPACE ) );
 
             sink.rawText( parser.getAttributeName( i ) );
 
-            sink.rawText( EQUAL_MARKUP );
+            sink.rawText( String.valueOf( EQUAL ) );
 
-            sink.rawText( QUOTE_MARKUP );
+            sink.rawText( String.valueOf( QUOTE ) );
 
             sink.rawText( parser.getAttributeValue( i ) );
 
-            sink.rawText( QUOTE_MARKUP );
+            sink.rawText( String.valueOf( QUOTE ) );
         }
 
-        sink.rawText( END_MARKUP );
+        sink.rawText( String.valueOf( GREATER_THAN ) );
     }
 }

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java?view=diff&rev=562690&r1=562689&r2=562690
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java
(original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java
Sat Aug  4 03:58:29 2007
@@ -20,15 +20,13 @@
  */
 
 import java.io.Writer;
-import java.util.Enumeration;
 
-import javax.swing.text.AttributeSet;
 import javax.swing.text.MutableAttributeSet;
 import javax.swing.text.SimpleAttributeSet;
 import javax.swing.text.html.HTML.Attribute;
 import javax.swing.text.html.HTML.Tag;
 
-import org.apache.maven.doxia.sink.SinkAdapter;
+import org.apache.maven.doxia.sink.AbstractXmlSink;
 import org.apache.maven.doxia.util.HtmlTools;
 import org.apache.maven.doxia.util.LineBreaker;
 import org.apache.maven.doxia.parser.Parser;
@@ -41,7 +39,7 @@
  * @since 1.0
  */
 public class XdocSink
-    extends SinkAdapter
+    extends AbstractXmlSink
     implements XdocMarkup
 {
     // ----------------------------------------------------------------------
@@ -346,13 +344,13 @@
     {
         if ( depth == 1 )
         {
-            markup( START_MARKUP + SECTION_TAG.toString() + SPACE_MARKUP + Attribute.NAME
+ EQUAL_MARKUP
-                + QUOTE_MARKUP );
+            markup( String.valueOf( LESS_THAN ) + SECTION_TAG.toString() + String.valueOf(
SPACE ) + Attribute.NAME
+                + String.valueOf( EQUAL ) + String.valueOf( QUOTE ) );
         }
         else if ( depth == 2 )
         {
-            markup( START_MARKUP + SUBSECTION_TAG.toString() + SPACE_MARKUP + Attribute.NAME
+ EQUAL_MARKUP
-                + QUOTE_MARKUP );
+            markup( String.valueOf( LESS_THAN ) + SUBSECTION_TAG.toString() + String.valueOf(
SPACE ) + Attribute.NAME
+                + String.valueOf( EQUAL ) + String.valueOf( QUOTE ) );
         }
     }
 
@@ -394,7 +392,7 @@
     {
         if ( depth == 1 || depth == 2 )
         {
-            markup( QUOTE_MARKUP + END_MARKUP );
+            markup( String.valueOf( QUOTE ) + String.valueOf( GREATER_THAN ) );
         }
         else if ( depth == 3 )
         {
@@ -601,31 +599,32 @@
      */
     public void figure()
     {
-        markup( START_MARKUP + Tag.IMG );
+        markup( String.valueOf( SPACE ) + Tag.IMG );
     }
 
     /** {@inheritDoc} */
     public void figure_()
     {
-        markup( SPACE_MARKUP + SLASH_MARKUP + END_MARKUP );
+        markup( String.valueOf( SPACE ) + String.valueOf( SLASH ) + String.valueOf( GREATER_THAN
) );
     }
 
     /** {@inheritDoc} */
     public void figureGraphics( String s )
     {
-        markup( SPACE_MARKUP + Attribute.SRC + EQUAL_MARKUP + QUOTE_MARKUP + s + QUOTE_MARKUP
);
+        markup( String.valueOf( SPACE ) + Attribute.SRC + String.valueOf( EQUAL ) + String.valueOf(
QUOTE ) + s
+            + String.valueOf( QUOTE ) );
     }
 
     /** {@inheritDoc} */
     public void figureCaption()
     {
-        markup( SPACE_MARKUP + Attribute.ALT + EQUAL_MARKUP + QUOTE_MARKUP );
+        markup( String.valueOf( SPACE ) + Attribute.ALT + String.valueOf( EQUAL ) + String.valueOf(
QUOTE ) );
     }
 
     /** {@inheritDoc} */
     public void figureCaption_()
     {
-        markup( QUOTE_MARKUP );
+        markup( String.valueOf( QUOTE ) );
     }
 
     /**
@@ -1123,143 +1122,9 @@
         out.close();
     }
 
-    // ----------------------------------------------------------------------
-    // TODO Move these in core utils
-    // ----------------------------------------------------------------------
-
-    /**
-     * Starts a Tag, for instance:
-     * <pre>
-     * &lt;tag&gt;
-     * </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>
-     * &lt;tag attName="attValue"&gt;
-     * </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>
-     * &lt;tag attName="attValue"&gt;
-     * </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 );
-        }
-
-        markup( sb.toString() );
-    }
-
-    /**
-     * Ends a Tag, for instance:
-     * <pre>
-     * &lt;/tag&gt;
-     * </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 );
-
-        markup( sb.toString() );
-    }
-
-    /**
-     * Starts a simple Tag, for instance:
-     * <pre>
-     * &lt;tag /&gt;
-     * </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>
-     * &lt;tag attName="attValue" /&gt;
-     * </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 )
+    /** {@inheritDoc} */
+    protected void write( String text )
     {
-        writeStartTag ( t, att, true );
+        markup( text );
     }
 }



Mime
View raw message