]> source.dussan.org Git - poi.git/commitdiff
generate CSS without tag names
authorSergey Vladimirov <sergey@apache.org>
Tue, 13 Sep 2011 11:10:23 +0000 (11:10 +0000)
committerSergey Vladimirov <sergey@apache.org>
Tue, 13 Sep 2011 11:10:23 +0000 (11:10 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1170116 13f79535-47bb-0310-9956-ffa450edef68

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

index 946770fd00ae5f3a98fa86a9adef445087fddc7b..e5ce39719f1f496b264c9a188ab82f8bad3bc4df 100644 (file)
@@ -136,8 +136,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
     public ExcelToHtmlConverter( Document doc )
     {
         htmlDocumentFacade = new HtmlDocumentFacade( doc );
-        cssClassTable = htmlDocumentFacade.getOrCreateCssClass( "table", "t",
-                "border-collapse:collapse;border-spacing:0;" );
+        cssClassTable = htmlDocumentFacade.getOrCreateCssClass( "t", "border-collapse:collapse;border-spacing:0;" );
     }
 
     protected String buildStyle( HSSFWorkbook workbook, HSSFCellStyle cellStyle )
@@ -249,8 +248,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
             return knownClass;
 
         String cssStyle = buildStyle( workbook, cellStyle );
-        String cssClass = htmlDocumentFacade.getOrCreateCssClass( "td", "c",
-                cssStyle );
+        String cssClass = htmlDocumentFacade.getOrCreateCssClass( "c", cssStyle );
         excelStyleToClass.put( cellStyleKey, cssClass );
         return cssClass;
     }
@@ -693,10 +691,9 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
         {
             // prepare CSS classes for later usage
             this.cssClassContainerCell = htmlDocumentFacade
-                    .getOrCreateCssClass( "td", "c",
-                            "padding:0;margin:0;align:left;vertical-align:top;" );
+                    .getOrCreateCssClass( "c", "padding:0;margin:0;align:left;vertical-align:top;" );
             this.cssClassContainerDiv = htmlDocumentFacade.getOrCreateCssClass(
-                    "div", "d", "position:relative;" );
+                    "d", "position:relative;" );
         }
 
         for ( int s = 0; s < workbook.getNumberOfSheets(); s++ )
index 6218210bf03d82adb649d9464ed8d21e4ac11141..7c28c368658d72c5f0baf7edfc18f4f39877851c 100644 (file)
@@ -87,8 +87,7 @@ public class HtmlDocumentFacade
             String style )
     {
         String exising = element.getAttribute( "class" );
-        String addition = getOrCreateCssClass( element.getTagName(),
-                classNamePrefix, style );
+        String addition = getOrCreateCssClass( classNamePrefix, style );
         String newClassValue = WordToHtmlUtils.isEmpty( exising ) ? addition
                 : ( exising + " " + addition );
         element.setAttribute( "class", newClassValue );
@@ -210,13 +209,13 @@ public class HtmlDocumentFacade
         return head;
     }
 
-    public String getOrCreateCssClass( String tagName, String classNamePrefix,
-            String style )
+    public String getOrCreateCssClass( String classNamePrefix, String style )
     {
-        if ( !stylesheet.containsKey( tagName ) )
-            stylesheet.put( tagName, new LinkedHashMap<String, String>( 1 ) );
+        if ( !stylesheet.containsKey( classNamePrefix ) )
+            stylesheet.put( classNamePrefix, new LinkedHashMap<String, String>(
+                    1 ) );
 
-        Map<String, String> styleToClassName = stylesheet.get( tagName );
+        Map<String, String> styleToClassName = stylesheet.get( classNamePrefix );
         String knownClass = styleToClassName.get( style );
         if ( knownClass != null )
             return knownClass;
@@ -257,18 +256,14 @@ public class HtmlDocumentFacade
     public void updateStylesheet()
     {
         StringBuilder stringBuilder = new StringBuilder();
-        for ( Map.Entry<String, Map<String, String>> byTag : stylesheet
-                .entrySet() )
+        for ( Map<String, String> byPrefix : stylesheet.values() )
         {
-            String tagName = byTag.getKey();
-            for ( Map.Entry<String, String> byStyle : byTag.getValue()
-                    .entrySet() )
+            for ( Map.Entry<String, String> byStyle : byPrefix.entrySet() )
             {
                 String style = byStyle.getKey();
                 String className = byStyle.getValue();
 
-                stringBuilder.append( tagName + "." + className + "{" + style
-                        + "}\n" );
+                stringBuilder.append( "." + className + "{" + style + "}\n" );
             }
         }
         stylesheetElement.setTextContent( stringBuilder.toString() );
index c33776495f4301e63cd0b091c556b4e6b4f30a76..3b4f4c55253b43586172bcb62a636826c785c45e 100644 (file)
@@ -450,7 +450,7 @@ public class WordToHtmlConverter extends AbstractWordConverter
     {
         final String textIndex = String.valueOf( noteIndex + 1 );
         final String textIndexClass = htmlDocumentFacade.getOrCreateCssClass(
-                "a", "a", "vertical-align:super;font-size:smaller;" );
+                "a", "vertical-align:super;font-size:smaller;" );
         final String forwardNoteLink = type + "note_" + textIndex;
         final String backwardNoteLink = type + "note_back_" + textIndex;
 
@@ -682,8 +682,7 @@ public class WordToHtmlConverter extends AbstractWordConverter
 
             if ( tableRowStyle.length() > 0 )
                 tableRowElement.setAttribute( "class", htmlDocumentFacade
-                        .getOrCreateCssClass( "tr", "r",
-                                tableRowStyle.toString() ) );
+                        .getOrCreateCssClass( "r", tableRowStyle.toString() ) );
 
             if ( tableRow.isTableHeader() )
             {
@@ -700,8 +699,7 @@ public class WordToHtmlConverter extends AbstractWordConverter
                 .setAttribute(
                         "class",
                         htmlDocumentFacade.getOrCreateCssClass(
-                                tableElement.getTagName(), "t",
-                                "table-layout:fixed;border-collapse:collapse;border-spacing:0;" ) );
+                                "t", "table-layout:fixed;border-collapse:collapse;border-spacing:0;" ) );
         if ( tableHeader.hasChildNodes() )
         {
             tableElement.appendChild( tableHeader );