Author: rfscholte Date: Sun Apr 7 09:50:29 2013 New Revision: 1465353 URL: http://svn.apache.org/r1465353 Log: [DOXIA-170] Confluence module should do something with non-doxia formatting
Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/LinethroughBlock.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/SubBlock.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/SupBlock.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/UnderlineBlock.java Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/ChildBlocksBuilder.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/ChildBlocksBuilder.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/ChildBlocksBuilder.java?rev=1465353&r1=1465352&r2=1465353&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/ChildBlocksBuilder.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/ChildBlocksBuilder.java Sun Apr 7 09:50:29 2013 @@ -41,6 +41,14 @@ public class ChildBlocksBuilder private boolean insideLink = false; + private boolean insideLinethrough = false; + + private boolean insideUnderline = false; + + private boolean insideSub = false; + + private boolean insideSup = false; + private List<Block> blocks = new ArrayList<Block>(); private StringBuilder text = new StringBuilder(); @@ -106,6 +114,74 @@ public class ChildBlocksBuilder } break; + case '-': + if ( insideLinethrough ) + { + insideLinethrough = false; + blocks.add( new LinethroughBlock( text.toString() ) ); + text = new StringBuilder(); + } + else if ( insideLink ) + { + text.append( c ); + } + else + { + text = addTextBlockIfNecessary( blocks, specialBlocks, text ); + insideLinethrough = true; + } + break; + case '+': + if ( insideUnderline ) + { + insideUnderline = false; + blocks.add( new UnderlineBlock( text.toString() ) ); + text = new StringBuilder(); + } + else if ( insideLink ) + { + text.append( c ); + } + else + { + text = addTextBlockIfNecessary( blocks, specialBlocks, text ); + insideUnderline = true; + } + break; + case '~': + if ( insideSub ) + { + insideSub = false; + blocks.add( new SubBlock( text.toString() ) ); + text = new StringBuilder(); + } + else if ( insideLink ) + { + text.append( c ); + } + else + { + text = addTextBlockIfNecessary( blocks, specialBlocks, text ); + insideSub = true; + } + break; + case '^': + if ( insideSup ) + { + insideSup = false; + blocks.add( new SupBlock( text.toString() ) ); + text = new StringBuilder(); + } + else if ( insideLink ) + { + text.append( c ); + } + else + { + text = addTextBlockIfNecessary( blocks, specialBlocks, text ); + insideSup = true; + } + break; case '[': insideLink = true; text = addTextBlockIfNecessary( blocks, specialBlocks, text ); Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/LinethroughBlock.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/LinethroughBlock.java?rev=1465353&view=auto ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/LinethroughBlock.java (added) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/LinethroughBlock.java Sun Apr 7 09:50:29 2013 @@ -0,0 +1,45 @@ +package org.apache.maven.doxia.module.confluence.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.sink.Sink; +import org.apache.maven.doxia.sink.SinkEventAttributeSet; +import org.apache.maven.doxia.sink.SinkEventAttributes; + +/** + * + * @author Robert Scholte + * @since 1.4 + */ +public class LinethroughBlock + implements Block +{ + private String text; + + public LinethroughBlock( String text ) + { + this.text = text; + } + + public void traverse( Sink sink ) + { + sink.text( text, new SinkEventAttributeSet( SinkEventAttributes.DECORATION, "line-through" ) ); + } +} Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/SubBlock.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/SubBlock.java?rev=1465353&view=auto ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/SubBlock.java (added) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/SubBlock.java Sun Apr 7 09:50:29 2013 @@ -0,0 +1,45 @@ +package org.apache.maven.doxia.module.confluence.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.sink.Sink; +import org.apache.maven.doxia.sink.SinkEventAttributeSet; +import org.apache.maven.doxia.sink.SinkEventAttributes; + +/** + * + * @author Robert Scholte + * @since 1.4 + */ +public class SubBlock + implements Block +{ + private String text; + + public SubBlock( String text ) + { + this.text = text; + } + + public void traverse( Sink sink ) + { + sink.text( text, new SinkEventAttributeSet( SinkEventAttributes.VALIGN, "sub" ) ); + } +} Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/SupBlock.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/SupBlock.java?rev=1465353&view=auto ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/SupBlock.java (added) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/SupBlock.java Sun Apr 7 09:50:29 2013 @@ -0,0 +1,45 @@ +package org.apache.maven.doxia.module.confluence.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.sink.Sink; +import org.apache.maven.doxia.sink.SinkEventAttributeSet; +import org.apache.maven.doxia.sink.SinkEventAttributes; + +/** + * + * @author Robert Scholte + * @since 1.4 + */ +public class SupBlock + implements Block +{ + private String text; + + public SupBlock( String text ) + { + this.text = text; + } + + public void traverse( Sink sink ) + { + sink.text( text, new SinkEventAttributeSet( SinkEventAttributes.VALIGN, "sup" ) ); + } +} Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/UnderlineBlock.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/UnderlineBlock.java?rev=1465353&view=auto ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/UnderlineBlock.java (added) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/UnderlineBlock.java Sun Apr 7 09:50:29 2013 @@ -0,0 +1,45 @@ +package org.apache.maven.doxia.module.confluence.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.sink.Sink; +import org.apache.maven.doxia.sink.SinkEventAttributeSet; +import org.apache.maven.doxia.sink.SinkEventAttributes; + +/** + * + * @author Robert Scholte + * @since 1.4 + */ +public class UnderlineBlock + implements Block +{ + private String text; + + public UnderlineBlock( String text ) + { + this.text = text; + } + + public void traverse( Sink sink ) + { + sink.text( text, new SinkEventAttributeSet( SinkEventAttributes.DECORATION, "underline" ) ); + } +} Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java?rev=1465353&r1=1465352&r2=1465353&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java Sun Apr 7 09:50:29 2013 @@ -31,6 +31,7 @@ import org.apache.maven.doxia.parser.Abs 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.SinkEventAttributeSet; import org.apache.maven.doxia.sink.SinkEventElement; import org.apache.maven.doxia.sink.SinkEventTestingSink; import org.apache.maven.doxia.sink.TextSink; @@ -548,6 +549,62 @@ public class ConfluenceParserTest assertEquals("body_", it.next().getName() ); } + public void testLinethrough() throws Exception { + String document = "-Linethrough-"; + output = new StringWriter(); + SinkEventTestingSink sink = new SinkEventTestingSink(); + createParser().parse(new StringReader(document), sink); + + Iterator<SinkEventElement> it = sink.getEventList().iterator(); + assertEquals(it, "head", "head_", "body", "paragraph"); + assertEquals(it.next(), "text", "Linethrough", + new SinkEventAttributeSet("decoration", "line-through")); + assertEquals(it, "paragraph_", "body_"); + assertFalse(it.hasNext()); + } + + public void testUnderline() throws Exception { + String document = "+Underline+"; + output = new StringWriter(); + SinkEventTestingSink sink = new SinkEventTestingSink(); + createParser().parse(new StringReader(document), sink); + + Iterator<SinkEventElement> it = sink.getEventList().iterator(); + assertEquals(it, "head", "head_", "body", "paragraph"); + assertEquals(it.next(), "text", "Underline", new SinkEventAttributeSet( + "decoration", "underline")); + assertEquals(it, "paragraph_", "body_"); + assertFalse(it.hasNext()); + } + + public void testSub() throws Exception { + String document = "~Sub~"; + output = new StringWriter(); + SinkEventTestingSink sink = new SinkEventTestingSink(); + createParser().parse(new StringReader(document), sink); + + Iterator<SinkEventElement> it = sink.getEventList().iterator(); + assertEquals(it, "head", "head_", "body", "paragraph"); + assertEquals(it.next(), "text", "Sub", new SinkEventAttributeSet( + "valign", "sub")); + assertEquals(it, "paragraph_", "body_"); + assertFalse(it.hasNext()); + } + + public void testSup() throws Exception { + String document = "^Sup^"; + output = new StringWriter(); + SinkEventTestingSink sink = new SinkEventTestingSink(); + createParser().parse(new StringReader(document), sink); + + Iterator<SinkEventElement> it = sink.getEventList().iterator(); + assertEquals(it, "head", "head_", "body", "paragraph"); + assertEquals(it.next(), "text", "Sup", new SinkEventAttributeSet( + "valign", "sup")); + assertEquals(it, "paragraph_", "body_"); + assertFalse(it.hasNext()); + } + private void assertContainsLines( String message, String result, String lines ) { lines = StringUtils.replace( lines, "\n", EOL );