maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vsive...@apache.org
Subject svn commit: r496552 - in /maven/doxia/trunk/doxia-core/src: main/java/org/apache/maven/doxia/index/ main/java/org/apache/maven/doxia/macro/toc/ main/java/org/apache/maven/doxia/module/apt/ main/java/org/apache/maven/doxia/module/xdoc/ main/java/org/apa...
Date Tue, 16 Jan 2007 00:43:07 GMT
Author: vsiveton
Date: Mon Jan 15 16:43:05 2007
New Revision: 496552

URL: http://svn.apache.org/viewvc?view=rev&rev=496552
Log:
DOXIA-40: Request for a TOC-like feature

o added a new TOC macro to handle that (i.e. in an apt file %{toc|section=2|fromDepth=2|toDepth=2}
)
o used some classes from doxia-book to do that
o updated doxia-book with new references from core
o modified the apt and xdoc parsers to add a second parsing way (maybe to be optimized)
o finally, added test cases

Added:
    maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/
    maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexEntry.java
      - copied, changed from r496219, maven/sandbox/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/context/IndexEntry.java
    maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexingSink.java
      - copied, changed from r496219, maven/sandbox/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexingSink.java
    maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/toc/
    maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/toc/TocMacro.java
  (with props)
    maven/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/index/
    maven/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/index/IndexEntryTest.java
      - copied, changed from r496219, maven/sandbox/doxia/doxia-book/src/test/java/org/apache/maven/doxia/book/context/IndexEntryTest.java
    maven/doxia/trunk/doxia-core/src/test/site/apt/toc.apt   (with props)
    maven/doxia/trunk/doxia-core/src/test/site/xdoc/toc.xml   (with props)
Modified:
    maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java
    maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java
    maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java
    maven/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/module/apt/AptParserTest.java
    maven/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java

Copied: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexEntry.java
(from r496219, maven/sandbox/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/context/IndexEntry.java)
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexEntry.java?view=diff&rev=496552&p1=maven/sandbox/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/context/IndexEntry.java&r1=496219&p2=maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexEntry.java&r2=496552
==============================================================================
--- maven/sandbox/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/context/IndexEntry.java
(original)
+++ maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexEntry.java
Mon Jan 15 16:43:05 2007
@@ -1,4 +1,23 @@
-package org.apache.maven.doxia.book.context;
+package org.apache.maven.doxia.index;
+
+/*
+ * 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.StringUtils;
 
@@ -193,7 +212,8 @@
 
         String indent = "";
 
-        for( int i = 0; i < depth; i++ ) {
+        for ( int i = 0; i < depth; i++ )
+        {
             indent += " ";
         }
 

Copied: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexingSink.java
(from r496219, maven/sandbox/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexingSink.java)
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexingSink.java?view=diff&rev=496552&p1=maven/sandbox/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexingSink.java&r1=496219&p2=maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexingSink.java&r2=496552
==============================================================================
--- maven/sandbox/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexingSink.java
(original)
+++ maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexingSink.java
Mon Jan 15 16:43:05 2007
@@ -1,35 +1,37 @@
-package org.apache.maven.doxia.book.services.indexer;
+package org.apache.maven.doxia.index;
 
 /*
- * Copyright 2006 The Apache Software Foundation.
+ * 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
  *
- * Licensed 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
  *
- *      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.
+ * 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.Stack;
 
-import org.apache.maven.doxia.book.context.IndexEntry;
 import org.apache.maven.doxia.module.HtmlTools;
 import org.apache.maven.doxia.sink.SinkAdapter;
 
 /**
- * A simk implementation for book index
+ * A sink implementation for index
  *
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
  * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
  * @version $Id$
  */
