You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by vm...@apache.org on 2008/01/18 18:21:48 UTC

svn commit: r613206 - in /maven/sandbox/trunk/doxia/doxia-module-xwiki/src: main/java/org/apache/maven/doxia/module/xwiki/ main/java/org/apache/maven/doxia/module/xwiki/blocks/ main/java/org/apache/maven/doxia/module/xwiki/parser/ test/java/org/apache/...

Author: vmassol
Date: Fri Jan 18 09:21:42 2008
New Revision: 613206

URL: http://svn.apache.org/viewvc?rev=613206&view=rev
Log:
DOXIA-200: Add a Parser for XWiki

* Added Blocks which can serve as the basis for http://jira.codehaus.org/browse/DOXIA-202
* Fixed macro parsing use cases + tests
* Some refactorings
* Started rewriting the XWiki Parser Test (using blocks for assertions instead of sink output)

Added:
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/AbstractFatherBlock.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/Block.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/BoldBlock.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/FigureBlock.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/ItalicBlock.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/LinebreakBlock.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/LinkBlock.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/MacroBlock.java
      - copied, changed from r613132, maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/MacroBlock.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/ParagraphBlock.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/SectionBlock.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/TextBlock.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/AbstractBlockParser.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/BlockParser.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/MacroParser2.java
Modified:
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/XWikiParser.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/ChildBlocksBuilder.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/FigureBlockParser.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/MacroParser.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/ParagraphBlockParser.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/SectionBlockParser.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/test/java/org/apache/maven/doxia/module/xwiki/XWikiParserTest.java
    maven/sandbox/trunk/doxia/doxia-module-xwiki/src/test/java/org/apache/maven/doxia/module/xwiki/parser/MacroParserTest.java

Modified: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/XWikiParser.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/XWikiParser.java?rev=613206&r1=613205&r2=613206&view=diff
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/XWikiParser.java (original)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/XWikiParser.java Fri Jan 18 09:21:42 2008
@@ -20,7 +20,7 @@
  */
 
 import org.apache.maven.doxia.module.confluence.parser.Block;
-import org.apache.maven.doxia.module.confluence.parser.BlockParser;
+import org.apache.maven.doxia.module.xwiki.parser.BlockParser;
 import org.apache.maven.doxia.module.xwiki.parser.FigureBlockParser;
 import org.apache.maven.doxia.module.xwiki.parser.ParagraphBlockParser;
 import org.apache.maven.doxia.module.xwiki.parser.SectionBlockParser;
@@ -52,6 +52,8 @@
     {
         BlockParser headingParser = new SectionBlockParser();
         BlockParser figureParser = new FigureBlockParser();
+        figureParser.setCompatibilityMode( true );
+
 //        BlockParser verbatimParser = new VerbatimBlockParser();
 //        BlockParser definitionParser = new DefinitionListBlockParser();
 //        BlockParser horizontalRuleParser = new HorizontalRuleBlockParser();
@@ -60,12 +62,19 @@
 
         BlockParser[] subparsers = new BlockParser[]{headingParser, figureParser/*, listParser, tableParser*/};
         BlockParser paragraphParser = new ParagraphBlockParser( subparsers );
+        paragraphParser.setCompatibilityMode( true );
 
         parsers = new BlockParser[]{headingParser, figureParser/*, verbatimParser, definitionParser, horizontalRuleParser,
                 listParser, tableParser*/, paragraphParser};
     }
 
