Author: ltheussl
Date: Fri May 29 09:33:31 2009
New Revision: 779903

URL: http://svn.apache.org/viewvc?rev=779903&view=rev
Log:
Formatting, checkstyle fixes

Modified:
    
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java
    
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/ByLineSource.java
    
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/HtmlTools.java
    
maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java

Modified: 
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java
URL: 
http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java?rev=779903&r1=779902&r2=779903&view=diff
==============================================================================
--- 
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java
 (original)
+++ 
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java
 Fri May 29 09:33:31 2009
@@ -41,7 +41,6 @@
 
 import org.apache.maven.doxia.logging.Log;
 import org.apache.maven.doxia.macro.MacroExecutionException;
-import org.apache.maven.doxia.markup.HtmlMarkup;
 import org.apache.maven.doxia.markup.XmlMarkup;
 import org.apache.maven.doxia.sink.Sink;
 import org.apache.maven.doxia.sink.SinkEventAttributeSet;
@@ -371,8 +370,6 @@
      * <ul>
      * <li>the entities with names <code>#160</code>, <code>nbsp</code> and 
<code>#x00A0</code>
      * are emitted as <code>nonBreakingSpace()</code> events.</li>
-     * <li>if an entity cannot be resolved, it is emitted as an 
<code>unknown()</code> event,
-     * with a required parameter that contains {...@link 
HtmlMarkup#ENTITY_TYPE} as first argument.</li>
      * </ul>
      *
      * @param parser A parser, not null.
@@ -1053,211 +1050,222 @@
             char ch = more();
             if ( ch == '#' )
             {
-                // parse character reference
-                char charRef = 0;
-                ch = more();
-                StringBuffer sb = new StringBuffer();
-                if ( ch == 'x' )
+                return numericEntity( ch );
+            }
+            else
+            {
+                return namedEntity( ch );
+            }
+        }
+
+        /** {...@inheritdoc} */
+        // Fix PLXUTILS-110
+        public void defineEntityReplacementText( String entityName,
+                                                String replacementText )
+            throws XmlPullParserException
+        {
+            //      throw new XmlPullParserException("not allowed");
+
+            if ( !replacementText.startsWith( "&#" ) && this.entityName != 
null && replacementText.length() > 1 )
+            {
+                String tmp = replacementText.substring( 1, 
replacementText.length() - 1 );
+                for ( int i = 0; i < this.entityName.length; i++ )
                 {
-                    // encoded in hex
-                    while ( true )
+                    if ( this.entityName[i] != null && 
this.entityName[i].equals( tmp ) )
                     {
-                        ch = more();
-                        if ( ch >= '0' && ch <= '9' )
-                        {
-                            sb.append( ch );
-                            charRef = (char) ( charRef * 16 + ( ch - '0' ) );
-                        }
-                        else if ( ch >= 'a' && ch <= 'f' )
-                        {
-                            sb.append( ch );
-                            charRef = (char) ( charRef * 16 + ( ch - ( 'a' - 
10 ) ) );
-                        }
-                        else if ( ch >= 'A' && ch <= 'F' )
-                        {
-                            sb.append( ch );
-                            charRef = (char) ( charRef * 16 + ( ch - ( 'A' - 
10 ) ) );
-                        }
-                        else if ( ch == ';' )
-                        {
-                            break;
-                        }
-                        else
-                        {
-                            throw new XmlPullParserException(
-                                                              "character 
reference (with hex value) may not contain " +
-                                                               printable( ch 
), this, null );
-                        }
+                        replacementText = this.entityReplacement[i];
                     }
                 }
-                else
+            }
+
+            //protected char[] entityReplacement[];
+            ensureEntityCapacity();
+
+            // this is to make sure that if interning works we will take 
advantage of it ...
+            this.entityName[entityEnd] = newString( entityName.toCharArray(), 
0, entityName.length() );
+            entityNameBuf[entityEnd] = entityName.toCharArray();
+
+            entityReplacement[entityEnd] = replacementText;
+            entityReplacementBuf[entityEnd] = replacementText.toCharArray();
+            if ( !allStringsInterned )
+            {
+                entityNameHash[ entityEnd ] =
+                    fastHash( entityNameBuf[entityEnd], 0, 
entityNameBuf[entityEnd].length );
+            }
+            ++entityEnd;
+            //TODO disallow < or & in entity replacement text (or ]]>???)
+            // TOOD keepEntityNormalizedForAttributeValue cached as well ...
+        }
+
+        private char[] namedEntity( char ch )
+                throws IOException, XmlPullParserException
+        {
+            // [68] EntityRef ::= '&' Name ';'
+            // scan anem until ;
+            if ( !isNameStartChar( ch ) )
+            {
+                throw new XmlPullParserException( "entity reference names can 
not start with character '"
+                        + printable( ch ) + "'", this, null );
+            }
+            while ( true )
+            {
+                ch = more();
+                if ( ch == ';' )
                 {
-                    // encoded in decimal
-                    while ( true )
-                    {
-                        if ( ch >= '0' && ch <= '9' )
-                        {
-                            charRef = (char) ( charRef * 10 + ( ch - '0' ) );
-                        }
-                        else if ( ch == ';' )
-                        {
-                            break;
-                        }
-                        else
-                        {
-                            throw new XmlPullParserException(
-                                    "character reference (with decimal value) 
may not contain " +
-                                    printable( ch ), this, null );
-                        }
-                        ch = more();
-                    }
+                    break;
                 }
-                posEnd = pos - 1;
-                if ( sb.length() > 0 )
+                if ( !isNameChar( ch ) )
                 {
-                    char[] tmp = HtmlTools.toChars( Integer.parseInt( 
sb.toString(), 16 ) );
-                    charRefOneCharBuf = tmp;
-                    if ( tokenize )
-                    {
-                        text = newString( charRefOneCharBuf, 0, 
charRefOneCharBuf.length );
-                    }
-                    return charRefOneCharBuf;
+                    throw new XmlPullParserException( "entity reference name 
can not contain character "
+                            + printable( ch ) + "'", this, null );
                 }
-                charRefOneCharBuf[0] = charRef;
+            }
+            posEnd = pos - 1;
+            // determine what name maps to
+            final int len = posEnd - posStart;
+            if ( len == 2 && buf[posStart] == 'l' && buf[posStart + 1] == 't' )
+            {
                 if ( tokenize )
                 {
-                    text = newString( charRefOneCharBuf, 0, 1 );
+                    text = "<";
                 }
+                charRefOneCharBuf[0] = '<';
+                return charRefOneCharBuf;
+                // if(paramPC || isParserTokenizing) {
+                // if(pcEnd >= pc.length) ensurePC();
+                // pc[pcEnd++] = '<';
+                // }
+            }
+            else if ( len == 3 && buf[posStart] == 'a' && buf[posStart + 1] == 
'm' && buf[posStart + 2] == 'p' )
+            {
+                if ( tokenize )
+                {
+                    text = "&";
+                }
+                charRefOneCharBuf[0] = '&';
+                return charRefOneCharBuf;
+            }
+            else if ( len == 2 && buf[posStart] == 'g' && buf[posStart + 1] == 
't' )
+            {
+                if ( tokenize )
+                {
+                    text = ">";
+                }
+                charRefOneCharBuf[0] = '>';
+                return charRefOneCharBuf;
+            }
+            else if ( len == 4 && buf[posStart] == 'a' && buf[posStart + 1] == 
'p'
+                    && buf[posStart + 2] == 'o' && buf[posStart + 3] == 's' )
+            {
+                if ( tokenize )
+                {
+                    text = "'";
+                }
+                charRefOneCharBuf[0] = '\'';
+                return charRefOneCharBuf;
+            }
+            else if ( len == 4 && buf[posStart] == 'q' && buf[posStart + 1] == 
'u'
+                    && buf[posStart + 2] == 'o' && buf[posStart + 3] == 't' )
+            {
+                if ( tokenize )
+                {
+                    text = "\"";
+                }
+                charRefOneCharBuf[0] = '"';
                 return charRefOneCharBuf;
             }
             else
             {
-                // [68] EntityRef ::= '&' Name ';'
-                // scan anem until ;
-                if ( !isNameStartChar( ch ) )
+                final char[] result = lookuEntityReplacement( len );
+                if ( result != null )
                 {
-                    throw new XmlPullParserException( "entity reference names 
can not start with character '" +
-                     printable( ch ) + "'", this, null );
+                    return result;
                 }
+            }
+            if ( tokenize )
+            {
+                text = null;
+            }
+            return null;
+        }
+
+        private char[] numericEntity( char ch )
+                throws IOException, XmlPullParserException
+        {
+            // parse character reference
+            char charRef = 0;
+            ch = more();
+            StringBuffer sb = new StringBuffer();
+            if ( ch == 'x' )
+            {
+                // encoded in hex
                 while ( true )
                 {
                     ch = more();
-                    if ( ch == ';' )
+                    if ( ch >= '0' && ch <= '9' )
                     {
-                        break;
+                        sb.append( ch );
+                        charRef = (char) ( charRef * 16 + ( ch - '0' ) );
                     }
-                    if ( !isNameChar( ch ) )
+                    else if ( ch >= 'a' && ch <= 'f' )
                     {
-                        throw new XmlPullParserException( "entity reference 
name can not contain character " +
-                         printable( ch ) + "'", this, null );
+                        sb.append( ch );
+                        charRef = (char) ( charRef * 16 + ( ch - ( 'a' - 10 ) 
) );
                     }
-                }
-                posEnd = pos - 1;
-                // determine what name maps to
-                final int len = posEnd - posStart;
-                if ( len == 2 && buf[posStart] == 'l' && buf[posStart + 1] == 
't' )
-                {
-                    if ( tokenize )
+                    else if ( ch >= 'A' && ch <= 'F' )
                     {
-                        text = "<";
+                        sb.append( ch );
+                        charRef = (char) ( charRef * 16 + ( ch - ( 'A' - 10 ) 
) );
                     }
-                    charRefOneCharBuf[0] = '<';
-                    return charRefOneCharBuf;
-                    // if(paramPC || isParserTokenizing) {
-                    // if(pcEnd >= pc.length) ensurePC();
-                    // pc[pcEnd++] = '<';
-                    // }
-                }
-                else if ( len == 3 && buf[posStart] == 'a' && buf[posStart + 
1] == 'm' && buf[posStart + 2] == 'p' )
-                {
-                    if ( tokenize )
+                    else if ( ch == ';' )
                     {
-                        text = "&";
+                        break;
                     }
-                    charRefOneCharBuf[0] = '&';
-                    return charRefOneCharBuf;
-                }
-                else if ( len == 2 && buf[posStart] == 'g' && buf[posStart + 
1] == 't' )
-                {
-                    if ( tokenize )
+                    else
                     {
-                        text = ">";
+                        throw new XmlPullParserException( "character reference 
(with hex value) may not contain "
+                                + printable( ch ), this, null );
                     }
-                    charRefOneCharBuf[0] = '>';
-                    return charRefOneCharBuf;
                 }
-                else if ( len == 4 && buf[posStart] == 'a' && buf[posStart + 
1] == 'p' && buf[posStart + 2] == 'o'
-                    && buf[posStart + 3] == 's' )
+            }
+            else
+            {
+                // encoded in decimal
+                while ( true )
                 {
-                    if ( tokenize )
+                    if ( ch >= '0' && ch <= '9' )
                     {
-                        text = "'";
+                        charRef = (char) ( charRef * 10 + ( ch - '0' ) );
                     }
-                    charRefOneCharBuf[0] = '\'';
-                    return charRefOneCharBuf;
-                }
-                else if ( len == 4 && buf[posStart] == 'q' && buf[posStart + 
1] == 'u' && buf[posStart + 2] == 'o'
-                    && buf[posStart + 3] == 't' )
-                {
-                    if ( tokenize )
+                    else if ( ch == ';' )
                     {
-                        text = "\"";
+                        break;
                     }
-                    charRefOneCharBuf[0] = '"';
-                    return charRefOneCharBuf;
-                }
-                else
-                {
-                    final char[] result = lookuEntityReplacement( len );
-                    if ( result != null )
+                    else
                     {
-                        return result;
+                        throw new XmlPullParserException( "character reference 
(with decimal value) may not contain "
+                                + printable( ch ), this, null );
                     }
+                    ch = more();
                 }
-                if ( tokenize )
-                {
-                    text = null;
-                }
-                return null;
             }
-        }
-
-        /** {...@inheritdoc} */
-        // Fix PLXUTILS-110
-        public void defineEntityReplacementText(String entityName,
-                                                String replacementText)
-            throws XmlPullParserException
-        {
-            //      throw new XmlPullParserException("not allowed");
-
-            if ( !replacementText.startsWith( "&#" ) && this.entityName != 
null && replacementText.length() > 1 )
+            posEnd = pos - 1;
+            if ( sb.length() > 0 )
             {
-                String tmp = replacementText.substring( 1, 
replacementText.length() - 1 );
-                for ( int i = 0; i < this.entityName.length; i++ )
+                char[] tmp = HtmlTools.toChars( Integer.parseInt( 
sb.toString(), 16 ) );
+                charRefOneCharBuf = tmp;
+                if ( tokenize )
                 {
-                    if ( this.entityName[i] != null && 
this.entityName[i].equals( tmp ) )
-                    {
-                        replacementText = this.entityReplacement[i];
-                    }
+                    text = newString( charRefOneCharBuf, 0, 
charRefOneCharBuf.length );
                 }
+                return charRefOneCharBuf;
             }
-
-            //protected char[] entityReplacement[];
-            ensureEntityCapacity();
-
-            // this is to make sure that if interning works we will take 
advantage of it ...
-            this.entityName[entityEnd] = newString(entityName.toCharArray(), 
0, entityName.length());
-            entityNameBuf[entityEnd] = entityName.toCharArray();
-
-            entityReplacement[entityEnd] = replacementText;
-            entityReplacementBuf[entityEnd] = replacementText.toCharArray();
-            if(!allStringsInterned) {
-                entityNameHash[ entityEnd ] =
-                    fastHash(entityNameBuf[entityEnd], 0, 
entityNameBuf[entityEnd].length);
+            charRefOneCharBuf[0] = charRef;
+            if ( tokenize )
+            {
+                text = newString( charRefOneCharBuf, 0, 1 );
             }
-            ++entityEnd;
-            //TODO disallow < or & in entity replacement text (or ]]>???)
-            // TOOD keepEntityNormalizedForAttributeValue cached as well ...
+            return charRefOneCharBuf;
         }
     }
 }