-public class BookIndexingSink
+public class IndexingSink
     extends SinkAdapter
 {
     private final static int TYPE_SECTION_1 = 1;
@@ -61,7 +63,7 @@
      *
      * @param sectionEntry
      */
-    public BookIndexingSink( IndexEntry sectionEntry )
+    public IndexingSink( IndexEntry sectionEntry )
     {
         stack.push( sectionEntry );
     }

Added: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/toc/TocMacro.java
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/toc/TocMacro.java?view=auto&rev=496552
==============================================================================
--- maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/toc/TocMacro.java
(added)
+++ maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/toc/TocMacro.java
Mon Jan 15 16:43:05 2007
@@ -0,0 +1,222 @@
+package org.apache.maven.doxia.macro.toc;
+
+/*
+ * 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.StringReader;
+import java.util.Iterator;
+
+import org.apache.maven.doxia.index.IndexEntry;
+import org.apache.maven.doxia.index.IndexingSink;
+import org.apache.maven.doxia.macro.AbstractMacro;
+import org.apache.maven.doxia.macro.MacroExecutionException;
+import org.apache.maven.doxia.macro.MacroRequest;
+import org.apache.maven.doxia.module.HtmlTools;
+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.StringUtils;
+
+/**
+ * Macro to display a <code>Table Of Content</code> in a given <code>Sink</code>.
The input for this macro are:
+ * <dl>
+ * <dt>section</dt>
+ * <dd>Display the specificated section number or all sections if 0 (in this case,
other paramaters are ignored).<br/>
+ * Positive int, not mandatory, 0 by default.</dd>
+ * <dt>fromDepth</dt>
+ * <dd>Display the depth starting for the given section number.<br/>
+ * Positive int, not mandatory, 0 by default.</dd>
+ * <dt>toDepth</dt>
+ * <dd>Display the depth ending for the given section number.<br/>
+ * Positive int, not mandatory, 5 by default.</dd>
+ * </dl>
+ * For instance, in an APT file, you could write:
+ * <dl>
+ * <dt>%{toc|section=2|fromDepth=2|toDepth=2}</dt>
+ * <dd>Display a TOC for the section number 2 in the document, from the subsection
depth 1 to the subsection depth 2</dd>
+ * <dt>%{toc}</dt>
+ * <dd>display a TOC with all section and subsections (similar to %{toc|section=0}
)</dd>
+ * </dl>
+ * Moreover, you need to write APT link for section to allow anchor, for instance:
+ * <pre>
+ * * {SubSection 1}
+ * </pre>
+ *
+ * Similary, in an XDOC file, you could write:
+ * <pre>
+ * &lt;macro name="toc" section="1" fromDepth="1" toDepth="2"/&gt;
+ * </pre>
+ *
+ * @plexus.component role="org.apache.maven.doxia.macro.Macro"
+ * role-hint="toc"
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class TocMacro
+    extends AbstractMacro
+{
+    private int section;
+
+    private int fromDepth;
+
+    private int toDepth;
+
+    /**
+     * @see org.apache.maven.doxia.macro.Macro#execute(org.apache.maven.doxia.sink.Sink,
org.apache.maven.doxia.macro.MacroRequest)
+     */
+    public void execute( Sink sink, MacroRequest request )
+        throws MacroExecutionException
+    {
+        String source = (String) request.getParameter( "sourceContent" );
+        Parser parser = (Parser) request.getParameter( "parser" );
+
+        section = getInt( request, "section", 0 );
+        if ( section != 0 )
+        {
+            fromDepth = getInt( request, "fromDepth", 0 );
+            toDepth = getInt( request, "toDepth", 5 );
+        }
+        else
+        {
+            fromDepth = 0;
+            toDepth = 5;
+        }
+        IndexEntry index = new IndexEntry( "index" );
+        IndexingSink tocSink = new IndexingSink( index );
+
+        try
+        {
+            parser.parse( new StringReader( source ), tocSink );
+
+            if ( index.getChildEntries().size() > 0 )
+            {
+                if ( ( fromDepth < section ) || ( section == 0 ) )
+                {
+                    sink.list();
+                }
+                int i = 1;
+                for ( Iterator it = index.getChildEntries().iterator(); it.hasNext(); )
+                {
+                    IndexEntry sectionIndex = (IndexEntry) it.next();
+                    if ( ( i == section ) || ( section == 0 ) )
+                    {
+                        writeSubSectionN( sink, sectionIndex, i );
+                    }
+                    i++;
+                }
+                if ( ( fromDepth < section ) || ( section == 0 ) )
+                {
+                    sink.list_();
+                }
+            }
+        }
+        catch ( ParseException e )
+        {
+            throw new MacroExecutionException( "ParseException: " + e.getMessage(), e );
+        }
+    }
+
+    /**
+     * @param sink
+     * @param sectionIndex
+     * @param n
+     */
+    private void writeSubSectionN( Sink sink, IndexEntry sectionIndex, int n )
+    {
+        if ( fromDepth < n )
+        {
+            sink.listItem();
+            sink.link( "#" + HtmlTools.encodeId( sectionIndex.getId() ) );
+            sink.text( sectionIndex.getTitle() );
+            sink.link_();
+        }
+
+        if ( toDepth >= n )
+        {
+            if ( sectionIndex.getChildEntries().size() > 0 )
+            {
+                if ( fromDepth < ( n + 1 ) )
+                {
+                    sink.list();
+                }
+                for ( Iterator it = sectionIndex.getChildEntries().iterator(); it.hasNext();
)
+                {
+                    IndexEntry subsectionIndex = (IndexEntry) it.next();
+                    if ( n == 5 )
+                    {
+                        sink.listItem();
+                        sink.link( "#" + HtmlTools.encodeId( subsectionIndex.getId() ) );
+                        sink.text( subsectionIndex.getTitle() );
+                        sink.link_();
+                        sink.listItem_();
+                    }
+                    else
+                    {
+                        writeSubSectionN( sink, subsectionIndex, n + 1 );
+                    }
+                }
+                if ( fromDepth < ( n + 1 ) )
+                {
+                    sink.list_();
+                }
+            }
+        }
+
+        if ( fromDepth < n )
+        {
+            sink.listItem_();
+        }
+    }
+
+    /**
+     * @param request
+     * @param parameter
+     * @param defaultValue
+     * @return the int value of an parameter in the request.
+     * @throws MacroExecutionException
+     */
+    private static int getInt( MacroRequest request, String parameter, int defaultValue )
+        throws MacroExecutionException
+    {
+        String value = (String) request.getParameter( parameter );
+
+        if ( StringUtils.isEmpty( value ) )
+        {
+            return defaultValue;
+        }
+
+        int i;
+        try
+        {
+            i = Integer.parseInt( value );
+        }
+        catch ( NumberFormatException e )
+        {
+            return defaultValue;
+        }
+
+        if ( i < 0 )
+        {
+            throw new MacroExecutionException( "The " + parameter + "=" + i + " should be
positive." );
+        }
+
+        return i;
+    }
+}

Propchange: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/toc/TocMacro.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/toc/TocMacro.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java?view=diff&rev=496552&r1=496551&r2=496552
==============================================================================
--- maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java
(original)
+++ maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java
Mon Jan 15 16:43:05 2007
@@ -22,9 +22,13 @@
 import org.apache.maven.doxia.parser.AbstractParser;
 import org.apache.maven.doxia.sink.Sink;
 import org.apache.maven.doxia.sink.SinkAdapter;
+import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
 
+import java.io.IOException;
 import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.StringTokenizer;
@@ -85,6 +89,8 @@
 
     // -----------------------------------------------------------------------
 
+    private String sourceContent;
+
     private AptSource source;
 
     private Sink sink;
@@ -104,7 +110,18 @@
     {
         try
         {
-            this.source = new AptReaderSource( source );
+            try
+            {
+                StringWriter contentWriter = new StringWriter();
+                IOUtil.copy( source, contentWriter );
+                sourceContent = contentWriter.toString();
+            }
+            catch ( IOException e )
+            {
+                throw new AptParseException( "IOException: " + e.getMessage(), e );
+            }
+
+            this.source = new AptReaderSource( new StringReader( sourceContent ) );
 
             this.sink = sink;
 
@@ -2122,6 +2139,11 @@
         public void traverse()
             throws AptParseException
         {
+            if ( secondParsing )
+            {
+                return;
+            }
+
             String s = text;
 
             s = s.substring( 2, s.length() - 1 );
@@ -2139,8 +2161,13 @@
                 parameters.put( param[0], param[1] );
             }
 
-            MacroRequest request = new MacroRequest( parameters, getBasedir() );
+            parameters.put( "sourceContent", sourceContent );
+
+            AptParser aptParser = new AptParser();
+            aptParser.setSecondParsing( true );
+            parameters.put( "parser", aptParser );
 
+            MacroRequest request = new MacroRequest( parameters, getBasedir() );
             try
             {
                 AptParser.this.executeMacro( macroId, request, sink );

Modified: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java?view=diff&rev=496552&r1=496551&r2=496552
==============================================================================
--- maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java
(original)
+++ maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java
Mon Jan 15 16:43:05 2007
@@ -16,17 +16,20 @@
  * limitations under the License.
  */
 
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.maven.doxia.macro.MacroRequest;
 import org.apache.maven.doxia.parser.AbstractParser;
 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.xml.pull.MXParser;
 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
 
-import java.io.Reader;
-import java.util.HashMap;
-import java.util.Map;
-
 /**
  * Parse an xdoc model and emit events into the specified doxia
  * Sink.
@@ -39,14 +42,20 @@
 public class XdocParser
     extends AbstractParser
 {
+    private String sourceContent;
+
     public void parse( Reader reader, Sink sink )
         throws ParseException
     {
         try
         {
+            StringWriter contentWriter = new StringWriter();
+            IOUtil.copy( reader, contentWriter );
+            sourceContent = contentWriter.toString();
+
             XmlPullParser parser = new MXParser();
 
-            parser.setInput( reader );
+            parser.setInput( new StringReader( sourceContent ) );
 
             parseXdoc( parser, sink );
         }
@@ -161,20 +170,29 @@
                 }
                 else if ( parser.getName().equals( "macro" ) )
                 {
-                    String macroName = parser.getAttributeValue( null, "name" );
+                    if ( !secondParsing )
+                    {
+                        String macroName = parser.getAttributeValue( null, "name" );
 
-                    int count = parser.getAttributeCount();
+                        int count = parser.getAttributeCount();
 
-                    Map parameters = new HashMap();
+                        Map parameters = new HashMap();
 
-                    for ( int i = 1; i < count; i++ )
-                    {
-                        parameters.put( parser.getAttributeName( i ), parser.getAttributeValue(
i ) );
-                    }
+                        for ( int i = 1; i < count; i++ )
+                        {
+                            parameters.put( parser.getAttributeName( i ), parser.getAttributeValue(
i ) );
+                        }
+
+                        parameters.put( "sourceContent", sourceContent );
 
-                    MacroRequest request = new MacroRequest( parameters, getBasedir() );
+                        XdocParser xdocParser = new XdocParser();
+                        xdocParser.setSecondParsing( true );
+                        parameters.put( "parser", xdocParser );
 
-                    executeMacro( macroName, request, sink );
+                        MacroRequest request = new MacroRequest( parameters, getBasedir()
);
+
+                        executeMacro( macroName, request, sink );
+                    }
                 }
 
                 // ----------------------------------------------------------------------

Modified: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java?view=diff&rev=496552&r1=496551&r2=496552
==============================================================================
--- maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java
(original)
+++ maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java
Mon Jan 15 16:43:05 2007
@@ -16,15 +16,14 @@
  * limitations under the License.
  */
 
+import java.io.File;
+
 import org.apache.maven.doxia.macro.Macro;
 import org.apache.maven.doxia.macro.MacroExecutionException;
 import org.apache.maven.doxia.macro.MacroRequest;
 import org.apache.maven.doxia.macro.manager.MacroManager;
 import org.apache.maven.doxia.macro.manager.MacroNotFoundException;
 import org.apache.maven.doxia.sink.Sink;
-import org.codehaus.plexus.util.StringUtils;
-
-import java.io.File;
 
 /**
  * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@@ -34,6 +33,8 @@
 public abstract class AbstractParser
     implements Parser
 {
+    protected boolean secondParsing = false;
+
     /**
      * @plexus.requirement
      */
@@ -61,5 +62,15 @@
         }
 
         return new File( new File( "" ).getAbsolutePath() );
+    }
+
+    /**
+     * Set <code>secondParsing</code> to true, if we need a second parsing
+     *
+     * @param secondParsing
+     */
+    public void setSecondParsing( boolean secondParsing )
+    {
+        this.secondParsing = secondParsing;
     }
 }

Copied: maven/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/index/IndexEntryTest.java
(from r496219, maven/sandbox/doxia/doxia-book/src/test/java/org/apache/maven/doxia/book/context/IndexEntryTest.java)
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/index/IndexEntryTest.java?view=diff&rev=496552&p1=maven/sandbox/doxia/doxia-book/src/test/java/org/apache/maven/doxia/book/context/IndexEntryTest.java&r1=496219&p2=maven/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/index/IndexEntryTest.java&r2=496552
==============================================================================
--- maven/sandbox/doxia/doxia-book/src/test/java/org/apache/maven/doxia/book/context/IndexEntryTest.java
(original)
+++ maven/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/index/IndexEntryTest.java
Mon Jan 15 16:43:05 2007
@@ -1,4 +1,23 @@
-package org.apache.maven.doxia.book.context;
+package org.apache.maven.doxia.index;
+
+/*
+ * 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 junit.framework.TestCase;
 

Modified: maven/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/module/apt/AptParserTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/module/apt/AptParserTest.java?view=diff&rev=496552&r1=496551&r2=496552
==============================================================================
--- maven/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/module/apt/AptParserTest.java
(original)
+++ maven/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/module/apt/AptParserTest.java
Mon Jan 15 16:43:05 2007
@@ -116,4 +116,32 @@
             reader.close();
         }
     }
+
+    /**
+     * @throws Exception
+     */
+    public void testTocMacro()
+        throws Exception
+    {
+        StringWriter output = null;
+        Reader reader = null;
+
+        try
+        {
+            output = new StringWriter();
+            reader = new FileReader( getTestFile( getBasedir(), "src/test/site/apt/toc.apt"
) );
+
+            Sink sink = new AptSink( output );
+            getParser().parse( reader, sink );
+
+            // No section, only subsection 1 and 2
+            assertTrue( output.toString().indexOf( "* {{{#subsection_1}SubSection 1}}" )
!= -1 );
+            assertTrue( output.toString().indexOf( "* {{{#subsection_1211}SubSection 1211}}"
) == -1 );
+        }
+        finally
+        {
+            output.close();
+            reader.close();
+        }
+    }
 }

