generate CSS without tag names

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1170116 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sergey Vladimirov 2011-09-13 11:10:23 +00:00
parent 7b475e643d
commit 57f40b0e3f
3 changed files with 16 additions and 26 deletions

View 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++ )

View 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() );

View 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 );