Modified: 
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/ByLineSource.java
URL: 
http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/ByLineSource.java?rev=779903&r1=779902&r2=779903&view=diff
==============================================================================
--- 
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/ByLineSource.java
 (original)
+++ 
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/ByLineSource.java
 Fri May 29 09:33:31 2009
@@ -55,7 +55,7 @@
     /**
      * <p>ungetLine</p>
      *
-     * @throws java.lang.IllegalStateException if the ungetLine/unget is 
called more than
+     * This should throw a java.lang.IllegalStateException if called more than
      *                               one time without calling getNextLine()
      */
     void ungetLine();
@@ -65,7 +65,7 @@
      * <p>unget</p>
      *
      * @param s some text to push back to the parser
-     * @throws java.lang.IllegalStateException if the ungetLine/unget is 
called more than
+     * This should throw a java.lang.IllegalStateException if called more than
      *                               one time without calling getNextLine()
      */
     void unget( String s );

Modified: 
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/HtmlTools.java
URL: 
http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/HtmlTools.java?rev=779903&r1=779902&r2=779903&view=diff
==============================================================================
--- 
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/HtmlTools.java
 (original)
+++ 
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/HtmlTools.java
 Fri May 29 09:33:31 2009
@@ -392,7 +392,7 @@
      *
      * @param id The id to be encoded.
      * @return The trimmed and encoded id, or null if id is null.
