simplify HTML CSS creation code
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1155357 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
73bfd88166
commit
339e6e29fa
@ -524,11 +524,8 @@ public class ExcelToHtmlConverter
|
|||||||
innerDivStyle.append( "pt;white-space:nowrap;" );
|
innerDivStyle.append( "pt;white-space:nowrap;" );
|
||||||
ExcelToHtmlUtils.appendAlign( innerDivStyle,
|
ExcelToHtmlUtils.appendAlign( innerDivStyle,
|
||||||
cellStyle.getAlignment() );
|
cellStyle.getAlignment() );
|
||||||
innerDiv.setAttribute(
|
htmlDocumentFacade.addStyleClass( outerDiv, "d",
|
||||||
"class",
|
innerDivStyle.toString() );
|
||||||
htmlDocumentFacade.getOrCreateCssClass(
|
|
||||||
outerDiv.getTagName(), "d",
|
|
||||||
innerDivStyle.toString() ) );
|
|
||||||
|
|
||||||
innerDiv.appendChild( text );
|
innerDiv.appendChild( text );
|
||||||
outerDiv.appendChild( innerDiv );
|
outerDiv.appendChild( innerDiv );
|
||||||
@ -761,11 +758,8 @@ public class ExcelToHtmlConverter
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
Element tableRowElement = htmlDocumentFacade.createTableRow();
|
Element tableRowElement = htmlDocumentFacade.createTableRow();
|
||||||
tableRowElement.setAttribute(
|
htmlDocumentFacade.addStyleClass( tableRowElement, "r", "height:"
|
||||||
"class",
|
+ ( row.getHeight() / 20f ) + "pt;" );
|
||||||
htmlDocumentFacade.getOrCreateCssClass(
|
|
||||||
tableRowElement.getTagName(), "r", "height:"
|
|
||||||
+ ( row.getHeight() / 20f ) + "pt;" ) );
|
|
||||||
|
|
||||||
int maxRowColumnNumber = processRow( mergedRanges, row,
|
int maxRowColumnNumber = processRow( mergedRanges, row,
|
||||||
tableRowElement );
|
tableRowElement );
|
||||||
|
@ -57,10 +57,7 @@ public class HtmlDocumentFacade
|
|||||||
html.appendChild( body );
|
html.appendChild( body );
|
||||||
head.appendChild( stylesheetElement );
|
head.appendChild( stylesheetElement );
|
||||||
|
|
||||||
body.setAttribute(
|
addStyleClass( body, "b", "white-space-collapsing:preserve;" );
|
||||||
"class",
|
|
||||||
getOrCreateCssClass( "body", "b",
|
|
||||||
"white-space-collapsing: preserve; " ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAuthor( String value )
|
public void addAuthor( String value )
|
||||||
@ -86,6 +83,17 @@ public class HtmlDocumentFacade
|
|||||||
head.appendChild( meta );
|
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()
|
public Element createBlock()
|
||||||
{
|
{
|
||||||
return document.createElement( "div" );
|
return document.createElement( "div" );
|
||||||
|
@ -217,8 +217,7 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
|||||||
|
|
||||||
WordToHtmlUtils.addCharactersProperties( characterRun, style );
|
WordToHtmlUtils.addCharactersProperties( characterRun, style );
|
||||||
if ( style.length() != 0 )
|
if ( style.length() != 0 )
|
||||||
span.setAttribute( "class", htmlDocumentFacade.getOrCreateCssClass(
|
htmlDocumentFacade.addStyleClass( span, "s", style.toString() );
|
||||||
span.getTagName(), "s", style.toString() ) );
|
|
||||||
|
|
||||||
Text textNode = htmlDocumentFacade.createText( text );
|
Text textNode = htmlDocumentFacade.createText( text );
|
||||||
span.appendChild( textNode );
|
span.appendChild( textNode );
|
||||||
@ -405,26 +404,22 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
|||||||
- cropBottom );
|
- cropBottom );
|
||||||
|
|
||||||
root = htmlDocumentFacade.createBlock();
|
root = htmlDocumentFacade.createBlock();
|
||||||
root.setAttribute( "class", htmlDocumentFacade.getOrCreateCssClass(
|
htmlDocumentFacade.addStyleClass( root, "d",
|
||||||
root.getTagName(), "d", "vertical-align:text-bottom;width:"
|
"vertical-align:text-bottom;width:" + visibleWidth
|
||||||
+ visibleWidth + "in;height:" + visibleHeight
|
+ "in;height:" + visibleHeight + "in;" );
|
||||||
+ "in;" ) );
|
|
||||||
|
|
||||||
// complex
|
// complex
|
||||||
Element inner = htmlDocumentFacade.createBlock();
|
Element inner = htmlDocumentFacade.createBlock();
|
||||||
inner.setAttribute( "class", htmlDocumentFacade
|
htmlDocumentFacade.addStyleClass( inner, "d",
|
||||||
.getOrCreateCssClass( inner.getTagName(), "d",
|
"position:relative;width:" + visibleWidth + "in;height:"
|
||||||
"position:relative;width:" + visibleWidth
|
+ visibleHeight + "in;overflow:hidden;" );
|
||||||
+ "in;height:" + visibleHeight
|
|
||||||
+ "in;overflow:hidden;" ) );
|
|
||||||
root.appendChild( inner );
|
root.appendChild( inner );
|
||||||
|
|
||||||
Element image = htmlDocumentFacade.createImage( imageSourcePath );
|
Element image = htmlDocumentFacade.createImage( imageSourcePath );
|
||||||
image.setAttribute( "class", htmlDocumentFacade
|
htmlDocumentFacade.addStyleClass( image, "i",
|
||||||
.getOrCreateCssClass( image.getTagName(), "i",
|
"position:absolute;left:-" + cropLeft + ";top:-" + cropTop
|
||||||
"position:absolute;left:-" + cropLeft + ";top:-"
|
+ ";width:" + imageWidth + "in;height:"
|
||||||
+ cropTop + ";width:" + imageWidth
|
+ imageHeight + "in;" );
|
||||||
+ "in;height:" + imageHeight + "in;" ) );
|
|
||||||
inner.appendChild( image );
|
inner.appendChild( image );
|
||||||
|
|
||||||
style.append( "overflow:hidden;" );
|
style.append( "overflow:hidden;" );
|
||||||
@ -560,10 +555,7 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( style.length() > 0 )
|
if ( style.length() > 0 )
|
||||||
pElement.setAttribute(
|
htmlDocumentFacade.addStyleClass( pElement, "p", style.toString() );
|
||||||
"class",
|
|
||||||
htmlDocumentFacade.getOrCreateCssClass(
|
|
||||||
pElement.getTagName(), "p", style.toString() ) );
|
|
||||||
|
|
||||||
WordToHtmlUtils.compactSpans( pElement );
|
WordToHtmlUtils.compactSpans( pElement );
|
||||||
return;
|
return;
|
||||||
@ -573,8 +565,7 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
|||||||
Section section, int sectionCounter )
|
Section section, int sectionCounter )
|
||||||
{
|
{
|
||||||
Element div = htmlDocumentFacade.createBlock();
|
Element div = htmlDocumentFacade.createBlock();
|
||||||
div.setAttribute( "class", htmlDocumentFacade.getOrCreateCssClass(
|
htmlDocumentFacade.addStyleClass( div, "d", getSectionStyle( section ) );
|
||||||
div.getTagName(), "d", getSectionStyle( section ) ) );
|
|
||||||
htmlDocumentFacade.body.appendChild( div );
|
htmlDocumentFacade.body.appendChild( div );
|
||||||
|
|
||||||
processParagraphes( wordDocument, div, section, Integer.MIN_VALUE );
|
processParagraphes( wordDocument, div, section, Integer.MIN_VALUE );
|
||||||
@ -584,9 +575,8 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
|||||||
protected void processSingleSection( HWPFDocumentCore wordDocument,
|
protected void processSingleSection( HWPFDocumentCore wordDocument,
|
||||||
Section section )
|
Section section )
|
||||||
{
|
{
|
||||||
htmlDocumentFacade.body
|
htmlDocumentFacade.addStyleClass( htmlDocumentFacade.body, "b",
|
||||||
.setAttribute( "class", htmlDocumentFacade.getOrCreateCssClass(
|
getSectionStyle( section ) );
|
||||||
"body", "b", getSectionStyle( section ) ) );
|
|
||||||
|
|
||||||
processParagraphes( wordDocument, htmlDocumentFacade.body, section,
|
processParagraphes( wordDocument, htmlDocumentFacade.body, section,
|
||||||
Integer.MIN_VALUE );
|
Integer.MIN_VALUE );
|
||||||
@ -672,11 +662,9 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
|||||||
.createParagraph() );
|
.createParagraph() );
|
||||||
}
|
}
|
||||||
if ( tableCellStyle.length() > 0 )
|
if ( tableCellStyle.length() > 0 )
|
||||||
tableCellElement.setAttribute( "class", htmlDocumentFacade
|
htmlDocumentFacade.addStyleClass( tableCellElement,
|
||||||
.getOrCreateCssClass(
|
tableCellElement.getTagName(),
|
||||||
tableCellElement.getTagName(),
|
tableCellStyle.toString() );
|
||||||
tableCellElement.getTagName(),
|
|
||||||
tableCellStyle.toString() ) );
|
|
||||||
|
|
||||||
tableRowElement.appendChild( tableCellElement );
|
tableRowElement.appendChild( tableCellElement );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user