diff --git a/.gitignore b/.gitignore index e08b03abe..acca58ef4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ /.idea /target /.repository/ +.idea +*.iml diff --git a/document/fr.opensagres.xdocreport.document.docx/src/main/java/fr/opensagres/xdocreport/document/docx/textstyling/DocxDocumentHandler.java b/document/fr.opensagres.xdocreport.document.docx/src/main/java/fr/opensagres/xdocreport/document/docx/textstyling/DocxDocumentHandler.java index 981c8690a..c5b643f9c 100644 --- a/document/fr.opensagres.xdocreport.document.docx/src/main/java/fr/opensagres/xdocreport/document/docx/textstyling/DocxDocumentHandler.java +++ b/document/fr.opensagres.xdocreport.document.docx/src/main/java/fr/opensagres/xdocreport/document/docx/textstyling/DocxDocumentHandler.java @@ -34,18 +34,13 @@ import fr.opensagres.xdocreport.document.textstyling.AbstractDocumentHandler; import fr.opensagres.xdocreport.document.textstyling.properties.Color; import fr.opensagres.xdocreport.document.textstyling.properties.ContainerProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.HeaderProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.ListItemProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.ListProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.ParagraphProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.SpanProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.TableCellProperties; import fr.opensagres.xdocreport.document.textstyling.properties.TableProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.TableRowProperties; import fr.opensagres.xdocreport.document.textstyling.properties.TextAlignment; import fr.opensagres.xdocreport.template.IContext; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.Stack; /** @@ -69,7 +64,7 @@ public class DocxDocumentHandler private Stack paragraphsStack; - private Stack spansStack; + private Stack spansStack; private HyperlinkRegistry hyperlinkRegistry; @@ -108,7 +103,7 @@ public void startDocument() this.subscripting = false; this.superscripting = false; this.paragraphsStack = new Stack(); - this.spansStack = new Stack(); + this.spansStack = new Stack(); this.addLineBreak = 0; } @@ -233,7 +228,7 @@ public void handleString( String content ) boolean subscript = subscripting; boolean superscript = superscripting; Color color = null; - SpanProperties properties = getCurrentSpanProperties(); + ContainerProperties properties = getCurrentProperties(); if ( properties != null ) { // override properties declared in the span. @@ -359,7 +354,7 @@ private void internalStartParagraph( ContainerProperties properties ) } } - public void startParagraph( ParagraphProperties properties ) + public void startParagraph( ContainerProperties properties ) throws IOException { processPageBreakBefore( properties ); @@ -410,7 +405,7 @@ public void endParagraph() processPageBreakAfter( paragraphsStack.pop() ); } - public void startListItem( ListItemProperties properties ) + public void startListItem( ContainerProperties properties ) throws IOException { // Close current paragraph @@ -517,7 +512,7 @@ public void endListItem() // endParagraph(); } - public void startHeading( int level, HeaderProperties properties ) + public void startHeading( int level, ContainerProperties properties ) throws IOException { // Close current paragraph @@ -543,7 +538,7 @@ public void endHeading( int level ) insideHeader = false; } - public void startSpan( SpanProperties properties ) + public void startSpan( ContainerProperties properties ) throws IOException { spansStack.push( properties ); @@ -557,11 +552,30 @@ public void startSpan( SpanProperties properties ) // super.write( "" ); } - private SpanProperties getCurrentSpanProperties() + /** + * Collects all active span properties + * @return + */ + private ContainerProperties getCurrentProperties() { if ( !spansStack.isEmpty() ) { - return spansStack.peek(); + // block elements first, then inline elements + List propertiesList = new ArrayList(paragraphsStack); + propertiesList.addAll( spansStack ); + ContainerProperties result = null; + for (ContainerProperties properties : propertiesList) + { + if (result == null) + { + result = properties; + } + else + { + result = ContainerProperties.combine( result, properties ); + } + } + return result; } return null; } @@ -573,7 +587,7 @@ public void endSpan() } @Override - protected void doStartOrderedList( ListProperties properties ) + protected void doStartOrderedList( ContainerProperties properties ) throws IOException { if(this.addLineBreak>0) @@ -593,7 +607,7 @@ protected void doStartOrderedList( ListProperties properties ) } @Override - protected void doStartUnorderedList( ListProperties properties ) + protected void doStartUnorderedList( ContainerProperties properties ) throws IOException { if(this.addLineBreak>0) @@ -767,7 +781,7 @@ public void doEndTable( TableProperties properties ) super.write( "" ); } - public void doStartTableRow( TableRowProperties properties ) + public void doStartTableRow( ContainerProperties properties ) throws IOException { super.write( "" ); @@ -779,7 +793,7 @@ public void doEndTableRow() super.write( "" ); } - public void doStartTableCell( TableCellProperties properties ) + public void doStartTableCell( ContainerProperties properties ) throws IOException { super.write( "" ); diff --git a/document/fr.opensagres.xdocreport.document.docx/src/test/java/fr/opensagres/xdocreport/document/docx/textstyling/DocxDocumentHandlerTestCase.java b/document/fr.opensagres.xdocreport.document.docx/src/test/java/fr/opensagres/xdocreport/document/docx/textstyling/DocxDocumentHandlerTestCase.java index 23b31bb88..09d6c6dc6 100644 --- a/document/fr.opensagres.xdocreport.document.docx/src/test/java/fr/opensagres/xdocreport/document/docx/textstyling/DocxDocumentHandlerTestCase.java +++ b/document/fr.opensagres.xdocreport.document.docx/src/test/java/fr/opensagres/xdocreport/document/docx/textstyling/DocxDocumentHandlerTestCase.java @@ -244,6 +244,22 @@ public void testStrikeWithStrike() Assert.assertEquals( "", handler.getTextEnd() ); } + @Test + public void testBoldAndItalicSpan() + throws Exception + { + IContext context = new MockContext(); + + ITextStylingTransformer formatter = HTMLTextStylingTransformer.INSTANCE; + IDocumentHandler handler = new DocxDocumentHandler( null, context, "word/document.xml" ); + formatter.transform( "text", handler ); + + Assert.assertEquals( "", handler.getTextBefore() ); + Assert.assertEquals( "text", + handler.getTextBody() ); + Assert.assertEquals( "", handler.getTextEnd() ); + } + @Test public void testHyperlinkByUsingXDocReport_HyperlinkStyle() throws Exception diff --git a/document/fr.opensagres.xdocreport.document.odt/src/main/java/fr/opensagres/xdocreport/document/odt/textstyling/ODTDefaultStylesGenerator.java b/document/fr.opensagres.xdocreport.document.odt/src/main/java/fr/opensagres/xdocreport/document/odt/textstyling/ODTDefaultStylesGenerator.java index 06ae34f9a..feb081ade 100644 --- a/document/fr.opensagres.xdocreport.document.odt/src/main/java/fr/opensagres/xdocreport/document/odt/textstyling/ODTDefaultStylesGenerator.java +++ b/document/fr.opensagres.xdocreport.document.odt/src/main/java/fr/opensagres/xdocreport/document/odt/textstyling/ODTDefaultStylesGenerator.java @@ -30,7 +30,7 @@ import java.util.regex.Pattern; import fr.opensagres.xdocreport.document.textstyling.properties.ContainerProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.ContainerProperties.ContainerType; +import fr.opensagres.xdocreport.document.textstyling.properties.ContainerType; import fr.opensagres.xdocreport.document.textstyling.properties.TextAlignment; /** diff --git a/document/fr.opensagres.xdocreport.document.odt/src/main/java/fr/opensagres/xdocreport/document/odt/textstyling/ODTDocumentHandler.java b/document/fr.opensagres.xdocreport.document.odt/src/main/java/fr/opensagres/xdocreport/document/odt/textstyling/ODTDocumentHandler.java index 59a6907d4..466f4dc42 100644 --- a/document/fr.opensagres.xdocreport.document.odt/src/main/java/fr/opensagres/xdocreport/document/odt/textstyling/ODTDocumentHandler.java +++ b/document/fr.opensagres.xdocreport.document.odt/src/main/java/fr/opensagres/xdocreport/document/odt/textstyling/ODTDocumentHandler.java @@ -33,15 +33,8 @@ import fr.opensagres.xdocreport.document.odt.template.ODTContextHelper; import fr.opensagres.xdocreport.document.preprocessor.sax.BufferedElement; import fr.opensagres.xdocreport.document.textstyling.AbstractDocumentHandler; -import fr.opensagres.xdocreport.document.textstyling.IDocumentHandler.TextLocation; -import fr.opensagres.xdocreport.document.textstyling.properties.HeaderProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.ListItemProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.ListProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.ParagraphProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.SpanProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.TableCellProperties; +import fr.opensagres.xdocreport.document.textstyling.properties.ContainerProperties; import fr.opensagres.xdocreport.document.textstyling.properties.TableProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.TableRowProperties; import fr.opensagres.xdocreport.template.IContext; public class ODTDocumentHandler @@ -263,7 +256,7 @@ private void startParagraphIfNeeded() } } - public void startParagraph( ParagraphProperties properties ) + public void startParagraph( ContainerProperties properties ) throws IOException { if ( paragraphsStack.isEmpty() || !paragraphsStack.peek() ) @@ -283,7 +276,7 @@ public void endParagraph() // } } - private void internalStartParagraph( boolean containerIsList, ParagraphProperties properties ) + private void internalStartParagraph( boolean containerIsList, ContainerProperties properties ) throws IOException { String styleName = null; @@ -350,7 +343,7 @@ private void internalEndParagraph() } } - public void startHeading( int level, HeaderProperties properties ) + public void startHeading( int level, ContainerProperties properties ) throws IOException { endParagraphIfNeeded(); @@ -371,7 +364,7 @@ public void endHeading( int level ) } @Override - protected void doStartOrderedList( ListProperties properties ) + protected void doStartOrderedList( ContainerProperties properties ) throws IOException { internalStartList( styleGen.getOLStyleName() ); @@ -385,7 +378,7 @@ protected void doEndOrderedList() } @Override - protected void doStartUnorderedList( ListProperties properties ) + protected void doStartUnorderedList( ContainerProperties properties ) throws IOException { internalStartList( styleGen.getULStyleName() ); @@ -440,7 +433,7 @@ protected void internalEndList() } } - public void startListItem( ListItemProperties properties ) + public void startListItem( ContainerProperties properties ) throws IOException { if ( itemStyle != null ) @@ -470,7 +463,7 @@ public void endListItem() super.write( "" ); } - public void startSpan( SpanProperties properties ) + public void startSpan( ContainerProperties properties ) throws IOException { internalStartSpan( styleGen.getTextStyleName( properties ), true ); @@ -532,7 +525,7 @@ public void doEndTable( TableProperties properties ) super.write( "" ); } - protected void doStartTableRow( TableRowProperties properties ) + protected void doStartTableRow( ContainerProperties properties ) throws IOException { super.write( "" ); @@ -544,7 +537,7 @@ protected void doEndTableRow() super.write( "" ); } - protected void doStartTableCell( TableCellProperties properties ) + protected void doStartTableCell( ContainerProperties properties ) throws IOException { super.write( "" ); diff --git a/document/fr.opensagres.xdocreport.document.textstyling.wiki/src/main/java/fr/opensagres/xdocreport/document/textstyling/wiki/WemListenerAdapter.java b/document/fr.opensagres.xdocreport.document.textstyling.wiki/src/main/java/fr/opensagres/xdocreport/document/textstyling/wiki/WemListenerAdapter.java index c0d33853a..19b1af5ab 100644 --- a/document/fr.opensagres.xdocreport.document.textstyling.wiki/src/main/java/fr/opensagres/xdocreport/document/textstyling/wiki/WemListenerAdapter.java +++ b/document/fr.opensagres.xdocreport.document.textstyling.wiki/src/main/java/fr/opensagres/xdocreport/document/textstyling/wiki/WemListenerAdapter.java @@ -28,6 +28,7 @@ import java.util.List; import java.util.logging.Logger; +import fr.opensagres.xdocreport.document.textstyling.properties.ContainerProperties; import org.wikimodel.wem.EmptyWemListener; import org.wikimodel.wem.IWemConstants; import org.wikimodel.wem.WikiFormat; @@ -37,9 +38,6 @@ import fr.opensagres.xdocreport.core.logging.LogUtils; import fr.opensagres.xdocreport.document.textstyling.IDocumentHandler; -import fr.opensagres.xdocreport.document.textstyling.properties.ListItemProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.ListProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.ParagraphProperties; /** * Wiki Event Model Adaptor to call methods of {@link IDocumentHandler}. @@ -136,7 +134,7 @@ public void beginList( WikiParameters params, boolean ordered ) { try { - ListProperties properties = null; + ContainerProperties properties = null; if ( ordered ) { documentHandler.startOrderedList( properties ); @@ -157,7 +155,7 @@ public void beginListItem() { try { - ListItemProperties properties = null; + ContainerProperties properties = null; documentHandler.startListItem( properties ); } catch ( IOException e ) @@ -230,7 +228,7 @@ public void beginParagraph( WikiParameters params ) { try { - ParagraphProperties properties = null; + ContainerProperties properties = null; documentHandler.startParagraph( properties ); } catch ( IOException e ) diff --git a/document/fr.opensagres.xdocreport.document.textstyling.wiki/src/test/java/fr/opensagres/xdocreport/document/textstyling/wiki/gwiki/HTMLDocumentHandler.java b/document/fr.opensagres.xdocreport.document.textstyling.wiki/src/test/java/fr/opensagres/xdocreport/document/textstyling/wiki/gwiki/HTMLDocumentHandler.java index 615ad6e96..8bac4f492 100644 --- a/document/fr.opensagres.xdocreport.document.textstyling.wiki/src/test/java/fr/opensagres/xdocreport/document/textstyling/wiki/gwiki/HTMLDocumentHandler.java +++ b/document/fr.opensagres.xdocreport.document.textstyling.wiki/src/test/java/fr/opensagres/xdocreport/document/textstyling/wiki/gwiki/HTMLDocumentHandler.java @@ -27,14 +27,8 @@ import java.io.IOException; import fr.opensagres.xdocreport.document.textstyling.AbstractDocumentHandler; -import fr.opensagres.xdocreport.document.textstyling.properties.HeaderProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.ListItemProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.ListProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.ParagraphProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.SpanProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.TableCellProperties; +import fr.opensagres.xdocreport.document.textstyling.properties.ContainerProperties; import fr.opensagres.xdocreport.document.textstyling.properties.TableProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.TableRowProperties; /** * Basic Document handler implementation to build html fragment content. @@ -136,7 +130,7 @@ public void endSuperscript() super.write( "" ); } - public void startListItem( ListItemProperties properties ) + public void startListItem( ContainerProperties properties ) throws IOException { super.write( "
  • " ); @@ -149,7 +143,7 @@ public void endListItem() } @Override - protected void doStartOrderedList( ListProperties properties ) + protected void doStartOrderedList( ContainerProperties properties ) throws IOException { super.write( "
      " ); @@ -163,7 +157,7 @@ protected void doEndOrderedList() } @Override - protected void doStartUnorderedList( ListProperties properties ) + protected void doStartUnorderedList( ContainerProperties properties ) throws IOException { super.write( "
        " ); @@ -176,7 +170,7 @@ protected void doEndUnorderedList() super.write( "
      " ); } - public void startParagraph( ParagraphProperties properties ) + public void startParagraph( ContainerProperties properties ) throws IOException { super.write( "

      " ); @@ -188,7 +182,7 @@ public void endParagraph() super.write( "

      " ); } - public void startSpan( SpanProperties properties ) + public void startSpan( ContainerProperties properties ) throws IOException { super.write( "" ); @@ -200,7 +194,7 @@ public void endSpan() super.write( "" ); } - public void startHeading( int level, HeaderProperties properties ) + public void startHeading( int level, ContainerProperties properties ) throws IOException { super.write( "" ); } - protected void doStartTableRow( TableRowProperties properties ) + protected void doStartTableRow( ContainerProperties properties ) throws IOException { super.write( "" ); @@ -267,7 +261,7 @@ public void doEndTableRow() super.write( "" ); } - protected void doStartTableCell( TableCellProperties properties ) + protected void doStartTableCell( ContainerProperties properties ) throws IOException { super.write( "" ); diff --git a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/AbstractDocumentHandler.java b/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/AbstractDocumentHandler.java index 8765c54fa..638077fa6 100644 --- a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/AbstractDocumentHandler.java +++ b/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/AbstractDocumentHandler.java @@ -30,10 +30,8 @@ import java.util.Stack; import fr.opensagres.xdocreport.document.preprocessor.sax.BufferedElement; -import fr.opensagres.xdocreport.document.textstyling.properties.ListProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.TableCellProperties; +import fr.opensagres.xdocreport.document.textstyling.properties.ContainerProperties; import fr.opensagres.xdocreport.document.textstyling.properties.TableProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.TableRowProperties; import fr.opensagres.xdocreport.template.IContext; /** @@ -80,7 +78,7 @@ public void handleString( String s ) getCurrentWriter().write( s ); } - public final void startOrderedList( ListProperties properties ) + public final void startOrderedList( ContainerProperties properties ) throws IOException { listStack.push( true ); @@ -94,7 +92,7 @@ public final void endOrderedList() doEndOrderedList(); } - public final void startUnorderedList( ListProperties properties ) + public final void startUnorderedList( ContainerProperties properties ) throws IOException { listStack.push( false ); @@ -144,7 +142,7 @@ public final void endTable() doEndTable( properties ); } - public final void startTableRow( TableRowProperties properties ) + public final void startTableRow( ContainerProperties properties ) throws IOException { TableProperties tableProperties = this.tablesStack.peek(); @@ -159,7 +157,7 @@ public final void endTableRow() doEndTableRow(); } - public final void startTableCell( TableCellProperties properties ) + public final void startTableCell( ContainerProperties properties ) throws IOException { TableProperties tableProperties = this.tablesStack.peek(); @@ -306,10 +304,10 @@ public String toString() return result.toString(); } - protected abstract void doStartUnorderedList( ListProperties properties ) + protected abstract void doStartUnorderedList( ContainerProperties properties ) throws IOException; - protected abstract void doStartOrderedList( ListProperties properties ) + protected abstract void doStartOrderedList( ContainerProperties properties ) throws IOException; protected abstract void doEndUnorderedList() @@ -324,13 +322,13 @@ protected abstract void doStartTable( TableProperties properties ) protected abstract void doEndTable( TableProperties properties ) throws IOException; - protected abstract void doStartTableRow( TableRowProperties properties ) + protected abstract void doStartTableRow( ContainerProperties properties ) throws IOException; protected abstract void doEndTableRow() throws IOException; - protected abstract void doStartTableCell( TableCellProperties properties ) + protected abstract void doStartTableCell( ContainerProperties properties ) throws IOException; protected abstract void doEndTableCell() diff --git a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/IDocumentHandler.java b/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/IDocumentHandler.java index 0a7d1e048..6a72c7686 100644 --- a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/IDocumentHandler.java +++ b/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/IDocumentHandler.java @@ -26,14 +26,8 @@ import java.io.IOException; -import fr.opensagres.xdocreport.document.textstyling.properties.HeaderProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.ListItemProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.ListProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.ParagraphProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.SpanProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.TableCellProperties; +import fr.opensagres.xdocreport.document.textstyling.properties.ContainerProperties; import fr.opensagres.xdocreport.document.textstyling.properties.TableProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.TableRowProperties; /** * Handler to build a document. @@ -62,7 +56,7 @@ void endDocument() /** * Start paragraph. */ - void startParagraph( ParagraphProperties properties ) + void startParagraph( ContainerProperties properties ) throws IOException; /** @@ -148,7 +142,7 @@ void endSuperscript() * * @param properties */ - void startOrderedList( ListProperties properties ) + void startOrderedList( ContainerProperties properties ) throws IOException; /** @@ -162,7 +156,7 @@ void endOrderedList() * * @param properties */ - void startUnorderedList( ListProperties properties ) + void startUnorderedList( ContainerProperties properties ) throws IOException; /** @@ -174,7 +168,7 @@ void endUnorderedList() /** * Start list item. */ - void startListItem( ListItemProperties properties ) + void startListItem( ContainerProperties properties ) throws IOException; /** @@ -186,7 +180,7 @@ void endListItem() /** * Start span item. */ - void startSpan( SpanProperties properties ) + void startSpan( ContainerProperties properties ) throws IOException; /** @@ -209,7 +203,7 @@ void handleString( String s ) * @param level * @throws IOException */ - void startHeading( int level, HeaderProperties properties ) + void startHeading( int level, ContainerProperties properties ) throws IOException; /** @@ -243,7 +237,7 @@ void endTable() * @param properties table row properties. @throws IOException */ - void startTableRow (TableRowProperties properties ) + void startTableRow ( ContainerProperties properties ) throws IOException; /** @@ -260,7 +254,7 @@ void endTableRow() * @param properties table cell propertie. * @throws IOException */ - void startTableCell( TableCellProperties properties ) + void startTableCell( ContainerProperties properties ) throws IOException; /** diff --git a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/html/HTMLTextStylingContentHandler.java b/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/html/HTMLTextStylingContentHandler.java index 4714eaddc..2168ac963 100644 --- a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/html/HTMLTextStylingContentHandler.java +++ b/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/html/HTMLTextStylingContentHandler.java @@ -26,26 +26,21 @@ import java.io.IOException; +import fr.opensagres.xdocreport.document.textstyling.properties.ContainerProperties; +import fr.opensagres.xdocreport.document.textstyling.properties.ContainerType; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; import fr.opensagres.xdocreport.document.textstyling.IDocumentHandler; -import fr.opensagres.xdocreport.document.textstyling.properties.HeaderProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.ListItemProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.ListProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.ParagraphProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.SpanProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.TableCellProperties; import fr.opensagres.xdocreport.document.textstyling.properties.TableProperties; -import fr.opensagres.xdocreport.document.textstyling.properties.TableRowProperties; /** * SAX content handler used to parse HTML content and call the right method of {@link IDocumentHandler} according the * HTML content. */ public class HTMLTextStylingContentHandler - extends DefaultHandler + extends DefaultHandler { private static final String STYLE_ATTR = "style"; @@ -136,7 +131,7 @@ public HTMLTextStylingContentHandler( IDocumentHandler visitor ) @Override public void startDocument() - throws SAXException + throws SAXException { super.startDocument(); try @@ -151,7 +146,7 @@ public void startDocument() @Override public void endDocument() - throws SAXException + throws SAXException { super.endDocument(); try @@ -166,7 +161,7 @@ public void endDocument() @Override public void startElement( String uri, String localName, String name, Attributes attributes ) - throws SAXException + throws SAXException { ignoreCharacters = false; try @@ -204,63 +199,71 @@ else if ( SUP_ELT.equals( name ) ) else if ( UL_ELT.equals( name ) ) { // Unordered List - ListProperties properties = StylesHelper.createListProperties( attributes.getValue( STYLE_ATTR ) ); + ContainerProperties properties = StylesHelper.createProperties( attributes.getValue( STYLE_ATTR ), + ContainerType.LIST ); startList( false, properties ); } else if ( OL_ELT.equals( name ) ) { // Orderer List - ListProperties properties = StylesHelper.createListProperties( attributes.getValue( STYLE_ATTR ) ); + ContainerProperties properties = StylesHelper.createProperties( attributes.getValue( STYLE_ATTR ), + ContainerType.LIST ); startList( true, properties ); } else if ( LI_ELT.equals( name ) ) { // List item - ListItemProperties properties = - StylesHelper.createListItemProperties( attributes.getValue( STYLE_ATTR ) ); + ContainerProperties properties = StylesHelper.createProperties( attributes.getValue( STYLE_ATTR ), + ContainerType.LIST_ITEM ); documentHandler.startListItem( properties ); } else if ( P_ELT.equals( name ) ) { // Paragraph - ParagraphProperties properties = - StylesHelper.createParagraphProperties( attributes.getValue( STYLE_ATTR ) ); + ContainerProperties properties = StylesHelper.createProperties( attributes.getValue( STYLE_ATTR ), + ContainerType.PARAGRAPH ); documentHandler.startParagraph( properties ); } else if ( H1_ELT.equals( name ) ) { // Header 1 - HeaderProperties properties = StylesHelper.createHeaderProperties( attributes.getValue( STYLE_ATTR ) ); + ContainerProperties properties = StylesHelper.createProperties( attributes.getValue( STYLE_ATTR ), + ContainerType.HEADER ); documentHandler.startHeading( 1, properties ); } else if ( H2_ELT.equals( name ) ) { // Header 2 - HeaderProperties properties = StylesHelper.createHeaderProperties( attributes.getValue( STYLE_ATTR ) ); + ContainerProperties properties = StylesHelper.createProperties( attributes.getValue( STYLE_ATTR ), + ContainerType.HEADER ); documentHandler.startHeading( 2, properties ); } else if ( H3_ELT.equals( name ) ) { // Header 3 - HeaderProperties properties = StylesHelper.createHeaderProperties( attributes.getValue( STYLE_ATTR ) ); + ContainerProperties properties = StylesHelper.createProperties( attributes.getValue( STYLE_ATTR ), + ContainerType.HEADER ); documentHandler.startHeading( 3, properties ); } else if ( H4_ELT.equals( name ) ) { // Header 4 - HeaderProperties properties = StylesHelper.createHeaderProperties( attributes.getValue( STYLE_ATTR ) ); + ContainerProperties properties = StylesHelper.createProperties( attributes.getValue( STYLE_ATTR ), + ContainerType.HEADER ); documentHandler.startHeading( 4, properties ); } else if ( H5_ELT.equals( name ) ) { // Header 5 - HeaderProperties properties = StylesHelper.createHeaderProperties( attributes.getValue( STYLE_ATTR ) ); + ContainerProperties properties = StylesHelper.createProperties( attributes.getValue( STYLE_ATTR ), + ContainerType.HEADER ); documentHandler.startHeading( 5, properties ); } else if ( H6_ELT.equals( name ) ) { // Header 6 - HeaderProperties properties = StylesHelper.createHeaderProperties( attributes.getValue( STYLE_ATTR ) ); + ContainerProperties properties = StylesHelper.createProperties( attributes.getValue( STYLE_ATTR ), + ContainerType.HEADER ); documentHandler.startHeading( 6, properties ); } else if ( A_ELT.equals( name ) ) @@ -277,7 +280,8 @@ else if ( IMG_ELT.equals( name ) ) else if ( SPAN_ELT.equals( name ) ) { // - SpanProperties properties = StylesHelper.createSpanProperties( attributes.getValue( STYLE_ATTR ) ); + ContainerProperties properties = StylesHelper.createProperties( attributes.getValue( STYLE_ATTR ), + ContainerType.SPAN ); documentHandler.startSpan( properties ); } else if ( TABLE_ELT.equals( name ) ) @@ -289,13 +293,15 @@ else if ( TABLE_ELT.equals( name ) ) else if ( TR_ELT.equals( name ) ) { // - TableRowProperties properties = StylesHelper.createTableRowProperties( attributes ); + ContainerProperties properties = StylesHelper.createProperties( attributes.getValue( STYLE_ATTR ), + ContainerType.TABLE_ROW ); documentHandler.startTableRow( properties ); } else if ( TD_ELT.equals( name ) ) { // - TableCellProperties properties = StylesHelper.createTableCellProperties( attributes ); + ContainerProperties properties = StylesHelper.createProperties( attributes.getValue( STYLE_ATTR ), + ContainerType.TABLE_CELL ); documentHandler.startTableCell( properties ); } } @@ -308,7 +314,7 @@ else if ( TD_ELT.equals( name ) ) @Override public void endElement( String uri, String localName, String name ) - throws SAXException + throws SAXException { ignoreCharacters = false; try @@ -436,7 +442,7 @@ else if ( TD_ELT.equals( name ) ) @Override public void characters( char[] ch, int start, int length ) - throws SAXException + throws SAXException { if ( !ignoreCharacters ) { @@ -459,8 +465,8 @@ public void characters( char[] ch, int start, int length ) super.characters( ch, start, length ); } - private void startList( boolean ordered, ListProperties properties ) - throws IOException + private void startList( boolean ordered, ContainerProperties properties ) + throws IOException { ignoreCharacters = true; if ( ordered ) @@ -474,7 +480,7 @@ private void startList( boolean ordered, ListProperties properties ) } private void endList( boolean ordered ) - throws IOException + throws IOException { if ( ordered ) { diff --git a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/html/StylesHelper.java b/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/html/StylesHelper.java index ad20d8305..6f5fb85f7 100644 --- a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/html/StylesHelper.java +++ b/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/html/StylesHelper.java @@ -67,95 +67,24 @@ public static Map parse( String style ) } /** - * Create {@link ParagraphProperties} from inline style. + * Create {@link ContainerProperties} from inline style. * * @param style + * @param type * @return */ - public static ParagraphProperties createParagraphProperties( String style ) + public static ContainerProperties createProperties( String style, ContainerType type ) { Map stylesMap = StylesHelper.parse( style ); if ( !stylesMap.isEmpty() ) { - ParagraphProperties properties = new ParagraphProperties(); + ContainerProperties properties = new ContainerProperties( type ); processContainerproperties(properties, stylesMap); return properties; } return null; } - /** - * Create {@link HeaderProperties} from inline style. - * - * @param style - * @return - */ - public static HeaderProperties createHeaderProperties( String style ) - { - Map stylesMap = StylesHelper.parse( style ); - if ( !stylesMap.isEmpty() ) - { - HeaderProperties properties = new HeaderProperties(); - processContainerproperties( properties, stylesMap ); - return properties; - } - return null; - } - - /** - * Create {@link ListItemProperties} from inline style. - * - * @param style - * @return - */ - public static ListItemProperties createListItemProperties( String style ) - { - Map stylesMap = StylesHelper.parse( style ); - if ( !stylesMap.isEmpty() ) - { - ListItemProperties properties = new ListItemProperties(); - processContainerproperties( properties, stylesMap ); - return properties; - } - return null; - } - - /** - * Create {@link ListProperties} from inline style. - * - * @param style - * @return - */ - public static ListProperties createListProperties( String style ) - { - Map stylesMap = StylesHelper.parse( style ); - if ( !stylesMap.isEmpty() ) - { - ListProperties properties = new ListProperties(); - processContainerproperties( properties, stylesMap ); - return properties; - } - return null; - } - - /** - * Create {@link SpanProperties} from inline style. - * - * @param style - * @return - */ - public static SpanProperties createSpanProperties( String style ) - { - Map stylesMap = StylesHelper.parse( style ); - if ( !stylesMap.isEmpty() ) - { - SpanProperties properties = new SpanProperties(); - processContainerproperties( properties, stylesMap ); - return properties; - } - return null; - } - private static void processContainerproperties( ContainerProperties properties, Map stylesMap ) { // page-break-before @@ -274,16 +203,4 @@ public static TableProperties createTableProperties( Attributes attributes ) TableProperties properties = new TableProperties(); return properties; } - - public static TableRowProperties createTableRowProperties( Attributes attributes ) - { - TableRowProperties properties = new TableRowProperties(); - return properties; - } - - public static TableCellProperties createTableCellProperties( Attributes attributes ) - { - TableCellProperties properties = new TableCellProperties(); - return properties; - } } diff --git a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/ContainerProperties.java b/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/ContainerProperties.java index 3160eaf04..e453eb18b 100644 --- a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/ContainerProperties.java +++ b/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/ContainerProperties.java @@ -27,14 +27,8 @@ /** * Container properties. */ -public abstract class ContainerProperties +public class ContainerProperties { - - public enum ContainerType - { - SPAN, PARAGRAPH, LIST, LIST_ITEM, HEADER - } - private boolean pageBreakBefore; private boolean pageBreakAfter; @@ -179,6 +173,26 @@ public void setColor( Color color ) this.color = color; } + public static ContainerProperties combine( ContainerProperties p1, ContainerProperties p2 ) + { + ContainerProperties result = new ContainerProperties( + p1.getType() == p2.getType() ? p1.getType() : ContainerType.COMBINED ); + + result.pageBreakBefore = p1.pageBreakBefore || p2.pageBreakBefore; + result.pageBreakAfter = p1.pageBreakAfter || p2.pageBreakAfter; + result.bold = p1.bold || p2.bold; + result.italic = p1.italic || p2.italic; + result.underline = p1.underline || p2.underline; + result.strike = p1.strike || p2.strike; + result.subscript = p1.subscript || p2.subscript; + result.superscript = p1.superscript || p2.superscript; + result.textAlignment = p2.textAlignment == null ? p1.textAlignment : p2.textAlignment; + result.color = p2.color == null ? p1.color : p2.color; + result.styleName = p2.styleName == null ? p1.styleName : p2.styleName; + + return result; + } + @Override public boolean equals( Object o ) { diff --git a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/TableRowProperties.java b/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/ContainerType.java similarity index 90% rename from document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/TableRowProperties.java rename to document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/ContainerType.java index a6f74f15e..d24757403 100644 --- a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/TableRowProperties.java +++ b/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/ContainerType.java @@ -1,33 +1,37 @@ -/** - * Copyright (C) 2011-2015 The XDocReport Team - * - * All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package fr.opensagres.xdocreport.document.textstyling.properties; - -/** - * Table properties. - */ -public class TableRowProperties -{ - -} +/** + * Copyright (C) 2011-2015 The XDocReport Team + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package fr.opensagres.xdocreport.document.textstyling.properties; + +public enum ContainerType +{ + SPAN, + PARAGRAPH, + LIST, + LIST_ITEM, + HEADER, + TABLE_ROW, + TABLE_CELL, + COMBINED +} diff --git a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/HeaderProperties.java b/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/HeaderProperties.java deleted file mode 100644 index c0ee5f48e..000000000 --- a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/HeaderProperties.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (C) 2011-2015 The XDocReport Team - * - * All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package fr.opensagres.xdocreport.document.textstyling.properties; - -/** - * Header properties. - */ -public class HeaderProperties - extends ContainerProperties -{ - - public HeaderProperties() - { - super( ContainerType.HEADER ); - } -} diff --git a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/ListItemProperties.java b/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/ListItemProperties.java deleted file mode 100644 index 0dea63d29..000000000 --- a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/ListItemProperties.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (C) 2011-2015 The XDocReport Team - * - * All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package fr.opensagres.xdocreport.document.textstyling.properties; - -/** - * List Item properties. - */ -public class ListItemProperties - extends ContainerProperties -{ - - public ListItemProperties() - { - super( ContainerType.LIST_ITEM ); - } -} diff --git a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/ListProperties.java b/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/ListProperties.java deleted file mode 100644 index d8a806006..000000000 --- a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/ListProperties.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (C) 2011-2015 The XDocReport Team - * - * All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package fr.opensagres.xdocreport.document.textstyling.properties; - -/** - * List properties. - */ -public class ListProperties - extends ContainerProperties -{ - - public ListProperties() - { - super( ContainerType.LIST ); - } -} diff --git a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/ParagraphProperties.java b/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/ParagraphProperties.java deleted file mode 100644 index fbdc5ccaa..000000000 --- a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/ParagraphProperties.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (C) 2011-2015 The XDocReport Team - * - * All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package fr.opensagres.xdocreport.document.textstyling.properties; - -/** - * Paragraph properties. - */ -public class ParagraphProperties - extends ContainerProperties -{ - - public ParagraphProperties() - { - super( ContainerType.PARAGRAPH ); - } -} diff --git a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/SpanProperties.java b/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/SpanProperties.java deleted file mode 100644 index 15371c7b9..000000000 --- a/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/textstyling/properties/SpanProperties.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (C) 2011-2015 The XDocReport Team - * - * All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package fr.opensagres.xdocreport.document.textstyling.properties; - -/** - * Span properties. - */ -public class SpanProperties - extends ContainerProperties -{ - - public SpanProperties() - { - super( ContainerType.SPAN ); - } -} diff --git a/document/fr.opensagres.xdocreport.document/src/test/java/fr/opensagres/xdocreport/document/textstyling/html/StylesHelperTest.java b/document/fr.opensagres.xdocreport.document/src/test/java/fr/opensagres/xdocreport/document/textstyling/html/StylesHelperTest.java index ef5b5dae3..4d62ef2e7 100644 --- a/document/fr.opensagres.xdocreport.document/src/test/java/fr/opensagres/xdocreport/document/textstyling/html/StylesHelperTest.java +++ b/document/fr.opensagres.xdocreport.document/src/test/java/fr/opensagres/xdocreport/document/textstyling/html/StylesHelperTest.java @@ -25,7 +25,8 @@ package fr.opensagres.xdocreport.document.textstyling.html; import fr.opensagres.xdocreport.document.textstyling.properties.Color; -import fr.opensagres.xdocreport.document.textstyling.properties.SpanProperties; +import fr.opensagres.xdocreport.document.textstyling.properties.ContainerProperties; +import fr.opensagres.xdocreport.document.textstyling.properties.ContainerType; import junit.framework.Assert; import org.junit.Test; @@ -35,19 +36,25 @@ public class StylesHelperTest @Test public void createSpanPropertiesColor() { - SpanProperties expectedSpanProperties = new SpanProperties(); + ContainerProperties expectedSpanProperties = new ContainerProperties( ContainerType.SPAN ); expectedSpanProperties.setColor( new Color( 230, 0, 0 ) ); - Assert.assertEquals( expectedSpanProperties, StylesHelper.createSpanProperties( "color: rgb(230, 0, 0);" ) ); + Assert.assertEquals( expectedSpanProperties, + StylesHelper.createProperties( "color: rgb(230, 0, 0);", ContainerType.SPAN ) ); + Assert.assertEquals( expectedSpanProperties, + StylesHelper.createProperties( "color: #E60000;", ContainerType.SPAN ) ); } @Test public void createSpanPropertiesColorInvalid() { - SpanProperties expectedSpanProperties = new SpanProperties(); + ContainerProperties expectedSpanProperties = new ContainerProperties( ContainerType.SPAN ); - Assert.assertEquals( expectedSpanProperties, StylesHelper.createSpanProperties( "color: rgb(2303, 0, 0);" ) ); - Assert.assertEquals( expectedSpanProperties, StylesHelper.createSpanProperties( "color: #1234567;" ) ); - Assert.assertEquals( expectedSpanProperties, StylesHelper.createSpanProperties( "color: invalid;" ) ); + Assert.assertEquals( expectedSpanProperties, + StylesHelper.createProperties( "color: rgb(2303, 0, 0);", ContainerType.SPAN ) ); + Assert.assertEquals( expectedSpanProperties, + StylesHelper.createProperties( "color: #1234567;", ContainerType.SPAN ) ); + Assert.assertEquals( expectedSpanProperties, + StylesHelper.createProperties( "color: invalid;", ContainerType.SPAN ) ); } } diff --git a/document/fr.opensagres.xdocreport.document/src/test/java/fr/opensagres/xdocreport/document/textstyling/properties/ContainerPropertiesTest.java b/document/fr.opensagres.xdocreport.document/src/test/java/fr/opensagres/xdocreport/document/textstyling/properties/ContainerPropertiesTest.java new file mode 100644 index 000000000..1abd3c20a --- /dev/null +++ b/document/fr.opensagres.xdocreport.document/src/test/java/fr/opensagres/xdocreport/document/textstyling/properties/ContainerPropertiesTest.java @@ -0,0 +1,96 @@ +/** + * Copyright (C) 2011-2015 The XDocReport Team + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package fr.opensagres.xdocreport.document.textstyling.properties; + +import org.junit.Assert; +import org.junit.Test; + +public class ContainerPropertiesTest +{ + @Test + public void combineKeepTypeIfSame() + { + ContainerProperties a = new ContainerProperties( ContainerType.SPAN ); + ContainerProperties b = new ContainerProperties( ContainerType.SPAN ); + + ContainerProperties result = ContainerProperties.combine( a, b ); + Assert.assertEquals( result.getType(), ContainerType.SPAN ); + } + + @Test + public void combineCombinedTypeIfDifferent() + { + ContainerProperties a = new ContainerProperties( ContainerType.SPAN ); + ContainerProperties b = new ContainerProperties( ContainerType.HEADER ); + + ContainerProperties result = ContainerProperties.combine( a, b ); + Assert.assertEquals( result.getType(), ContainerType.COMBINED ); + } + + @Test + public void combineCombined() + { + ContainerProperties a = new ContainerProperties( ContainerType.SPAN ); + a.setPageBreakBefore( true ); + a.setPageBreakAfter( true ); + a.setBold( true ); + a.setItalic( false ); + a.setUnderline( false ); + a.setStrike( true ); + a.setSubscript( true ); + a.setSuperscript( true ); + a.setTextAlignment( TextAlignment.Center ); + final Color color = new Color( 120, 130, 140 ); + a.setColor( color ); + a.setStyleName( "a" ); + + ContainerProperties b = new ContainerProperties( ContainerType.HEADER ); + b.setPageBreakBefore( false ); + b.setPageBreakAfter( true ); + b.setBold( false ); + b.setItalic( false ); + b.setUnderline( true ); + b.setStrike( false ); + b.setSubscript( false ); + b.setSuperscript( false ); + b.setTextAlignment( TextAlignment.Inherit ); + b.setColor( null ); + b.setStyleName( "b" ); + + ContainerProperties result = ContainerProperties.combine( a, b ); + Assert.assertEquals( result.getType(), ContainerType.COMBINED ); + Assert.assertTrue( result.isPageBreakBefore() ); + Assert.assertTrue( result.isPageBreakAfter() ); + Assert.assertTrue( result.isBold() ); + Assert.assertFalse( result.isItalic() ); + Assert.assertTrue( result.isUnderline() ); + Assert.assertTrue( result.isStrike() ); + Assert.assertTrue( result.isSubscript() ); + Assert.assertTrue( result.isSuperscript() ); + Assert.assertEquals( TextAlignment.Inherit, result.getTextAlignment() ); + Assert.assertEquals( color, result.getColor() ); + Assert.assertEquals( "b", result.getStyleName() ); + } +} \ No newline at end of file