poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ser...@apache.org
Subject svn commit: r1155357 - in /poi/trunk/src/scratchpad/src/org/apache/poi: hssf/converter/ExcelToHtmlConverter.java hwpf/converter/HtmlDocumentFacade.java hwpf/converter/WordToHtmlConverter.java
Date Tue, 09 Aug 2011 13:25:57 GMT
Author: sergey
Date: Tue Aug  9 13:25:56 2011
New Revision: 1155357

URL: http://svn.apache.org/viewvc?rev=1155357&view=rev
Log:
simplify HTML CSS creation code

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/HtmlDocumentFacade.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java?rev=1155357&r1=1155356&r2=1155357&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java Tue
Aug  9 13:25:56 2011
@@ -524,11 +524,8 @@ public class ExcelToHtmlConverter
             innerDivStyle.append( "pt;white-space:nowrap;" );
             ExcelToHtmlUtils.appendAlign( innerDivStyle,
                     cellStyle.getAlignment() );
-            innerDiv.setAttribute(
-                    "class",
-                    htmlDocumentFacade.getOrCreateCssClass(
-                            outerDiv.getTagName(), "d",
-                            innerDivStyle.toString() ) );
+            htmlDocumentFacade.addStyleClass( outerDiv, "d",
+                    innerDivStyle.toString() );
 
             innerDiv.appendChild( text );
             outerDiv.appendChild( innerDiv );
@@ -761,11 +758,8 @@ public class ExcelToHtmlConverter
                 continue;
 
             Element tableRowElement = htmlDocumentFacade.createTableRow();
-            tableRowElement.setAttribute(
-                    "class",
-                    htmlDocumentFacade.getOrCreateCssClass(
-                            tableRowElement.getTagName(), "r", "height:"
-                                    + ( row.getHeight() / 20f ) + "pt;" ) );
+            htmlDocumentFacade.addStyleClass( tableRowElement, "r", "height:"
+                    + ( row.getHeight() / 20f ) + "pt;" );
 
             int maxRowColumnNumber = processRow( mergedRanges, row,
                     tableRowElement );

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/HtmlDocumentFacade.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/HtmlDocumentFacade.java?rev=1155357&r1=1155356&r2=1155357&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/HtmlDocumentFacade.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/HtmlDocumentFacade.java Tue
Aug  9 13:25:56 2011
@@ -57,10 +57,7 @@ public class HtmlDocumentFacade
         html.appendChild( body );
         head.appendChild( stylesheetElement );
 
-        body.setAttribute(
-                "class",
-                getOrCreateCssClass( "body", "b",
-                        "white-space-collapsing: preserve; " ) );
+        addStyleClass( body, "b", "white-space-collapsing:preserve;" );
     }
 
     public void addAuthor( String value )
@@ -86,6 +83,17 @@ public class HtmlDocumentFacade
         head.appendChild( meta );
     }
 
+    public void addStyleClass( Element element, String classNamePrefix,
+            String style )
+    {
+        String exising = element.getAttribute( "class" );
+        String addition = getOrCreateCssClass( element.getTagName(),
+                classNamePrefix, style );
+        String newClassValue = WordToHtmlUtils.isEmpty( exising ) ? addition
+                : ( exising + " " + addition );
+        element.setAttribute( "class", newClassValue );
+    }
+
     public Element createBlock()
     {
         return document.createElement( "div" );

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java?rev=1155357&r1=1155356&r2=1155357&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java Tue
Aug  9 13:25:56 2011
@@ -217,8 +217,7 @@ public class WordToHtmlConverter extends
 
         WordToHtmlUtils.addCharactersProperties( characterRun, style );
         if ( style.length() != 0 )
-            span.setAttribute( "class", htmlDocumentFacade.getOrCreateCssClass(
-                    span.getTagName(), "s", style.toString() ) );
+            htmlDocumentFacade.addStyleClass( span, "s", style.toString() );
 
         Text textNode = htmlDocumentFacade.createText( text );
         span.appendChild( textNode );
@@ -405,26 +404,22 @@ public class WordToHtmlConverter extends
                     - cropBottom );
 
             root = htmlDocumentFacade.createBlock();
