diff options
author | Sergey Vladimirov <sergey@apache.org> | 2011-09-13 11:10:23 +0000 |
---|---|---|
committer | Sergey Vladimirov <sergey@apache.org> | 2011-09-13 11:10:23 +0000 |
commit | 9434b9ba3fa2ac2bc0a4c2393c4881bfb2ef9480 (patch) | |
tree | 8bb50fdbb089cba42c1389caa6a72784ef70fb39 | |
parent | 936bf2f9b35abc7e54945f163745a594e32d9a57 (diff) | |
download | poi-9434b9ba3fa2ac2bc0a4c2393c4881bfb2ef9480.tar.gz poi-9434b9ba3fa2ac2bc0a4c2393c4881bfb2ef9480.zip |
generate CSS without tag names
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1170116 13f79535-47bb-0310-9956-ffa450edef68
3 files changed, 16 insertions, 26 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java index 946770fd00..e5ce39719f 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java +++ b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java @@ -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++ ) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/HtmlDocumentFacade.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/HtmlDocumentFacade.java index 6218210bf0..7c28c36865 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/HtmlDocumentFacade.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/HtmlDocumentFacade.java @@ -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() ); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java index c33776495f..3b4f4c5525 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java @@ -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 ); |