mirror of https://github.com/apache/poi.git
rename extractor -> converter and move to converter package
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1142767 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1bee2b0cdb
commit
03035ed09a
|
@ -14,7 +14,7 @@
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.hwpf.extractor;
|
package org.apache.poi.hwpf.converter;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -38,7 +38,7 @@ import org.apache.poi.util.POILogger;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
public abstract class AbstractWordExtractor
|
public abstract class AbstractWordConverter
|
||||||
{
|
{
|
||||||
private static final byte BEL_MARK = 7;
|
private static final byte BEL_MARK = 7;
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ public abstract class AbstractWordExtractor
|
||||||
private static final byte FIELD_SEPARATOR_MARK = 20;
|
private static final byte FIELD_SEPARATOR_MARK = 20;
|
||||||
|
|
||||||
private static final POILogger logger = POILogFactory
|
private static final POILogger logger = POILogFactory
|
||||||
.getLogger( AbstractWordExtractor.class );
|
.getLogger( AbstractWordConverter.class );
|
||||||
|
|
||||||
public abstract Document getDocument();
|
public abstract Document getDocument();
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.hwpf.extractor;
|
package org.apache.poi.hwpf.converter;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
|
@ -14,7 +14,7 @@
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.hwpf.extractor;
|
package org.apache.poi.hwpf.converter;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
|
@ -14,7 +14,7 @@
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.hwpf.extractor;
|
package org.apache.poi.hwpf.converter;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
|
@ -17,24 +17,27 @@
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.poi.hwpf.extractor;
|
package org.apache.poi.hwpf.converter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment me
|
* Comment me
|
||||||
*
|
*
|
||||||
* @author Ryan Ackley
|
* @author Ryan Ackley
|
||||||
*/
|
*/
|
||||||
public final class NumberFormatter {
|
public final class NumberFormatter
|
||||||
|
{
|
||||||
|
|
||||||
private static String[] C_LETTERS = new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i",
|
private static String[] C_LETTERS = new String[] { "a", "b", "c", "d", "e",
|
||||||
"j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "x", "y", "z" };
|
"f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
|
||||||
|
"s", "t", "u", "v", "x", "y", "z" };
|
||||||
|
|
||||||
private static String[] C_ROMAN = new String[] { "i", "ii", "iii", "iv", "v", "vi", "vii",
|
private static String[] C_ROMAN = new String[] { "i", "ii", "iii", "iv",
|
||||||
"viii", "ix", "x", "xi", "xii", "xiii", "xiv", "xv", "xvi", "xvii", "xviii", "xix",
|
"v", "vi", "vii", "viii", "ix", "x", "xi", "xii", "xiii", "xiv",
|
||||||
"xx", "xxi", "xxii", "xxiii", "xxiv", "xxv", "xxvi", "xxvii", "xxviii", "xxix", "xxx",
|
"xv", "xvi", "xvii", "xviii", "xix", "xx", "xxi", "xxii", "xxiii",
|
||||||
"xxxi", "xxxii", "xxxiii", "xxxiv", "xxxv", "xxxvi", "xxxvii", "xxxvii", "xxxviii",
|
"xxiv", "xxv", "xxvi", "xxvii", "xxviii", "xxix", "xxx", "xxxi",
|
||||||
"xxxix", "xl", "xli", "xlii", "xliii", "xliv", "xlv", "xlvi", "xlvii", "xlviii",
|
"xxxii", "xxxiii", "xxxiv", "xxxv", "xxxvi", "xxxvii", "xxxvii",
|
||||||
"xlix", "l" };
|
"xxxviii", "xxxix", "xl", "xli", "xlii", "xliii", "xliv", "xlv",
|
||||||
|
"xlvi", "xlvii", "xlviii", "xlix", "l" };
|
||||||
|
|
||||||
private final static int T_ARABIC = 0;
|
private final static int T_ARABIC = 0;
|
||||||
private final static int T_LOWER_LETTER = 4;
|
private final static int T_LOWER_LETTER = 4;
|
||||||
|
@ -43,8 +46,10 @@ public final class NumberFormatter {
|
||||||
private final static int T_UPPER_LETTER = 3;
|
private final static int T_UPPER_LETTER = 3;
|
||||||
private final static int T_UPPER_ROMAN = 1;
|
private final static int T_UPPER_ROMAN = 1;
|
||||||
|
|
||||||
public static String getNumber(int num, int style) {
|
public static String getNumber( int num, int style )
|
||||||
switch (style) {
|
{
|
||||||
|
switch ( style )
|
||||||
|
{
|
||||||
case T_UPPER_ROMAN:
|
case T_UPPER_ROMAN:
|
||||||
return C_ROMAN[num - 1].toUpperCase();
|
return C_ROMAN[num - 1].toUpperCase();
|
||||||
case T_LOWER_ROMAN:
|
case T_LOWER_ROMAN:
|
||||||
|
@ -56,7 +61,7 @@ public final class NumberFormatter {
|
||||||
case T_ARABIC:
|
case T_ARABIC:
|
||||||
case T_ORDINAL:
|
case T_ORDINAL:
|
||||||
default:
|
default:
|
||||||
return String.valueOf(num);
|
return String.valueOf( num );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.hwpf.extractor;
|
package org.apache.poi.hwpf.converter;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
|
@ -54,7 +54,7 @@ import org.w3c.dom.Text;
|
||||||
/**
|
/**
|
||||||
* @author Sergey Vladimirov (vlsergey {at} gmail {dot} com)
|
* @author Sergey Vladimirov (vlsergey {at} gmail {dot} com)
|
||||||
*/
|
*/
|
||||||
public class WordToFoExtractor extends AbstractWordExtractor
|
public class WordToFoConverter extends AbstractWordConverter
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,7 +80,7 @@ public class WordToFoExtractor extends AbstractWordExtractor
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final POILogger logger = POILogFactory
|
private static final POILogger logger = POILogFactory
|
||||||
.getLogger( WordToFoExtractor.class );
|
.getLogger( WordToFoConverter.class );
|
||||||
|
|
||||||
public static String getBorderType( BorderCode borderCode )
|
public static String getBorderType( BorderCode borderCode )
|
||||||
{
|
{
|
||||||
|
@ -132,21 +132,20 @@ public class WordToFoExtractor extends AbstractWordExtractor
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Java main() interface to interact with WordToFoExtractor
|
* Java main() interface to interact with {@link WordToFoConverter}
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Usage: WordToFoExtractor infile outfile
|
* Usage: WordToFoConverter infile outfile
|
||||||
* </p>
|
* </p>
|
||||||
* Where infile is an input .doc file ( Word 97-2007) which will be rendered
|
* Where infile is an input .doc file ( Word 97-2007) which will be rendered
|
||||||
* as XSL-FO into outfile
|
* as XSL-FO into outfile
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public static void main( String[] args )
|
public static void main( String[] args )
|
||||||
{
|
{
|
||||||
if ( args.length < 2 )
|
if ( args.length < 2 )
|
||||||
{
|
{
|
||||||
System.err
|
System.err
|
||||||
.println( "Usage: WordToFoExtractor <inputFile.doc> <saveTo.fo>" );
|
.println( "Usage: WordToFoConverter <inputFile.doc> <saveTo.fo>" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +153,7 @@ public class WordToFoExtractor extends AbstractWordExtractor
|
||||||
System.out.println( "Saving output to " + args[1] );
|
System.out.println( "Saving output to " + args[1] );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Document doc = WordToFoExtractor.process( new File( args[0] ) );
|
Document doc = WordToFoConverter.process( new File( args[0] ) );
|
||||||
|
|
||||||
FileWriter out = new FileWriter( args[1] );
|
FileWriter out = new FileWriter( args[1] );
|
||||||
DOMSource domSource = new DOMSource( doc );
|
DOMSource domSource = new DOMSource( doc );
|
||||||
|
@ -176,11 +175,11 @@ public class WordToFoExtractor extends AbstractWordExtractor
|
||||||
static Document process( File docFile ) throws Exception
|
static Document process( File docFile ) throws Exception
|
||||||
{
|
{
|
||||||
final HWPFDocumentCore hwpfDocument = WordToFoUtils.loadDoc( docFile );
|
final HWPFDocumentCore hwpfDocument = WordToFoUtils.loadDoc( docFile );
|
||||||
WordToFoExtractor wordToFoExtractor = new WordToFoExtractor(
|
WordToFoConverter wordToFoConverter = new WordToFoConverter(
|
||||||
DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
||||||
.newDocument() );
|
.newDocument() );
|
||||||
wordToFoExtractor.processDocument( hwpfDocument );
|
wordToFoConverter.processDocument( hwpfDocument );
|
||||||
return wordToFoExtractor.getDocument();
|
return wordToFoConverter.getDocument();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Stack<BlockProperies> blocksProperies = new Stack<BlockProperies>();
|
private final Stack<BlockProperies> blocksProperies = new Stack<BlockProperies>();
|
||||||
|
@ -188,14 +187,14 @@ public class WordToFoExtractor extends AbstractWordExtractor
|
||||||
protected final FoDocumentFacade foDocumentFacade;
|
protected final FoDocumentFacade foDocumentFacade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new instance of {@link WordToFoExtractor}. Can be used for output
|
* Creates new instance of {@link WordToFoConverter}. Can be used for output
|
||||||
* several {@link HWPFDocument}s into single FO document.
|
* several {@link HWPFDocument}s into single FO document.
|
||||||
*
|
*
|
||||||
* @param document
|
* @param document
|
||||||
* XML DOM Document used as XSL FO document. Shall support
|
* XML DOM Document used as XSL FO document. Shall support
|
||||||
* namespaces
|
* namespaces
|
||||||
*/
|
*/
|
||||||
public WordToFoExtractor( Document document )
|
public WordToFoConverter( Document document )
|
||||||
{
|
{
|
||||||
this.foDocumentFacade = new FoDocumentFacade( document );
|
this.foDocumentFacade = new FoDocumentFacade( document );
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.hwpf.extractor;
|
package org.apache.poi.hwpf.converter;
|
||||||
|
|
||||||
import org.apache.poi.hwpf.usermodel.BorderCode;
|
import org.apache.poi.hwpf.usermodel.BorderCode;
|
||||||
import org.apache.poi.hwpf.usermodel.CharacterProperties;
|
import org.apache.poi.hwpf.usermodel.CharacterProperties;
|
|
@ -14,7 +14,7 @@
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.hwpf.extractor;
|
package org.apache.poi.hwpf.converter;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
|
@ -44,12 +44,18 @@ import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.Text;
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
import static org.apache.poi.hwpf.extractor.AbstractWordUtils.TWIPS_PER_INCH;
|
import static org.apache.poi.hwpf.converter.AbstractWordUtils.TWIPS_PER_INCH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Converts Word files (95-2007) into HTML files.
|
||||||
|
* <p>
|
||||||
|
* 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)
|
* @author Sergey Vladimirov (vlsergey {at} gmail {dot} com)
|
||||||
*/
|
*/
|
||||||
public class WordToHtmlExtractor extends AbstractWordExtractor
|
public class WordToHtmlConverter extends AbstractWordConverter
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,7 +75,7 @@ public class WordToHtmlExtractor extends AbstractWordExtractor
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final POILogger logger = POILogFactory
|
private static final POILogger logger = POILogFactory
|
||||||
.getLogger( WordToHtmlExtractor.class );
|
.getLogger( WordToHtmlConverter.class );
|
||||||
|
|
||||||
private static String getSectionStyle( Section section )
|
private static String getSectionStyle( Section section )
|
||||||
{
|
{
|
||||||
|
@ -100,10 +106,10 @@ public class WordToHtmlExtractor extends AbstractWordExtractor
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Java main() interface to interact with WordToHtmlExtractor
|
* Java main() interface to interact with {@link WordToHtmlConverter}
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Usage: WordToHtmlExtractor infile outfile
|
* Usage: WordToHtmlConverter infile outfile
|
||||||
* </p>
|
* </p>
|
||||||
* Where infile is an input .doc file ( Word 95-2007) which will be rendered
|
* Where infile is an input .doc file ( Word 95-2007) which will be rendered
|
||||||
* as HTML into outfile
|
* as HTML into outfile
|
||||||
|
@ -113,7 +119,7 @@ public class WordToHtmlExtractor extends AbstractWordExtractor
|
||||||
if ( args.length < 2 )
|
if ( args.length < 2 )
|
||||||
{
|
{
|
||||||
System.err
|
System.err
|
||||||
.println( "Usage: WordToHtmlExtractor <inputFile.doc> <saveTo.html>" );
|
.println( "Usage: WordToHtmlConverter <inputFile.doc> <saveTo.html>" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +127,7 @@ public class WordToHtmlExtractor extends AbstractWordExtractor
|
||||||
System.out.println( "Saving output to " + args[1] );
|
System.out.println( "Saving output to " + args[1] );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Document doc = WordToHtmlExtractor.process( new File( args[0] ) );
|
Document doc = WordToHtmlConverter.process( new File( args[0] ) );
|
||||||
|
|
||||||
FileWriter out = new FileWriter( args[1] );
|
FileWriter out = new FileWriter( args[1] );
|
||||||
DOMSource domSource = new DOMSource( doc );
|
DOMSource domSource = new DOMSource( doc );
|
||||||
|
@ -145,11 +151,11 @@ public class WordToHtmlExtractor extends AbstractWordExtractor
|
||||||
static Document process( File docFile ) throws Exception
|
static Document process( File docFile ) throws Exception
|
||||||
{
|
{
|
||||||
final HWPFDocumentCore wordDocument = WordToHtmlUtils.loadDoc( docFile );
|
final HWPFDocumentCore wordDocument = WordToHtmlUtils.loadDoc( docFile );
|
||||||
WordToHtmlExtractor wordToHtmlExtractor = new WordToHtmlExtractor(
|
WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(
|
||||||
DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
||||||
.newDocument() );
|
.newDocument() );
|
||||||
wordToHtmlExtractor.processDocument( wordDocument );
|
wordToHtmlConverter.processDocument( wordDocument );
|
||||||
return wordToHtmlExtractor.getDocument();
|
return wordToHtmlConverter.getDocument();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Stack<BlockProperies> blocksProperies = new Stack<BlockProperies>();
|
private final Stack<BlockProperies> blocksProperies = new Stack<BlockProperies>();
|
||||||
|
@ -157,13 +163,13 @@ public class WordToHtmlExtractor extends AbstractWordExtractor
|
||||||
private final HtmlDocumentFacade htmlDocumentFacade;
|
private final HtmlDocumentFacade htmlDocumentFacade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new instance of {@link WordToHtmlExtractor}. Can be used for
|
* Creates new instance of {@link WordToHtmlConverter}. Can be used for
|
||||||
* output several {@link HWPFDocument}s into single HTML document.
|
* output several {@link HWPFDocument}s into single HTML document.
|
||||||
*
|
*
|
||||||
* @param document
|
* @param document
|
||||||
* XML DOM Document used as HTML document
|
* XML DOM Document used as HTML document
|
||||||
*/
|
*/
|
||||||
public WordToHtmlExtractor( Document document )
|
public WordToHtmlConverter( Document document )
|
||||||
{
|
{
|
||||||
this.htmlDocumentFacade = new HtmlDocumentFacade( document );
|
this.htmlDocumentFacade = new HtmlDocumentFacade( document );
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.hwpf.extractor;
|
package org.apache.poi.hwpf.converter;
|
||||||
|
|
||||||
import org.apache.poi.hwpf.usermodel.BorderCode;
|
import org.apache.poi.hwpf.usermodel.BorderCode;
|
||||||
import org.apache.poi.hwpf.usermodel.CharacterProperties;
|
import org.apache.poi.hwpf.usermodel.CharacterProperties;
|
|
@ -14,7 +14,7 @@
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.hwpf.extractor;
|
package org.apache.poi.hwpf.converter;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
|
@ -35,7 +35,7 @@ import junit.framework.TestSuite;
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hwpf.HWPFDocumentCore;
|
import org.apache.poi.hwpf.HWPFDocumentCore;
|
||||||
|
|
||||||
public class TestWordToExtractorSuite
|
public class TestWordToConverterSuite
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* YK: a quick hack to exclude failing documents from the suite.
|
* YK: a quick hack to exclude failing documents from the suite.
|
||||||
|
@ -87,14 +87,14 @@ public class TestWordToExtractorSuite
|
||||||
}
|
}
|
||||||
catch ( Exception exc )
|
catch ( Exception exc )
|
||||||
{
|
{
|
||||||
// unable to parse file -- not WordToFoExtractor fault
|
// unable to parse file -- not WordToFoConverter fault
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WordToFoExtractor wordToFoExtractor = new WordToFoExtractor(
|
WordToFoConverter wordToFoConverter = new WordToFoConverter(
|
||||||
DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
||||||
.newDocument() );
|
.newDocument() );
|
||||||
wordToFoExtractor.processDocument( hwpfDocument );
|
wordToFoConverter.processDocument( hwpfDocument );
|
||||||
|
|
||||||
StringWriter stringWriter = new StringWriter();
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ public class TestWordToExtractorSuite
|
||||||
transformer.setOutputProperty( OutputKeys.ENCODING, "utf-8" );
|
transformer.setOutputProperty( OutputKeys.ENCODING, "utf-8" );
|
||||||
transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
|
transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
|
||||||
transformer.transform(
|
transformer.transform(
|
||||||
new DOMSource( wordToFoExtractor.getDocument() ),
|
new DOMSource( wordToFoConverter.getDocument() ),
|
||||||
new StreamResult( stringWriter ) );
|
new StreamResult( stringWriter ) );
|
||||||
|
|
||||||
if ( html )
|
if ( html )
|
|
@ -16,7 +16,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*/
|
*/
|
||||||
package org.apache.poi.hwpf.extractor;
|
package org.apache.poi.hwpf.converter;
|
||||||
|
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
|
||||||
|
@ -32,11 +32,11 @@ import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hwpf.HWPFDocument;
|
import org.apache.poi.hwpf.HWPFDocument;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test cases for {@link WordToFoExtractor}
|
* Test cases for {@link WordToFoConverter}
|
||||||
*
|
*
|
||||||
* @author Sergey Vladimirov (vlsergey {at} gmail {dot} com)
|
* @author Sergey Vladimirov (vlsergey {at} gmail {dot} com)
|
||||||
*/
|
*/
|
||||||
public class TestWordToFoExtractor extends TestCase
|
public class TestWordToFoConverter extends TestCase
|
||||||
{
|
{
|
||||||
private static String getFoText( final String sampleFileName )
|
private static String getFoText( final String sampleFileName )
|
||||||
throws Exception
|
throws Exception
|
||||||
|
@ -44,10 +44,10 @@ public class TestWordToFoExtractor extends TestCase
|
||||||
HWPFDocument hwpfDocument = new HWPFDocument( POIDataSamples
|
HWPFDocument hwpfDocument = new HWPFDocument( POIDataSamples
|
||||||
.getDocumentInstance().openResourceAsStream( sampleFileName ) );
|
.getDocumentInstance().openResourceAsStream( sampleFileName ) );
|
||||||
|
|
||||||
WordToFoExtractor wordToFoExtractor = new WordToFoExtractor(
|
WordToFoConverter wordToFoConverter = new WordToFoConverter(
|
||||||
DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
||||||
.newDocument() );
|
.newDocument() );
|
||||||
wordToFoExtractor.processDocument( hwpfDocument );
|
wordToFoConverter.processDocument( hwpfDocument );
|
||||||
|
|
||||||
StringWriter stringWriter = new StringWriter();
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
|
||||||
|
@ -55,13 +55,22 @@ public class TestWordToFoExtractor extends TestCase
|
||||||
.newTransformer();
|
.newTransformer();
|
||||||
transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
|
transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
|
||||||
transformer.transform(
|
transformer.transform(
|
||||||
new DOMSource( wordToFoExtractor.getDocument() ),
|
new DOMSource( wordToFoConverter.getDocument() ),
|
||||||
new StreamResult( stringWriter ) );
|
new StreamResult( stringWriter ) );
|
||||||
|
|
||||||
String result = stringWriter.toString();
|
String result = stringWriter.toString();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testEquation() throws Exception
|
||||||
|
{
|
||||||
|
final String sampleFileName = "equation.doc";
|
||||||
|
String result = getFoText( sampleFileName );
|
||||||
|
|
||||||
|
assertTrue( result
|
||||||
|
.contains( "<!--Image link to '0.emf' can be here-->" ) );
|
||||||
|
}
|
||||||
|
|
||||||
public void testHyperlink() throws Exception
|
public void testHyperlink() throws Exception
|
||||||
{
|
{
|
||||||
final String sampleFileName = "hyperlink.doc";
|
final String sampleFileName = "hyperlink.doc";
|
||||||
|
@ -72,15 +81,6 @@ public class TestWordToFoExtractor extends TestCase
|
||||||
assertTrue( result.contains( "Hyperlink text" ) );
|
assertTrue( result.contains( "Hyperlink text" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEquation() throws Exception
|
|
||||||
{
|
|
||||||
final String sampleFileName = "equation.doc";
|
|
||||||
String result = getFoText( sampleFileName );
|
|
||||||
|
|
||||||
assertTrue( result
|
|
||||||
.contains( "<!--Image link to '0.emf' can be here-->" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPageref() throws Exception
|
public void testPageref() throws Exception
|
||||||
{
|
{
|
||||||
final String sampleFileName = "pageref.doc";
|
final String sampleFileName = "pageref.doc";
|
|
@ -14,7 +14,7 @@
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.hwpf.extractor;
|
package org.apache.poi.hwpf.converter;
|
||||||
|
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
|
||||||
|
@ -30,11 +30,11 @@ import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hwpf.HWPFDocument;
|
import org.apache.poi.hwpf.HWPFDocument;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test cases for {@link WordToFoExtractor}
|
* Test cases for {@link WordToFoConverter}
|
||||||
*
|
*
|
||||||
* @author Sergey Vladimirov (vlsergey {at} gmail {dot} com)
|
* @author Sergey Vladimirov (vlsergey {at} gmail {dot} com)
|
||||||
*/
|
*/
|
||||||
public class TestWordToHtmlExtractor extends TestCase
|
public class TestWordToHtmlConverter extends TestCase
|
||||||
{
|
{
|
||||||
private static String getHtmlText( final String sampleFileName )
|
private static String getHtmlText( final String sampleFileName )
|
||||||
throws Exception
|
throws Exception
|
||||||
|
@ -42,10 +42,10 @@ public class TestWordToHtmlExtractor extends TestCase
|
||||||
HWPFDocument hwpfDocument = new HWPFDocument( POIDataSamples
|
HWPFDocument hwpfDocument = new HWPFDocument( POIDataSamples
|
||||||
.getDocumentInstance().openResourceAsStream( sampleFileName ) );
|
.getDocumentInstance().openResourceAsStream( sampleFileName ) );
|
||||||
|
|
||||||
WordToHtmlExtractor wordToHtmlExtractor = new WordToHtmlExtractor(
|
WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(
|
||||||
DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
||||||
.newDocument() );
|
.newDocument() );
|
||||||
wordToHtmlExtractor.processDocument( hwpfDocument );
|
wordToHtmlConverter.processDocument( hwpfDocument );
|
||||||
|
|
||||||
StringWriter stringWriter = new StringWriter();
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public class TestWordToHtmlExtractor extends TestCase
|
||||||
transformer.setOutputProperty( OutputKeys.ENCODING, "utf-8" );
|
transformer.setOutputProperty( OutputKeys.ENCODING, "utf-8" );
|
||||||
transformer.setOutputProperty( OutputKeys.METHOD, "html" );
|
transformer.setOutputProperty( OutputKeys.METHOD, "html" );
|
||||||
transformer.transform(
|
transformer.transform(
|
||||||
new DOMSource( wordToHtmlExtractor.getDocument() ),
|
new DOMSource( wordToHtmlConverter.getDocument() ),
|
||||||
new StreamResult( stringWriter ) );
|
new StreamResult( stringWriter ) );
|
||||||
|
|
||||||
String result = stringWriter.toString();
|
String result = stringWriter.toString();
|
Loading…
Reference in New Issue