-            root.setAttribute( "class", htmlDocumentFacade.getOrCreateCssClass(
-                    root.getTagName(), "d", "vertical-align:text-bottom;width:"
-                            + visibleWidth + "in;height:" + visibleHeight
-                            + "in;" ) );
+            htmlDocumentFacade.addStyleClass( root, "d",
+                    "vertical-align:text-bottom;width:" + visibleWidth
+                            + "in;height:" + visibleHeight + "in;" );
 
             // complex
             Element inner = htmlDocumentFacade.createBlock();
-            inner.setAttribute( "class", htmlDocumentFacade
-                    .getOrCreateCssClass( inner.getTagName(), "d",
-                            "position:relative;width:" + visibleWidth
-                                    + "in;height:" + visibleHeight
-                                    + "in;overflow:hidden;" ) );
+            htmlDocumentFacade.addStyleClass( inner, "d",
+                    "position:relative;width:" + visibleWidth + "in;height:"
+                            + visibleHeight + "in;overflow:hidden;" );
             root.appendChild( inner );
 
             Element image = htmlDocumentFacade.createImage( imageSourcePath );
-            image.setAttribute( "class", htmlDocumentFacade
-                    .getOrCreateCssClass( image.getTagName(), "i",
-                            "position:absolute;left:-" + cropLeft + ";top:-"
-                                    + cropTop + ";width:" + imageWidth
-                                    + "in;height:" + imageHeight + "in;" ) );
+            htmlDocumentFacade.addStyleClass( image, "i",
+                    "position:absolute;left:-" + cropLeft + ";top:-" + cropTop
+                            + ";width:" + imageWidth + "in;height:"
+                            + imageHeight + "in;" );
             inner.appendChild( image );
 
             style.append( "overflow:hidden;" );
@@ -560,10 +555,7 @@ public class WordToHtmlConverter extends
         }
 
         if ( style.length() > 0 )
-            pElement.setAttribute(
-                    "class",
-                    htmlDocumentFacade.getOrCreateCssClass(
-                            pElement.getTagName(), "p", style.toString() ) );
+            htmlDocumentFacade.addStyleClass( pElement, "p", style.toString() );
 
         WordToHtmlUtils.compactSpans( pElement );
         return;
@@ -573,8 +565,7 @@ public class WordToHtmlConverter extends
             Section section, int sectionCounter )
     {
         Element div = htmlDocumentFacade.createBlock();
-        div.setAttribute( "class", htmlDocumentFacade.getOrCreateCssClass(
-                div.getTagName(), "d", getSectionStyle( section ) ) );
+        htmlDocumentFacade.addStyleClass( div, "d", getSectionStyle( section ) );
         htmlDocumentFacade.body.appendChild( div );
 
         processParagraphes( wordDocument, div, section, Integer.MIN_VALUE );
@@ -584,9 +575,8 @@ public class WordToHtmlConverter extends
     protected void processSingleSection( HWPFDocumentCore wordDocument,
             Section section )
     {
-        htmlDocumentFacade.body
-                .setAttribute( "class", htmlDocumentFacade.getOrCreateCssClass(
-                        "body", "b", getSectionStyle( section ) ) );
+        htmlDocumentFacade.addStyleClass( htmlDocumentFacade.body, "b",
+                getSectionStyle( section ) );
 
         processParagraphes( wordDocument, htmlDocumentFacade.body, section,
                 Integer.MIN_VALUE );
@@ -672,11 +662,9 @@ public class WordToHtmlConverter extends
                             .createParagraph() );
                 }
                 if ( tableCellStyle.length() > 0 )
-                    tableCellElement.setAttribute( "class", htmlDocumentFacade
-                            .getOrCreateCssClass(
-                                    tableCellElement.getTagName(),
-                                    tableCellElement.getTagName(),
-                                    tableCellStyle.toString() ) );
+                    htmlDocumentFacade.addStyleClass( tableCellElement,
+                            tableCellElement.getTagName(),
+                            tableCellStyle.toString() );
 
                 tableRowElement.appendChild( tableCellElement );
             }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message