Modified: maven/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java?view=diff&rev=496552&r1=496551&r2=496552
==============================================================================
--- maven/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java
(original)
+++ maven/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java
Mon Jan 15 16:43:05 2007
@@ -89,4 +89,32 @@
             reader.close();
         }
     }
+
+    /**
+     * @throws Exception
+     */
+    public void testTocMacro()
+        throws Exception
+    {
+        StringWriter output = null;
+        Reader reader = null;
+
+        try
+        {
+            output = new StringWriter();
+            reader = new FileReader( getTestFile( getBasedir(), "src/test/site/xdoc/toc.xml"
) );
+
+            Sink sink = new XdocSink( output );
+            getParser().parse( reader, sink );
+
+            // No section, only subsection 1 and 2
+            assertTrue( output.toString().indexOf( "<li><a href=\"#section_11\">Section
11</a></li>" ) != -1 );
+            assertTrue( output.toString().indexOf( "<li><a href=\"#section_1211\">Section
1211</a></li>" ) == -1 );
+        }
+        finally
+        {
+            output.close();
+            reader.close();
+        }
+    }
 }

Added: maven/doxia/trunk/doxia-core/src/test/site/apt/toc.apt
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-core/src/test/site/apt/toc.apt?view=auto&rev=496552
==============================================================================
--- maven/doxia/trunk/doxia-core/src/test/site/apt/toc.apt (added)
+++ maven/doxia/trunk/doxia-core/src/test/site/apt/toc.apt Mon Jan 15 16:43:05 2007
@@ -0,0 +1,55 @@
+ ----
+ Test DOXIA-40
+ -----
+ Vincent Siveton
+ -----
+ January 2007
+ -----
+
+Test DOXIA-40
+
+Section 1
+
+%{toc|section=2|fromDepth=2|toDepth=4}
+
+* {SubSection 1}
+
+ SubSection 1
+
+** {SubSection 11}
+
+ SubSection 11
+
+** {SubSection 12}
+
+ SubSection 12
+
+*** {SubSection 121}
+
+ SubSection 121
+
+**** {SubSection 1211}
+
+ SubSection 1211
+
+*** {SubSection 122}
+
+ SubSection 122
+
+* {SubSection 2}
+
+ SubSection 2
+
+* {SubSection 3}
+
+ SubSection 3
+
+* {SubSection 4}
+
+ SubSection 4
+
+Section 2
+
+* {SubSection 1}
+
+ SubSection 1
\ No newline at end of file

Propchange: maven/doxia/trunk/doxia-core/src/test/site/apt/toc.apt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/doxia/trunk/doxia-core/src/test/site/apt/toc.apt
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/doxia/trunk/doxia-core/src/test/site/xdoc/toc.xml
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-core/src/test/site/xdoc/toc.xml?view=auto&rev=496552
==============================================================================
--- maven/doxia/trunk/doxia-core/src/test/site/xdoc/toc.xml (added)
+++ maven/doxia/trunk/doxia-core/src/test/site/xdoc/toc.xml Mon Jan 15 16:43:05 2007
@@ -0,0 +1,45 @@
+<?xml version="1.0"?>
+<document>
+  <properties>
+    <title>Test DOXIA-40</title>
+    <author email="vsiveton@apache.org">Vincent Siveton</author>
+  </properties>
+  <body>
+      <p>
+        Test DOXIA-40
+      </p>
+      <section name="Section 1">
+        <p>
+          Section 1
+        </p>
+        <p>
+          <macro name="toc" section="1" fromDepth="1" toDepth="2"/>
+        </p>
+        <subsection name="Section 11">
+          <p>
+            Section 11
+          </p>
+        </subsection>
+        <subsection name="Section 12">
+          <p>
+            Section 12
+          </p>
+          <subsection name="Section 121">
+            <p>
+              Section 121
+            </p>
+            <subsection name="Section 1211">
+              <p>
+                Section 1211
+              </p>
+            </subsection>
+          </subsection>
+        </subsection>
+        <subsection name="Section 13">
+          <p>
+            Section 13
+          </p>
+        </subsection>
+      </section>
+  </body>
+</document>

Propchange: maven/doxia/trunk/doxia-core/src/test/site/xdoc/toc.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/doxia/trunk/doxia-core/src/test/site/xdoc/toc.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message