-    public List parse( ByLineSource source )
+    public List parse( Reader reader )
+        throws ParseException
+    {
+        return parse( new ByLineReaderSource( reader ) );
+    }
+
+    private List parse( ByLineSource source )
         throws ParseException
     {
         List blocks = new ArrayList();

Added: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/AbstractFatherBlock.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/AbstractFatherBlock.java?rev=613206&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/AbstractFatherBlock.java (added)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/AbstractFatherBlock.java Fri Jan 18 09:21:42 2008
@@ -0,0 +1,64 @@
+package org.apache.maven.doxia.module.xwiki.blocks;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.sink.Sink;
+
+import java.util.Iterator;
+import java.util.List;
+
+public abstract class AbstractFatherBlock
+    implements Block
+{
+    private List blocks;
+
+    public abstract void before( Sink sink );
+
+    public abstract void after( Sink sink );
+
+    public AbstractFatherBlock( List childBlocks )
+    {
+        if ( childBlocks == null )
+        {
+            throw new IllegalArgumentException( "argument can't be null" );
+        }
+
+        this.blocks = childBlocks;
+    }
+
+    public void traverse( Sink sink )
+    {
+        before( sink );
+
+        for ( Iterator i = blocks.iterator(); i.hasNext(); )
+        {
+            Block block = (Block) i.next();
+
+            block.traverse( sink );
+        }
+
+        after( sink );
+    }
+
+    public List getBlocks()
+    {
+        return blocks;
+    }
+}

Added: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/Block.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/Block.java?rev=613206&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/Block.java (added)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/Block.java Fri Jan 18 09:21:42 2008
@@ -0,0 +1,27 @@
+package org.apache.maven.doxia.module.xwiki.blocks;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.sink.Sink;
+
+public interface Block
+{
+    void traverse( Sink sink );
+}

Added: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/BoldBlock.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/BoldBlock.java?rev=613206&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/BoldBlock.java (added)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/BoldBlock.java Fri Jan 18 09:21:42 2008
@@ -0,0 +1,43 @@
+package org.apache.maven.doxia.module.xwiki.blocks;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.sink.Sink;
+
+import java.util.List;
+
+public class BoldBlock
+    extends AbstractFatherBlock
+{
+    public BoldBlock( List childBlocks )
+    {
+        super( childBlocks );
+    }
+
+    public void before( Sink sink )
+    {
+        sink.bold();
+    }
+
+    public void after( Sink sink )
+    {
+        sink.bold_();
+    }
+}

Added: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/FigureBlock.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/FigureBlock.java?rev=613206&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/FigureBlock.java (added)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/FigureBlock.java Fri Jan 18 09:21:42 2008
@@ -0,0 +1,48 @@
+package org.apache.maven.doxia.module.xwiki.blocks;
+
+import org.apache.maven.doxia.sink.Sink;
+
+public class FigureBlock
+    implements Block
+{
+    private String location;
+
+    private String caption;
+
+    public FigureBlock( String location )
+    {
+        this.location = location;
+    }
+
+    public FigureBlock( String location, String caption )
+    {
+        this.location = location;
+        this.caption = caption;
+    }
+
+    public void traverse( Sink sink )
+    {
+        sink.figure();
+        sink.figureGraphics( getLocation() );
+
+        if ( caption != null && caption.length() > 0 )
+        {
+            sink.figureCaption();
+            new TextBlock( caption ).traverse( sink );
+            sink.figureCaption_();
+        }
+
+        sink.figure_();
+    }
+
+    public String getLocation()
+    {
+        return this.location;
+    }
+
+    public String getCaption()
+    {
+        return this.caption;
+    }
+
+}

Added: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/ItalicBlock.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/ItalicBlock.java?rev=613206&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/ItalicBlock.java (added)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/ItalicBlock.java Fri Jan 18 09:21:42 2008
@@ -0,0 +1,43 @@
+package org.apache.maven.doxia.module.xwiki.blocks;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.sink.Sink;
+
+import java.util.List;
+
+public class ItalicBlock
+    extends AbstractFatherBlock
+{
+    public ItalicBlock( List childBlocks )
+    {
+        super( childBlocks );
+    }
+
+    public void before( Sink sink )
+    {
+        sink.italic();
+    }
+
+    public void after( Sink sink )
+    {
+        sink.italic_();
+    }
+}

Added: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/LinebreakBlock.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/LinebreakBlock.java?rev=613206&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/LinebreakBlock.java (added)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/LinebreakBlock.java Fri Jan 18 09:21:42 2008
@@ -0,0 +1,35 @@
+package org.apache.maven.doxia.module.xwiki.blocks;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.sink.Sink;
+
+/**
+ * @author Dave Syer
+ * @since 1.0
+ */
+public class LinebreakBlock
+    implements Block
+{
+    public void traverse( Sink sink )
+    {
+        sink.lineBreak();
+    }
+}

Added: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/LinkBlock.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/LinkBlock.java?rev=613206&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/LinkBlock.java (added)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/LinkBlock.java Fri Jan 18 09:21:42 2008
@@ -0,0 +1,50 @@
+package org.apache.maven.doxia.module.xwiki.blocks;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.sink.Sink;
+
+public class LinkBlock
+    implements Block
+{
+    private String reference;
+
+    private String text;
+
+    public LinkBlock( String reference, String text )
+        throws IllegalArgumentException
+    {
+        if ( reference == null || text == null )
+        {
+            throw new IllegalArgumentException( "arguments can't be null" );
+        }
+        this.reference = reference;
+        this.text = text;
+    }
+
+    public void traverse( Sink sink )
+    {
+        sink.link( reference );
+
+        sink.text( text );
+
+        sink.link_();
+    }
+}

Copied: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/MacroBlock.java (from r613132, maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/MacroBlock.java)
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/MacroBlock.java?p2=maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/MacroBlock.java&p1=maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/MacroBlock.java&r1=613132&r2=613206&rev=613206&view=diff
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/MacroBlock.java (original)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/MacroBlock.java Fri Jan 18 09:21:42 2008
@@ -1,14 +1,14 @@
-package org.apache.maven.doxia.module.xwiki.parser;
+package org.apache.maven.doxia.module.xwiki.blocks;
 
-import org.apache.maven.doxia.module.confluence.parser.AbstractFatherBlock;
+import org.apache.maven.doxia.module.confluence.parser.Block;
+import org.apache.maven.doxia.module.confluence.parser.FigureBlock;
 import org.apache.maven.doxia.sink.Sink;
 
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 public class MacroBlock
-    extends AbstractFatherBlock
+    implements Block
 {
     private String name;
 
@@ -16,23 +16,24 @@
 
     private String content;
 
-    public MacroBlock( String name, Map parameters, String content, List childBlocks )
+    public MacroBlock( String name, Map parameters, String content )
     {
-        super( childBlocks );
         this.name = name;
         this.parameters = parameters;
         this.content = content;
     }
 
-    public void before( Sink sink )
+    public void traverse( Sink sink )
     {
-        // TODO: Make sure to generate existing events for some macros like for example for the image macro we should
-        // send the same events as the one sent by the FigureBlock block.
-    }
-
-    public void after( Sink sink )
-    {
-
+        if ( name.equalsIgnoreCase( "image" ) )
+        {
+            FigureBlock block = new FigureBlock( (String) parameters.get( "default" ), (String) null );
+            block.traverse( sink );
+        }
+        else
+        {
+            // TODO
+        }
     }
 
     public String getName()

Added: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/ParagraphBlock.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/ParagraphBlock.java?rev=613206&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/ParagraphBlock.java (added)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/ParagraphBlock.java Fri Jan 18 09:21:42 2008
@@ -0,0 +1,48 @@
+package org.apache.maven.doxia.module.xwiki.blocks;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.sink.Sink;
+
+import java.util.List;
+
+/**
+ * @author Juan F. Codagnone
+ * @since Nov 1, 2005
+ */
+public class ParagraphBlock
+    extends AbstractFatherBlock
+{
+    public ParagraphBlock( List blocks )
+        throws IllegalArgumentException
+    {
+        super( blocks );
+    }
+
+    public void before( Sink sink )
+    {
+        sink.paragraph();
+    }
+
+    public void after( Sink sink )
+    {
+        sink.paragraph_();
+    }
+}

Added: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/SectionBlock.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/SectionBlock.java?rev=613206&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/SectionBlock.java (added)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/SectionBlock.java Fri Jan 18 09:21:42 2008
@@ -0,0 +1,98 @@
+package org.apache.maven.doxia.module.xwiki.blocks;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.sink.Sink;
+
+/**
+ * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
+ * @version $Id: SectionBlock.java 568157 2007-08-21 15:06:04Z ltheussl $
+ */
+public class SectionBlock
+    implements Block
+{
+    private String title;
+
+    private int level;
+
+    public SectionBlock( String title, int level )
+    {
+        this.title = title;
+        this.level = level;
+    }
+
+    public void traverse( Sink sink )
+    {
+        if ( level == Sink.SECTION_LEVEL_1 )
+        {
+            sink.section1();
+            sink.sectionTitle1();
+        }
+        else if ( level == Sink.SECTION_LEVEL_2 )
+        {
+            sink.section2();
+            sink.sectionTitle2();
+        }
+        else if ( level == Sink.SECTION_LEVEL_3 )
+        {
+            sink.section3();
+            sink.sectionTitle3();
+        }
+        else if ( level == Sink.SECTION_LEVEL_4 )
+        {
+            sink.section4();
+            sink.sectionTitle4();
+        }
+        else if ( level == Sink.SECTION_LEVEL_5 )
+        {
+            sink.section5();
+            sink.sectionTitle5();
+        }
+
+        sink.text( title );
+
+        if ( level == Sink.SECTION_LEVEL_1 )
+        {
+            sink.sectionTitle1_();
+            sink.section1_();
+        }
+        else if ( level == Sink.SECTION_LEVEL_2 )
+        {
+            sink.sectionTitle2_();
+            sink.section2_();
+        }
+        else if ( level == Sink.SECTION_LEVEL_3 )
+        {
+            sink.sectionTitle3_();
+            sink.section3_();
+
+        }
+        else if ( level == Sink.SECTION_LEVEL_4 )
+        {
+            sink.sectionTitle4_();
+            sink.section4_();
+        }
+        else if ( level == Sink.SECTION_LEVEL_5 )
+        {
+            sink.sectionTitle5_();
+            sink.section5_();
+        }
+    }
+}

Added: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/TextBlock.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/TextBlock.java?rev=613206&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/TextBlock.java (added)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/blocks/TextBlock.java Fri Jan 18 09:21:42 2008
@@ -0,0 +1,43 @@
+package org.apache.maven.doxia.module.xwiki.blocks;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.sink.Sink;
+
+public class TextBlock
+    implements Block
+{
+    private String text;
+
+    public TextBlock( String text )
+    {
+        this.text = text;
+    }
+
+    public void traverse( Sink sink )
+    {
+        sink.text( text );
+    }
+
+    public String getText()
+    {
+        return this.text;
+    }
+}

Added: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/AbstractBlockParser.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/AbstractBlockParser.java?rev=613206&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/AbstractBlockParser.java (added)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/AbstractBlockParser.java Fri Jan 18 09:21:42 2008
@@ -0,0 +1,17 @@
+package org.apache.maven.doxia.module.xwiki.parser;
+
+public abstract class AbstractBlockParser
+    implements BlockParser
+{
+    private boolean isInCompatibilityMode;
+
+    public void setCompatibilityMode( boolean isInCompatibilityMode )
+    {
+        this.isInCompatibilityMode = isInCompatibilityMode;
+    }
+
+    public boolean isInCompatibilityMode()
+    {
+        return this.isInCompatibilityMode;
+    }
+}

Added: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/BlockParser.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/BlockParser.java?rev=613206&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/BlockParser.java (added)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/BlockParser.java Fri Jan 18 09:21:42 2008
@@ -0,0 +1,36 @@
+package org.apache.maven.doxia.module.xwiki.parser;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.module.xwiki.blocks.Block;
+import org.apache.maven.doxia.parser.ParseException;
+import org.apache.maven.doxia.util.ByLineSource;
+
+public interface BlockParser
+{
+    boolean accept( String line, ByLineSource source );
+
+    Block visit( String line, ByLineSource source )
+        throws ParseException;
+
+    void setCompatibilityMode( boolean isInCompatibilityMode );
+
+    boolean isInCompatibilityMode();
+}

Modified: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/ChildBlocksBuilder.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/ChildBlocksBuilder.java?rev=613206&r1=613205&r2=613206&view=diff
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/ChildBlocksBuilder.java (original)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/ChildBlocksBuilder.java Fri Jan 18 09:21:42 2008
@@ -19,12 +19,12 @@
  * under the License.
  */
 
-import org.apache.maven.doxia.module.confluence.parser.Block;
-import org.apache.maven.doxia.module.confluence.parser.BoldBlock;
-import org.apache.maven.doxia.module.confluence.parser.ItalicBlock;
-import org.apache.maven.doxia.module.confluence.parser.LinebreakBlock;
-import org.apache.maven.doxia.module.confluence.parser.LinkBlock;
-import org.apache.maven.doxia.module.confluence.parser.TextBlock;
+import org.apache.maven.doxia.module.xwiki.blocks.Block;
+import org.apache.maven.doxia.module.xwiki.blocks.BoldBlock;
+import org.apache.maven.doxia.module.xwiki.blocks.ItalicBlock;
+import org.apache.maven.doxia.module.xwiki.blocks.LinebreakBlock;
+import org.apache.maven.doxia.module.xwiki.blocks.LinkBlock;
+import org.apache.maven.doxia.module.xwiki.blocks.TextBlock;
 import org.apache.maven.doxia.parser.ParseException;
 import org.codehaus.plexus.util.StringUtils;
 
@@ -61,6 +61,11 @@
         this.input = input;
     }
 
+    public void setCompatibilityMode( boolean isInCompatibilityMode )
+    {
+        macroParser.setCompatibilityMode( isInCompatibilityMode );
+    }
+
     /**
      * Utility method to convert marked up content into blocks for rendering.
      *
@@ -147,7 +152,9 @@
                     break;
                 case '{':
                     text = addTextBlockIfNecessary( blocks, specialBlocks, text );
-                    i = macroParser.parse( input, i + 1, blocks ) - 2;
+                    MacroParser.MacroParserResult result = macroParser.parse( input, i + 1 );
+                    i = result.position - 1;
+                    blocks.add( result.block );
                     break;
                 case '\\':
 

Modified: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/FigureBlockParser.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/FigureBlockParser.java?rev=613206&r1=613205&r2=613206&view=diff
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/FigureBlockParser.java (original)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/FigureBlockParser.java Fri Jan 18 09:21:42 2008
@@ -19,9 +19,8 @@
  * under the License.
  */
 
-import org.apache.maven.doxia.module.confluence.parser.Block;
-import org.apache.maven.doxia.module.confluence.parser.BlockParser;
-import org.apache.maven.doxia.module.confluence.parser.FigureBlock;
+import org.apache.maven.doxia.module.xwiki.blocks.Block;
+import org.apache.maven.doxia.module.xwiki.blocks.FigureBlock;
 import org.apache.maven.doxia.parser.ParseException;
 import org.apache.maven.doxia.util.ByLineSource;
 
@@ -31,9 +30,11 @@
  * {@link org.apache.maven.doxia.module.xwiki.parser.MacroParser} when they're inside a paragraph.
  */
 public class FigureBlockParser
-    implements BlockParser
+    extends AbstractBlockParser
 {
-    static String LS = System.getProperty( "line.separator" );
+    private static String LS = System.getProperty( "line.separator" );
+
+    private MacroParser macroParser = new MacroParser();
 
     public boolean accept( String line, ByLineSource source )
     {
@@ -43,8 +44,22 @@
     public Block visit( String line, ByLineSource source )
         throws ParseException
     {
-        int pos = line.indexOf( "{image:" );
-        int pos2 = line.indexOf( "}", pos + 7 );
-        return new FigureBlock( line.substring( pos + 7, pos2 ) );
+        macroParser.setCompatibilityMode( isInCompatibilityMode() );
+        MacroParser.MacroParserResult result = macroParser.parse( line, 1 );
+
+        String caption = (String) result.block.getParameters().get( "alt" );
+        String location = (String) result.block.getParameters().get( "default" );
+
+        if ( location == null )
+        {
+            location = (String) result.block.getParameters().get( "file" );
+        }
+
+        if ( caption == null )
+        {
+            return new FigureBlock( location );
+        }
+
+        return new FigureBlock( location, caption );
     }
 }

Modified: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/MacroParser.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/MacroParser.java?rev=613206&r1=613205&r2=613206&view=diff
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/MacroParser.java (original)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/MacroParser.java Fri Jan 18 09:21:42 2008
@@ -1,5 +1,6 @@
 package org.apache.maven.doxia.module.xwiki.parser;
 
+import org.apache.maven.doxia.module.xwiki.blocks.MacroBlock;
 import org.apache.maven.doxia.parser.ParseException;
 
 import java.util.ArrayList;
@@ -44,6 +45,13 @@
 
     private List multilineMacros;
 
+    public class MacroParserResult
+    {
+        public int position;
+
+        public MacroBlock block;
+    }
+
     public MacroParser()
     {
         this.multilineMacros = new ArrayList();
@@ -57,9 +65,10 @@
         this.isInCompatibilityMode = isInCompatibilityMode;
     }
 
-    public int parse( String input, int position, List blocks )
+    public MacroParserResult parse( String input, int position )
         throws ParseException
     {
+        MacroParserResult result = new MacroParserResult();
         String macroName = null;
         Map parameters = new HashMap();
         String parameterName = null;
@@ -121,7 +130,7 @@
                     {
                         text.append( c );
                     }
-                    else if (isInCompatibilityMode && state == STATE_PARAM_NAME)
+                    else if ( isInCompatibilityMode && state == STATE_PARAM_NAME )
                     {
                         if ( charAt( input, i ) == '}' )
                         {
@@ -146,7 +155,32 @@
                     // * {newmacro..}...{/newmacro}
                     // * {oldsinglelinemacro:...}
                     // * {oldmultilinemacro:...}...{oldmultilinemacro}
-                    if ( state == STATE_PARAM_VALUE )
+                    if ( state == STATE_PARAM_NAME )
+                    {
+                        if ( isInCompatibilityMode )
+                        {
+                            parameters.put( "default", text.toString() );
+                            text = new StringBuffer();
+
+                            // Since we can't guess if a macro is a multiline one or a single line one we rely on
+                            // a static list of known multiline macros...
+                            if ( multilineMacros.contains( macroName ) )
+                            {
+                                state = STATE_CONTENT;
+                            }
+                            else
+                            {
+                                state = STATE_END;
+                            }
+
+                        }
+                        else
+                        {
+                            throw new ParseException(
+                                "A value must be specified for a macro parameter (e.g. param=value)" );
+                        }
+                    }
+                    else if ( state == STATE_PARAM_VALUE )
                     {
                         parameters.put( parameterName, text.toString() );
                         text = new StringBuffer();
@@ -324,10 +358,12 @@
 
         if ( macroName != null )
         {
-            blocks.add( new MacroBlock( macroName, parameters, content, new ArrayList() ) );
+            result.block = new MacroBlock( macroName, parameters, content );
         }
 
-        return i;
+        result.position = i;
+
+        return result;
     }
 
     private static char charAt( String input, int i )

Added: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/MacroParser2.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/MacroParser2.java?rev=613206&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/MacroParser2.java (added)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/MacroParser2.java Fri Jan 18 09:21:42 2008
@@ -0,0 +1,26 @@
+package org.apache.maven.doxia.module.xwiki.parser;
+
+import java.util.regex.Pattern;
+
+public class MacroParser2
+{
+    private static final Pattern MACRO_PATTERN = Pattern.compile( "(?:(.*)(?::)?)?(.*)?(?:/)}(?:(.*)\\{(?:\\/)\1})?" );
+/*
+    public int parse( String input, int position, List blocks )
+        throws ParseException
+    {
+        Matcher m = MACRO_PATTERN.matcher(input.substring(position));
+        m.find();
+        Map parameters = new HashMap();
+        if (m.group(2) != null && m.group(2).length() > 0) {
+           StringTokenizer st = new StringTokenizer(m.group(2), "|");
+           while (st.hasMoreTokens()) {
+               String param = st.nextToken();
+               StringTokenizer st2 = new StringTokenizer(param, "=");
+               parameters.put(st2.nextToken(), st2.nextToken());
+           }
+        }
+
+        return position + m.
+    }*/
+}

Modified: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/ParagraphBlockParser.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/ParagraphBlockParser.java?rev=613206&r1=613205&r2=613206&view=diff
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/ParagraphBlockParser.java (original)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/ParagraphBlockParser.java Fri Jan 18 09:21:42 2008
@@ -19,16 +19,14 @@
  * under the License.
  */
 
-import org.apache.maven.doxia.module.confluence.parser.Block;
-import org.apache.maven.doxia.module.confluence.parser.BlockParser;
-import org.apache.maven.doxia.module.confluence.parser.ParagraphBlock;
+import org.apache.maven.doxia.module.xwiki.blocks.Block;
+import org.apache.maven.doxia.module.xwiki.blocks.ParagraphBlock;
 import org.apache.maven.doxia.parser.ParseException;
 import org.apache.maven.doxia.util.ByLineSource;
 
 public class ParagraphBlockParser
-    implements BlockParser
+    extends AbstractBlockParser
 {
-
     private BlockParser[] parsers;
 
     public ParagraphBlockParser( BlockParser[] parsers )
@@ -47,6 +45,7 @@
     {
 
         ChildBlocksBuilder builder = new ChildBlocksBuilder( appendUntilEmptyLine( line, source ) );
+        builder.setCompatibilityMode( isInCompatibilityMode() );
         return new ParagraphBlock( builder.getBlocks() );
     }
 

Modified: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/SectionBlockParser.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/SectionBlockParser.java?rev=613206&r1=613205&r2=613206&view=diff
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/SectionBlockParser.java (original)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/main/java/org/apache/maven/doxia/module/xwiki/parser/SectionBlockParser.java Fri Jan 18 09:21:42 2008
@@ -19,9 +19,8 @@
  * under the License.
  */
 
-import org.apache.maven.doxia.module.confluence.parser.Block;
-import org.apache.maven.doxia.module.confluence.parser.BlockParser;
-import org.apache.maven.doxia.module.confluence.parser.SectionBlock;
+import org.apache.maven.doxia.module.xwiki.blocks.Block;
+import org.apache.maven.doxia.module.xwiki.blocks.SectionBlock;
 import org.apache.maven.doxia.parser.ParseException;
 import org.apache.maven.doxia.util.ByLineSource;
 
@@ -30,7 +29,7 @@
  * @version $Id$
  */
 public class SectionBlockParser
-    implements BlockParser
+    extends AbstractBlockParser
 {
     public boolean accept( String line, ByLineSource source )
     {

Modified: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/test/java/org/apache/maven/doxia/module/xwiki/XWikiParserTest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/test/java/org/apache/maven/doxia/module/xwiki/XWikiParserTest.java?rev=613206&r1=613205&r2=613206&view=diff
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/test/java/org/apache/maven/doxia/module/xwiki/XWikiParserTest.java (original)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/test/java/org/apache/maven/doxia/module/xwiki/XWikiParserTest.java Fri Jan 18 09:21:42 2008
@@ -19,166 +19,58 @@
  * under the License.
  */
 
-import org.apache.maven.doxia.parser.AbstractParserTest;
-import org.apache.maven.doxia.parser.ParseException;
-import org.apache.maven.doxia.parser.Parser;
-import org.apache.maven.doxia.sink.Sink;
-import org.apache.maven.doxia.sink.TextSink;
-import org.codehaus.plexus.util.StringUtils;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringWriter;
-import java.io.Writer;
+import junit.framework.TestCase;
+import org.apache.maven.doxia.module.xwiki.blocks.FigureBlock;
+import org.apache.maven.doxia.module.xwiki.blocks.ParagraphBlock;
+import org.apache.maven.doxia.module.xwiki.blocks.TextBlock;
+
+import java.io.StringReader;
+import java.util.List;
 
 /**
  * Test class for XWikiParser.
  */
 public class XWikiParserTest
-    extends AbstractParserTest
+    extends TestCase
 {
     private XWikiParser parser;
 
-    private StringWriter output;
-
-    private Reader reader;
-
-    private Writer writer;
-
-    /**
-     * {@inheritDoc}
-     */
     protected void setUp()
-        throws Exception
-    {
-        super.setUp();
-
-        parser = (XWikiParser) lookup( Parser.ROLE, "xwiki" );
-
-        output = null;
-        reader = null;
-        writer = null;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    protected void tearDown()
-        throws Exception
-    {
-        if ( output != null )
-        {
-            output.close();
-        }
-        if ( reader != null )
-        {
-            reader.close();
-        }
-        if ( writer != null )
-        {
-            writer.close();
-        }
-
-        super.tearDown();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    protected Parser createParser()
-    {
-        return parser;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    protected String outputExtension()
     {
-        return "xwiki";
+        this.parser = new XWikiParser();
     }
 
-    /**
-     * @throws Exception
-     */
-    public void testSectionTitles()
+    public void testSimpleImageOnALine()
         throws Exception
     {
-        String result = locateAndParseTestSourceFile( "section" );
+        List blocks = parser.parse( new StringReader( "{image:photo.jpg}" ) );
 
-        for ( int i = 1; i <= 5; i++ )
-        {
-            assertContainsLines( "Could not locate section " + i + " title", result,
-                                 "sectionTitle" + i + "\ntext: Section" + i );
-        }
-
-        assertContainsLines( "Section title has leading space", result, "sectionTitle1\ntext: TitleWithLeadingSpace" );
-        assertContainsLines( "Section title has leading spaces before title", result,
-                             "sectionTitle1\ntext: TitleWithSpacesBefore" );
+        assertEquals( 1, blocks.size() );
+        assertTrue( blocks.get( 0 ) instanceof FigureBlock );
+        FigureBlock figureBlock = (FigureBlock) blocks.get( 0 );
+        assertEquals( "photo.jpg", figureBlock.getLocation() );
+        assertNull( figureBlock.getCaption() );
     }
 
-    /**
-     * @throws Exception
-     */
-    public void testFigure()
+    public void testImageInsideAParagraph()
         throws Exception
     {
-        String result = locateAndParseTestSourceFile( "figure" );
-
-        assertContainsLines( result, "begin:figure\nfigureGraphics, name: photo.jpg\nend:figure\n" );
-        assertContainsLines( result, "Simple paragraph with {image:image.jpg}." );
+        List blocks = parser.parse( new StringReader( "Image inside a {image:photo.jpg} paragraph." ) );
+        assertEquals( 1, blocks.size() );
+        assertTrue( blocks.get( 0 ) instanceof ParagraphBlock );
+        ParagraphBlock paraBlock = (ParagraphBlock) blocks.get( 0 );
+        assertEquals( 3, paraBlock.getBlocks().size() );
+        assertTrue( paraBlock.getBlocks().get( 0 ) instanceof TextBlock );
+        TextBlock textBlock1 = (TextBlock) paraBlock.getBlocks().get( 0 );
+        assertEquals( "Image inside a ", textBlock1.getText() );
+
+        // TODO: Decide if generate a MacroBlock or a FigureBlock
+        /*
+        FigureBlock figureBlock = (FigureBlock) paraBlock.getBlocks().get( 1 );
+        assertEquals( "photo.jpg ", figureBlock.getLocation() );
+        assertNull( figureBlock.getCaption() );
+        */
+        TextBlock textBlock2 = (TextBlock) paraBlock.getBlocks().get( 2 );
+        assertEquals( " paragraph.", textBlock2.getText() );
     }
-
-    /**
-     * @throws Exception
-     */
-    public void testParagraphWithSimpleFormatting()
-        throws Exception
-    {
-        String result = locateAndParseTestSourceFile( "simple-paragraph" );
-
-        assertContainsLines( result, "begin:bold\ntext: bold\n" );
-        assertContainsLines( result, "begin:italic\ntext: italic\n" );
-        assertContainsLines( result, "begin:monospaced\ntext: monospaced\n" );
-        assertContainsLines( result, "begin:link, name: http://jira.codehaus.org\ntext: http://jira.codehaus.org" );
-        assertContainsLines( result, "begin:link, name: http://jira.codehaus.org\ntext: JIRA\n" );
-        // four paragraphs in the input...
-        assertEquals( 5, result.split( "end:paragraph" ).length );
-    }
-
-    private void assertContainsLines( String message, String result, String lines )
-    {
-        lines = StringUtils.replace( lines, "\n", EOL );
-        if ( message != null )
-        {
-            assertTrue( message, result.indexOf( lines ) != -1 );
-        }
-        else
-        {
-            assertTrue( result.indexOf( lines ) != -1 );
-        }
-    }
-
-    private void assertContainsLines( String result, String lines )
-    {
-        this.assertContainsLines( null, result, lines );
-    }
-
-    private String locateAndParseTestSourceFile( String stem )
-        throws IOException, ParseException
-    {
-        output = new StringWriter();
-        reader = getTestReader( stem, outputExtension() );
-        writer = getTestWriter( stem, "txt" );
-
-        Sink sink = new TextSink( output );
-        createParser().parse( reader, sink );
-
-        // write to file
-        String expected = output.toString();
-        writer.write( expected );
-        writer.flush();
-        return expected;
-    }
-
 }

Modified: maven/sandbox/trunk/doxia/doxia-module-xwiki/src/test/java/org/apache/maven/doxia/module/xwiki/parser/MacroParserTest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-xwiki/src/test/java/org/apache/maven/doxia/module/xwiki/parser/MacroParserTest.java?rev=613206&r1=613205&r2=613206&view=diff
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-xwiki/src/test/java/org/apache/maven/doxia/module/xwiki/parser/MacroParserTest.java (original)
+++ maven/sandbox/trunk/doxia/doxia-module-xwiki/src/test/java/org/apache/maven/doxia/module/xwiki/parser/MacroParserTest.java Fri Jan 18 09:21:42 2008
@@ -2,9 +2,6 @@
 
 import junit.framework.TestCase;
 
-import java.util.ArrayList;
-import java.util.List;
-
 public class MacroParserTest
     extends TestCase
 {
@@ -18,139 +15,137 @@
     public void testParseSimplestMacroWithCondensedClosingStyle()
         throws Exception
     {
-        List blocks = new ArrayList();
         String macro = "{macro/}";
-        int pos = parser.parse( macro + " ...", 1, blocks );
+        MacroParser.MacroParserResult result = parser.parse( macro + " ...", 1 );
 
-        assertEquals( macro.length(), pos );
-        assertEquals( 1, blocks.size() );
-        MacroBlock macroBlock = (MacroBlock) blocks.get( 0 );
-        assertEquals( "macro", macroBlock.getName() );
-        assertEquals( "", macroBlock.getContent() );
-        assertTrue( macroBlock.getParameters().isEmpty() );
+        assertEquals( macro.length(), result.position );
+        assertNotNull( result.block );
+        assertEquals( "macro", result.block.getName() );
+        assertEquals( "", result.block.getContent() );
+        assertTrue( result.block.getParameters().isEmpty() );
     }
 
     public void testParseSimplestMacroWithExpandedClosingStyle()
         throws Exception
     {
-        List blocks = new ArrayList();
         String macro = "{macro}{/macro}";
-        int pos = parser.parse( macro + " ...", 1, blocks );
+        MacroParser.MacroParserResult result = parser.parse( macro + " ...", 1 );
 
-        assertEquals( macro.length(), pos );
-        assertEquals( 1, blocks.size() );
-        MacroBlock macroBlock = (MacroBlock) blocks.get( 0 );
-        assertEquals( "macro", macroBlock.getName() );
-        assertEquals( "", macroBlock.getContent() );
-        assertTrue( macroBlock.getParameters().isEmpty() );
+        assertEquals( macro.length(), result.position );
+        assertNotNull( result.block );
+        assertEquals( "macro", result.block.getName() );
+        assertEquals( "", result.block.getContent() );
+        assertTrue( result.block.getParameters().isEmpty() );
     }
 
     public void testParseMacroWithOneParameter()
         throws Exception
     {
-        List blocks = new ArrayList();
         String macro = "{macro:param1=value1/}";
-        int pos = parser.parse( macro + " ...", 1, blocks );
+        MacroParser.MacroParserResult result = parser.parse( macro + " ...", 1 );
 
-        assertEquals( macro.length(), pos );
-        assertEquals( 1, blocks.size() );
-        MacroBlock macroBlock = (MacroBlock) blocks.get( 0 );
-        assertEquals( "macro", macroBlock.getName() );
-        assertEquals( "", macroBlock.getContent() );
-        assertEquals( 1, macroBlock.getParameters().size() );
-        assertEquals( "value1", macroBlock.getParameters().get( "param1" ) );
+        assertEquals( macro.length(), result.position );
+        assertNotNull( result.block );
+        assertEquals( "macro", result.block.getName() );
+        assertEquals( "", result.block.getContent() );
+        assertEquals( 1, result.block.getParameters().size() );
+        assertEquals( "value1", result.block.getParameters().get( "param1" ) );
     }
 
     public void testParseMacroWithSeveralParameters()
         throws Exception
     {
-        List blocks = new ArrayList();
         String macro = "{macro:param1=value1|param2=value2/}";
-        int pos = parser.parse( macro + " ...", 1, blocks );
+        MacroParser.MacroParserResult result = parser.parse( macro + " ...", 1 );
 
-        assertEquals( macro.length(), pos );
-        assertEquals( 1, blocks.size() );
-        MacroBlock macroBlock = (MacroBlock) blocks.get( 0 );
-        assertEquals( "macro", macroBlock.getName() );
-        assertEquals( "", macroBlock.getContent() );
-        assertEquals( 2, macroBlock.getParameters().size() );
-        assertEquals( "value1", macroBlock.getParameters().get( "param1" ) );
-        assertEquals( "value2", macroBlock.getParameters().get( "param2" ) );
+        assertEquals( macro.length(), result.position );
+        assertNotNull( result.block );
+        assertEquals( "macro", result.block.getName() );
+        assertEquals( "", result.block.getContent() );
+        assertEquals( 2, result.block.getParameters().size() );
+        assertEquals( "value1", result.block.getParameters().get( "param1" ) );
+        assertEquals( "value2", result.block.getParameters().get( "param2" ) );
     }
 
     public void testParseMacroWithContent()
         throws Exception
     {
-        List blocks = new ArrayList();
         String macro = "{macro}Some /=|content{/macro}";
-        int pos = parser.parse( macro + " ...", 1, blocks );
+        MacroParser.MacroParserResult result = parser.parse( macro + " ...", 1 );
 
-        assertEquals( macro.length(), pos );
-        assertEquals( 1, blocks.size() );
-        MacroBlock macroBlock = (MacroBlock) blocks.get( 0 );
-        assertEquals( "macro", macroBlock.getName() );
-        assertEquals( "Some /=|content", macroBlock.getContent() );
-        assertEquals( 0, macroBlock.getParameters().size() );
+        assertEquals( macro.length(), result.position );
+        assertNotNull( result.block );
+        assertEquals( "macro", result.block.getName() );
+        assertEquals( "Some /=|content", result.block.getContent() );
+        assertEquals( 0, result.block.getParameters().size() );
     }
 
     public void testParseMacroWithInvalidMacroName()
         throws Exception
     {
-        List blocks = new ArrayList();
         // This is not a macro. It should be ignored and no macro block should be created
         String macro = "{[link]/}";
-        int pos = parser.parse( macro + " ...", 1, blocks );
+        MacroParser.MacroParserResult result = parser.parse( macro + " ...", 1 );
 
-        assertEquals( 1, pos );
-        assertEquals( 0, blocks.size() );
+        assertEquals( 1, result.position );
+        assertNull( result.block );
     }
 
     public void testParseOldStyleMacroInCompatibilityModeWhenMultilineMacro()
         throws Exception
     {
         parser.setCompatibilityMode( true );
-        List blocks = new ArrayList();
         String macro = "{code}Some content here{code}";
-        int pos = parser.parse( macro + " ...", 1, blocks );
+        MacroParser.MacroParserResult result = parser.parse( macro + " ...", 1 );
 
-        assertEquals( macro.length(), pos );
-        assertEquals( 1, blocks.size() );
-        MacroBlock macroBlock = (MacroBlock) blocks.get( 0 );
-        assertEquals( "code", macroBlock.getName() );
-        assertEquals( "Some content here", macroBlock.getContent() );
-        assertEquals( 0, macroBlock.getParameters().size() );
+        assertEquals( macro.length(), result.position );
+        assertNotNull( result.block );
+        assertEquals( "code", result.block.getName() );
+        assertEquals( "Some content here", result.block.getContent() );
+        assertEquals( 0, result.block.getParameters().size() );
     }
 
     public void testParseOldStyleMacroInCompatibilityModeWhenSinglelineMacro()
         throws Exception
     {
         parser.setCompatibilityMode( true );
-        List blocks = new ArrayList();
         String macro = "{somesinglelinemacro}";
-        int pos = parser.parse( macro + " ...", 1, blocks );
+        MacroParser.MacroParserResult result = parser.parse( macro + " ...", 1 );
 
-        assertEquals( macro.length(), pos );
-        assertEquals( 1, blocks.size() );
-        MacroBlock macroBlock = (MacroBlock) blocks.get( 0 );
-        assertEquals( "somesinglelinemacro", macroBlock.getName() );
-        assertEquals( "", macroBlock.getContent() );
-        assertEquals( 0, macroBlock.getParameters().size() );
+        assertEquals( macro.length(), result.position );
+        assertNotNull( result.block );
+        assertEquals( "somesinglelinemacro", result.block.getName() );
+        assertEquals( "", result.block.getContent() );
+        assertEquals( 0, result.block.getParameters().size() );
     }
 
     public void testParseOldStyleMacroWithDefaultParameterWithNoValue()
         throws Exception
     {
         parser.setCompatibilityMode( true );
-        List blocks = new ArrayList();
         String macro = "{macro:value/}";
-        int pos = parser.parse( macro + " ...", 1, blocks );
+        MacroParser.MacroParserResult result = parser.parse( macro + " ...", 1 );
+
+        assertEquals( macro.length(), result.position );
+        assertNotNull( result.block );
+        assertEquals( "macro", result.block.getName() );
+        assertEquals( "", result.block.getContent() );
+        assertEquals( 1, result.block.getParameters().size() );
+        assertEquals( "value", result.block.getParameters().get( "default" ) );
+    }
+
+    public void testParseOldStyleMacroWithDefaultParameterWithNoValueAndOldClosingStyle()
+        throws Exception
+    {
+        parser.setCompatibilityMode( true );
+        String macro = "{macro:value}";
+        MacroParser.MacroParserResult result = parser.parse( macro + " ...", 1 );
 
-        assertEquals( macro.length(), pos );
-        assertEquals( 1, blocks.size() );
-        MacroBlock macroBlock = (MacroBlock) blocks.get( 0 );
-        assertEquals( "macro", macroBlock.getName() );
-        assertEquals( "", macroBlock.getContent() );
-        assertEquals( 1, macroBlock.getParameters().size() );
-        assertEquals( "value", macroBlock.getParameters().get( "default" ) );
+        assertEquals( macro.length(), result.position );
+        assertNotNull( result.block );
+        assertEquals( "macro", result.block.getName() );
+        assertEquals( "", result.block.getContent() );
+        assertEquals( 1, result.block.getParameters().size() );
+        assertEquals( "value", result.block.getParameters().get( "default" ) );
     }
 }