-     * @see {...@link DoxiaUtils#encodeId(java.lang.String,boolean)}.
+     * @see DoxiaUtils#encodeId(java.lang.String,boolean)
      */
     public static String encodeId( String id )
     {
@@ -422,13 +422,17 @@
 // 
http://svn.apache.org/repos/asf/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Character.java
 //
 
+    private static final char LUNATE_SIGMA = 0x3FF;
+    private static final char NON_PRIVATE_USE_HIGH_SURROGATE = 0xD800;
+    private static final char LOW_SURROGATE = 0xDC00;
+
     private static int toCodePoint( char high, char low )
     {
         // See RFC 2781, Section 2.2
         // http://www.faqs.org/rfcs/rfc2781.html
-        int h = ( high & 0x3FF ) << 10;
-        int l = low & 0x3FF;
-        return ( h | l ) + 0x10000;
+        int h = ( high & LUNATE_SIGMA ) << 10;
+        int l = low & LUNATE_SIGMA;
+        return ( h | l ) + MIN_SUPPLEMENTARY_CODE_POINT;
     }
 
     private static final char MIN_HIGH_SURROGATE = '\uD800';
@@ -454,10 +458,11 @@
     }
 
     /**
-     * TODO add javadoc
+     * Converts the given code point to an equivalent character array.
      *
-     * @param codePoint
-     * @return
+     * @param codePoint the code point to convert.
+     * @return If codePoint is a supplementary code point, returns a character 
array of length 2,
+     * otherwise a character array of length 1 containing only the original 
int as a char.
      */
     public static char[] toChars( int codePoint )
     {
@@ -468,9 +473,9 @@
 
         if ( isSupplementaryCodePoint( codePoint ) )
         {
-            int cpPrime = codePoint - 0x10000;
-            int high = 0xD800 | ( ( cpPrime >> 10 ) & 0x3FF );
-            int low = 0xDC00 | ( cpPrime & 0x3FF );
+            int cpPrime = codePoint - MIN_SUPPLEMENTARY_CODE_POINT;
+            int high = NON_PRIVATE_USE_HIGH_SURROGATE | ( ( cpPrime >> 10 ) & 
LUNATE_SIGMA );
+            int low = LOW_SURROGATE | ( cpPrime & LUNATE_SIGMA );
             return new char[] { (char) high, (char) low };
         }
         return new char[] { (char) codePoint };

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?rev=779903&r1=779902&r2=779903&view=diff
==============================================================================
--- 
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
 Fri May 29 09:33:31 2009
@@ -132,29 +132,7 @@
         }
         else if ( parser.getName().equals( META.toString() ) )
         {
-            String name = parser.getAttributeValue( null, 
Attribute.NAME.toString() );
-            String content = parser.getAttributeValue( null, 
Attribute.CONTENT.toString() );
-
-            if ( "author".equals( name ) )
-            {
-                sink.author( null );
-
-                sink.text( content );
-
-                sink.author_();
-            }
-            else if ( "date".equals( name ) )
-            {
-                sink.date( null );
-
-                sink.text( content );
-
-                sink.date_();
-            }
-            else
-            {
-                sink.unknown( "meta", new Object[] {new Integer( 
TAG_TYPE_SIMPLE )}, attribs );
-            }
+            handleMetaStart( parser, sink, attribs );
         }
         else if ( parser.getName().equals( BODY.toString() ) )
         {
@@ -168,41 +146,11 @@
         }
         else if ( parser.getName().equals( SECTION_TAG.toString() ) )
         {
-            consecutiveSections( Sink.SECTION_LEVEL_1, sink );
-
-            Object id = attribs.getAttribute( Attribute.ID.toString() );
-            if ( id != null )
-            {
-                sink.anchor( id.toString() );
-                sink.anchor_();
-            }
-
-            sink.section( Sink.SECTION_LEVEL_1, attribs );
-
-            sink.sectionTitle( Sink.SECTION_LEVEL_1, attribs );
-
-            sink.text( HtmlTools.unescapeHTML( parser.getAttributeValue( null, 
Attribute.NAME.toString() ) ) );
-
-            sink.sectionTitle1_();
+            handleSectionStart( Sink.SECTION_LEVEL_1, sink, attribs, parser );
         }
         else if ( parser.getName().equals( SUBSECTION_TAG.toString() ) )
         {
-            consecutiveSections( Sink.SECTION_LEVEL_2, sink );
-
-            Object id = attribs.getAttribute( Attribute.ID.toString() );
-            if ( id != null )
-            {
-                sink.anchor( id.toString() );
-                sink.anchor_();
-            }
-
-            sink.section( Sink.SECTION_LEVEL_2, attribs );
-
-            sink.sectionTitle( Sink.SECTION_LEVEL_2, attribs );
-
-            sink.text( HtmlTools.unescapeHTML( parser.getAttributeValue( null, 
Attribute.NAME.toString() ) ) );
-
-            sink.sectionTitle2_();
+            handleSectionStart( Sink.SECTION_LEVEL_2, sink, attribs, parser );
         }
         else if ( parser.getName().equals( SOURCE_TAG.toString() ) )
         {
@@ -228,46 +176,11 @@
 
         else if ( parser.getName().equals( MACRO_TAG.toString() ) )
         {
-            if ( !isSecondParsing() )
-            {
-                macroName = parser.getAttributeValue( null, 
Attribute.NAME.toString() );
-
-                if ( macroParameters == null )
-                {
-                    macroParameters = new HashMap();
-                }
-
-                if ( StringUtils.isEmpty( macroName ) )
-                {
-                    throw new MacroExecutionException( "The '" + 
Attribute.NAME.toString() + "' attribute for the '"
-                        + MACRO_TAG.toString() + "' tag is required." );
-                }
-            }
+            handleMacroStart( parser );
         }
         else if ( parser.getName().equals( PARAM.toString() ) )
         {
-            if ( !isSecondParsing() )
-            {
-                if ( StringUtils.isNotEmpty( macroName ) )
-                {
-                    String paramName = parser.getAttributeValue( null, 
Attribute.NAME.toString() );
-                    String paramValue = parser.getAttributeValue( null, 
Attribute.VALUE.toString() );
-
-                    if ( StringUtils.isEmpty( paramName ) || 
StringUtils.isEmpty( paramValue ) )
-                    {
-                        throw new MacroExecutionException( "'" + 
Attribute.NAME.toString() + "' and '"
-                            + Attribute.VALUE.toString() + "' attributes for 
the '" + PARAM.toString()
-                            + "' tag are required inside the '" + 
MACRO_TAG.toString() + "' tag." );
-                    }
-
-                    macroParameters.put( paramName, paramValue );
-                }
-                else
-                {
-                    // param tag from non-macro object, see MSITE-288
-                    handleUnknown( parser, sink, TAG_TYPE_START );
-                }
-            }
+            handleParamStart( parser, sink );
         }
         else if ( !baseStartTag( parser, sink ) )
         {
@@ -332,40 +245,9 @@
         {
             //Do nothing, head is closed with BODY start.
         }
-
-        // 
----------------------------------------------------------------------
-        // Macro
-        // 
----------------------------------------------------------------------
-
         else if ( parser.getName().equals( MACRO_TAG.toString() ) )
         {
-            if ( !isSecondParsing() )
-            {
-                if ( StringUtils.isNotEmpty( macroName ) )
-                {
-                    // TODO handles specific macro attributes
-                    macroParameters.put( "sourceContent", sourceContent );
-
-                    XdocParser xdocParser = new XdocParser();
-                    xdocParser.setSecondParsing( true );
-                    macroParameters.put( "parser", xdocParser );
-
-                    MacroRequest request = new MacroRequest( macroParameters, 
getBasedir() );
-
-                    try
-                    {
-                        executeMacro( macroName, request, sink );
-                    }
-                    catch ( MacroNotFoundException me )
-                    {
-                        throw new MacroExecutionException( "Macro not found: " 
+ macroName, me );
-                    }
-                }
-            }
-
-            // Reinit macro
-            macroName = null;
-            macroParameters = null;
+            handleMacroEnd( sink );
         }
         else if ( parser.getName().equals( PARAM.toString() ) )
         {
@@ -432,6 +314,125 @@
         }
     }
 
+    private void handleMacroEnd( Sink sink )
+            throws MacroExecutionException
+    {
+        if ( !isSecondParsing() )
+        {
+            if ( StringUtils.isNotEmpty( macroName ) )
+            {
+                // TODO handles specific macro attributes
+                macroParameters.put( "sourceContent", sourceContent );
+                XdocParser xdocParser = new XdocParser();
+                xdocParser.setSecondParsing( true );
+                macroParameters.put( "parser", xdocParser );
+
+                MacroRequest request = new MacroRequest( macroParameters, 
getBasedir() );
+
+                try
+                {
+                    executeMacro( macroName, request, sink );
+                } catch ( MacroNotFoundException me )
+                {
+                    throw new MacroExecutionException( "Macro not found: " + 
macroName, me );
+                }
+            }
+        }
+
+        // Reinit macro
+        macroName = null;
+        macroParameters = null;
+    }
+
+    private void handleMacroStart( XmlPullParser parser )
+            throws MacroExecutionException
+    {
+        if ( !isSecondParsing() )
+        {
+            macroName = parser.getAttributeValue( null, 
Attribute.NAME.toString() );
+
+            if ( macroParameters == null )
+            {
+                macroParameters = new HashMap();
+            }
+
+            if ( StringUtils.isEmpty( macroName ) )
+            {
+                throw new MacroExecutionException( "The '" + 
Attribute.NAME.toString()
+                        + "' attribute for the '" + MACRO_TAG.toString() + "' 
tag is required." );
+            }
+        }
+    }
+
+    private void handleMetaStart( XmlPullParser parser, Sink sink, 
SinkEventAttributeSet attribs )
+    {
+        String name = parser.getAttributeValue( null, 
Attribute.NAME.toString() );
+        String content = parser.getAttributeValue( null, 
Attribute.CONTENT.toString() );
+
+        if ( "author".equals( name ) )
+        {
+            sink.author( null );
+            sink.text( content );
+            sink.author_();
+        }
+        else if ( "date".equals( name ) )
+        {
+            sink.date( null );
+            sink.text( content );
+            sink.date_();
+        }
+        else
+        {
+            sink.unknown( "meta", new Object[] {new Integer( TAG_TYPE_SIMPLE 
)}, attribs );
+        }
+    }
+
+    private void handleParamStart( XmlPullParser parser, Sink sink )
+            throws MacroExecutionException
+    {
+        if ( !isSecondParsing() )
+        {
+            if ( StringUtils.isNotEmpty( macroName ) )
+            {
+                String paramName = parser.getAttributeValue( null, 
Attribute.NAME.toString() );
+                String paramValue = parser.getAttributeValue( null,
+                        Attribute.VALUE.toString() );
+
+                if ( StringUtils.isEmpty( paramName ) || StringUtils.isEmpty( 
paramValue ) )
+                {
+                    throw new MacroExecutionException( "'" + 
Attribute.NAME.toString()
+                            + "' and '" + Attribute.VALUE.toString() + "' 
attributes for the '" + PARAM.toString()
+                            + "' tag are required inside the '" + 
MACRO_TAG.toString() + "' tag." );
+                }
+
+                macroParameters.put( paramName, paramValue );
+            }
+            else
+            {
+                // param tag from non-macro object, see MSITE-288
+                handleUnknown( parser, sink, TAG_TYPE_START );
+            }
+        }
+    }
+
+    private void handleSectionStart( int level, Sink sink, 
SinkEventAttributeSet attribs, XmlPullParser parser )
+    {
+        consecutiveSections( level, sink );
+
+        Object id = attribs.getAttribute( Attribute.ID.toString() );
+
+        if ( id != null )
+        {
+            sink.anchor( id.toString() );
+            sink.anchor_();
+        }
+
+        sink.section( level, attribs );
+        sink.sectionTitle( level, attribs );
+        sink.text( HtmlTools.unescapeHTML( parser.getAttributeValue( null, 
Attribute.NAME.toString() ) ) );
+        sink.sectionTitle_( level );
+    }
+
     /**
      * Open missing h4, h5, h6 sections.
      */


Reply via email to