SonarQube fixes and removed redundant logger level checks, for simple String messages
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1782548 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ea2eb34f46
commit
db3000b142
File diff suppressed because it is too large
Load Diff
@ -19,11 +19,15 @@ package org.apache.poi.hwpf.converter;
|
||||
import static org.apache.poi.hwpf.converter.AbstractWordUtils.TWIPS_PER_INCH;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
@ -56,8 +60,6 @@ import org.w3c.dom.Text;
|
||||
* This implementation doesn't create images or links to them. This can be
|
||||
* changed by overriding {@link #processImage(Element, boolean, Picture)}
|
||||
* method.
|
||||
*
|
||||
* @author Sergey Vladimirov (vlsergey {at} gmail {dot} com)
|
||||
*/
|
||||
@Beta
|
||||
public class WordToHtmlConverter extends AbstractWordConverter
|
||||
@ -78,9 +80,27 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
}
|
||||
}
|
||||
|
||||
private static final POILogger logger = POILogFactory
|
||||
.getLogger( WordToHtmlConverter.class );
|
||||
private static final POILogger logger = POILogFactory.getLogger( WordToHtmlConverter.class );
|
||||
|
||||
private final Deque<BlockProperies> blocksProperies = new LinkedList<BlockProperies>();
|
||||
|
||||
private final HtmlDocumentFacade htmlDocumentFacade;
|
||||
|
||||
private Element notes;
|
||||
|
||||
/**
|
||||
* Creates new instance of {@link WordToHtmlConverter}. Can be used for
|
||||
* output several {@link HWPFDocument}s into single HTML document.
|
||||
*
|
||||
* @param document XML DOM Document used as HTML document
|
||||
*/
|
||||
public WordToHtmlConverter( Document document ) {
|
||||
this.htmlDocumentFacade = new HtmlDocumentFacade( document );
|
||||
}
|
||||
|
||||
public WordToHtmlConverter( HtmlDocumentFacade htmlDocumentFacade ) {
|
||||
this.htmlDocumentFacade = htmlDocumentFacade;
|
||||
}
|
||||
|
||||
private static String getSectionStyle( Section section )
|
||||
{
|
||||
@ -110,20 +130,17 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
}
|
||||
|
||||
/**
|
||||
* Java main() interface to interact with {@link WordToHtmlConverter}
|
||||
* Java main() interface to interact with {@link WordToHtmlConverter}<p>
|
||||
*
|
||||
* Usage: WordToHtmlConverter infile outfile<p>
|
||||
*
|
||||
* <p>
|
||||
* Usage: WordToHtmlConverter infile outfile
|
||||
* </p>
|
||||
* Where infile is an input .doc file ( Word 95-2007) which will be rendered
|
||||
* as HTML into outfile
|
||||
*/
|
||||
public static void main( String[] args ) throws Exception
|
||||
{
|
||||
if ( args.length < 2 )
|
||||
{
|
||||
System.err
|
||||
.println( "Usage: WordToHtmlConverter <inputFile.doc> <saveTo.html>" );
|
||||
public static void main( String[] args )
|
||||
throws IOException, ParserConfigurationException, TransformerException {
|
||||
if ( args.length < 2 ) {
|
||||
System.err.println( "Usage: WordToHtmlConverter <inputFile.doc> <saveTo.html>" );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -144,9 +161,9 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
serializer.transform( domSource, streamResult );
|
||||
}
|
||||
|
||||
static Document process( File docFile ) throws Exception
|
||||
static Document process( File docFile ) throws IOException, ParserConfigurationException
|
||||
{
|
||||
final HWPFDocumentCore wordDocument = WordToHtmlUtils.loadDoc( docFile );
|
||||
final HWPFDocumentCore wordDocument = AbstractWordUtils.loadDoc( docFile );
|
||||
WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(
|
||||
XMLHelper.getDocumentBuilderFactory().newDocumentBuilder()
|
||||
.newDocument() );
|
||||
@ -154,38 +171,17 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
return wordToHtmlConverter.getDocument();
|
||||
}
|
||||
|
||||
private final Stack<BlockProperies> blocksProperies = new Stack<BlockProperies>();
|
||||
|
||||
private final HtmlDocumentFacade htmlDocumentFacade;
|
||||
|
||||
private Element notes;
|
||||
|
||||
/**
|
||||
* Creates new instance of {@link WordToHtmlConverter}. Can be used for
|
||||
* output several {@link HWPFDocument}s into single HTML document.
|
||||
*
|
||||
* @param document
|
||||
* XML DOM Document used as HTML document
|
||||
*/
|
||||
public WordToHtmlConverter( Document document )
|
||||
{
|
||||
this.htmlDocumentFacade = new HtmlDocumentFacade( document );
|
||||
}
|
||||
|
||||
public WordToHtmlConverter( HtmlDocumentFacade htmlDocumentFacade )
|
||||
{
|
||||
this.htmlDocumentFacade = htmlDocumentFacade;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterProcess()
|
||||
{
|
||||
if ( notes != null )
|
||||
if ( notes != null ) {
|
||||
htmlDocumentFacade.getBody().appendChild( notes );
|
||||
}
|
||||
|
||||
htmlDocumentFacade.updateStylesheet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document getDocument()
|
||||
{
|
||||
return htmlDocumentFacade.getDocument();
|
||||
@ -202,8 +198,8 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
BlockProperies blockProperies = this.blocksProperies.peek();
|
||||
Triplet triplet = getCharacterRunTriplet( characterRun );
|
||||
|
||||
if ( WordToHtmlUtils.isNotEmpty( triplet.fontName )
|
||||
&& !WordToHtmlUtils.equals( triplet.fontName,
|
||||
if ( AbstractWordUtils.isNotEmpty( triplet.fontName )
|
||||
&& !AbstractWordUtils.equals( triplet.fontName,
|
||||
blockProperies.pFontName ) )
|
||||
{
|
||||
style.append( "font-family:" + triplet.fontName + ";" );
|
||||
@ -222,8 +218,9 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
}
|
||||
|
||||
WordToHtmlUtils.addCharactersProperties( characterRun, style );
|
||||
if ( style.length() != 0 )
|
||||
if ( style.length() != 0 ) {
|
||||
htmlDocumentFacade.addStyleClass( span, "s", style.toString() );
|
||||
}
|
||||
|
||||
Text textNode = htmlDocumentFacade.createText( text );
|
||||
span.appendChild( textNode );
|
||||
@ -243,27 +240,32 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
parent = bookmarkElement;
|
||||
}
|
||||
|
||||
if ( range != null )
|
||||
if ( range != null ) {
|
||||
processCharacters( wordDocument, currentTableLevel, range, parent );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processDocumentInformation(
|
||||
SummaryInformation summaryInformation )
|
||||
{
|
||||
if ( WordToHtmlUtils.isNotEmpty( summaryInformation.getTitle() ) )
|
||||
if ( AbstractWordUtils.isNotEmpty( summaryInformation.getTitle() ) ) {
|
||||
htmlDocumentFacade.setTitle( summaryInformation.getTitle() );
|
||||
}
|
||||
|
||||
if ( WordToHtmlUtils.isNotEmpty( summaryInformation.getAuthor() ) )
|
||||
if ( AbstractWordUtils.isNotEmpty( summaryInformation.getAuthor() ) ) {
|
||||
htmlDocumentFacade.addAuthor( summaryInformation.getAuthor() );
|
||||
}
|
||||
|
||||
if ( WordToHtmlUtils.isNotEmpty( summaryInformation.getKeywords() ) )
|
||||
if ( AbstractWordUtils.isNotEmpty( summaryInformation.getKeywords() ) ) {
|
||||
htmlDocumentFacade.addKeywords( summaryInformation.getKeywords() );
|
||||
}
|
||||
|
||||
if ( WordToHtmlUtils.isNotEmpty( summaryInformation.getComments() ) )
|
||||
if ( AbstractWordUtils.isNotEmpty( summaryInformation.getComments() ) ) {
|
||||
htmlDocumentFacade
|
||||
.addDescription( summaryInformation.getComments() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processDocumentPart( HWPFDocumentCore wordDocument, Range range )
|
||||
@ -318,11 +320,13 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
Element basicLink = htmlDocumentFacade.createHyperlink( hyperlink );
|
||||
currentBlock.appendChild( basicLink );
|
||||
|
||||
if ( textRange != null )
|
||||
if ( textRange != null ) {
|
||||
processCharacters( wordDocument, currentTableLevel, textRange,
|
||||
basicLink );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processImage( Element currentBlock, boolean inlined,
|
||||
Picture picture, String imageSourcePath )
|
||||
{
|
||||
@ -372,7 +376,7 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
}
|
||||
|
||||
Element root;
|
||||
if ( cropTop != 0 || cropRight != 0 || cropBottom != 0 || cropLeft != 0 )
|
||||
if ( Math.abs(cropTop)+Math.abs(cropRight)+Math.abs(cropBottom)+Math.abs(cropLeft) > 0 )
|
||||
{
|
||||
float visibleWidth = Math
|
||||
.max( 0, imageWidth - cropLeft - cropRight );
|
||||
@ -482,6 +486,7 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
flow.appendChild( htmlDocumentFacade.createLineBreak() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processPageref( HWPFDocumentCore hwpfDocument,
|
||||
Element currentBlock, Range textRange, int currentTableLevel,
|
||||
String pageref )
|
||||
@ -489,11 +494,13 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
Element basicLink = htmlDocumentFacade.createHyperlink( "#" + pageref );
|
||||
currentBlock.appendChild( basicLink );
|
||||
|
||||
if ( textRange != null )
|
||||
if ( textRange != null ) {
|
||||
processCharacters( hwpfDocument, currentTableLevel, textRange,
|
||||
basicLink );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processParagraph( HWPFDocumentCore hwpfDocument,
|
||||
Element parentElement, int currentTableLevel, Paragraph paragraph,
|
||||
String bulletText )
|
||||
@ -526,13 +533,13 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
else
|
||||
{
|
||||
pFontSize = -1;
|
||||
pFontName = WordToHtmlUtils.EMPTY;
|
||||
pFontName = AbstractWordUtils.EMPTY;
|
||||
}
|
||||
blocksProperies.push( new BlockProperies( pFontName, pFontSize ) );
|
||||
}
|
||||
try
|
||||
{
|
||||
if ( WordToHtmlUtils.isNotEmpty( bulletText ) )
|
||||
if ( AbstractWordUtils.isNotEmpty( bulletText ) )
|
||||
{
|
||||
if ( bulletText.endsWith( "\t" ) )
|
||||
{
|
||||
@ -581,13 +588,15 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
blocksProperies.pop();
|
||||
}
|
||||
|
||||
if ( style.length() > 0 )
|
||||
if ( style.length() > 0 ) {
|
||||
htmlDocumentFacade.addStyleClass( pElement, "p", style.toString() );
|
||||
}
|
||||
|
||||
WordToHtmlUtils.compactSpans( pElement );
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processSection( HWPFDocumentCore wordDocument,
|
||||
Section section, int sectionCounter )
|
||||
{
|
||||
@ -609,13 +618,14 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
Integer.MIN_VALUE );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processTable( HWPFDocumentCore hwpfDocument, Element flow,
|
||||
Table table )
|
||||
{
|
||||
Element tableHeader = htmlDocumentFacade.createTableHeader();
|
||||
Element tableBody = htmlDocumentFacade.createTableBody();
|
||||
|
||||
final int[] tableCellEdges = WordToHtmlUtils
|
||||
final int[] tableCellEdges = AbstractWordUtils
|
||||
.buildTableCellEdgesArray( table );
|
||||
final int tableRows = table.numRows();
|
||||
|
||||
@ -667,18 +677,21 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
currentEdgeIndex, tableCell );
|
||||
currentEdgeIndex += colSpan;
|
||||
|
||||
if ( colSpan == 0 )
|
||||
if ( colSpan == 0 ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( colSpan != 1 )
|
||||
if ( colSpan != 1 ) {
|
||||
tableCellElement.setAttribute( "colspan",
|
||||
String.valueOf( colSpan ) );
|
||||
}
|
||||
|
||||
final int rowSpan = getNumberRowsSpanned( table,
|
||||
tableCellEdges, r, c, tableCell );
|
||||
if ( rowSpan > 1 )
|
||||
if ( rowSpan > 1 ) {
|
||||
tableCellElement.setAttribute( "rowspan",
|
||||
String.valueOf( rowSpan ) );
|
||||
}
|
||||
|
||||
processParagraphes( hwpfDocument, tableCellElement, tableCell,
|
||||
table.getTableLevel() );
|
||||
@ -688,17 +701,19 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
tableCellElement.appendChild( htmlDocumentFacade
|
||||
.createParagraph() );
|
||||
}
|
||||
if ( tableCellStyle.length() > 0 )
|
||||
if ( tableCellStyle.length() > 0 ) {
|
||||
htmlDocumentFacade.addStyleClass( tableCellElement,
|
||||
tableCellElement.getTagName(),
|
||||
tableCellStyle.toString() );
|
||||
}
|
||||
|
||||
tableRowElement.appendChild( tableCellElement );
|
||||
}
|
||||
|
||||
if ( tableRowStyle.length() > 0 )
|
||||
if ( tableRowStyle.length() > 0 ) {
|
||||
tableRowElement.setAttribute( "class", htmlDocumentFacade
|
||||
.getOrCreateCssClass( "r", tableRowStyle.toString() ) );
|
||||
}
|
||||
|
||||
if ( tableRow.isTableHeader() )
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user