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
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
package org.apache.poi.hwpf.extractor;
|
||||
package org.apache.poi.hwpf.converter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -38,7 +38,7 @@ import org.apache.poi.util.POILogger;
|
|||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public abstract class AbstractWordExtractor
|
||||
public abstract class AbstractWordConverter
|
||||
{
|
||||
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 POILogger logger = POILogFactory
|
||||
.getLogger( AbstractWordExtractor.class );
|
||||
.getLogger( AbstractWordConverter.class );
|
||||
|
||||
public abstract Document getDocument();
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
package org.apache.poi.hwpf.extractor;
|
||||
package org.apache.poi.hwpf.converter;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
|
@ -14,7 +14,7 @@
|
|||
See the License for the specific language governing permissions and
|
||||
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.Element;
|
|
@ -14,7 +14,7 @@
|
|||
See the License for the specific language governing permissions and
|
||||
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.Element;
|
|
@ -17,24 +17,27 @@
|
|||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.apache.poi.hwpf.extractor;
|
||||
package org.apache.poi.hwpf.converter;
|
||||
|
||||
/**
|
||||
* Comment me
|
||||
*
|
||||
* @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",
|
||||
"j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "x", "y", "z" };
|
||||
private static String[] C_LETTERS = new String[] { "a", "b", "c", "d", "e",
|
||||
"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",
|
||||
"viii", "ix", "x", "xi", "xii", "xiii", "xiv", "xv", "xvi", "xvii", "xviii", "xix",
|
||||
"xx", "xxi", "xxii", "xxiii", "xxiv", "xxv", "xxvi", "xxvii", "xxviii", "xxix", "xxx",
|
||||
"xxxi", "xxxii", "xxxiii", "xxxiv", "xxxv", "xxxvi", "xxxvii", "xxxvii", "xxxviii",
|
||||
"xxxix", "xl", "xli", "xlii", "xliii", "xliv", "xlv", "xlvi", "xlvii", "xlviii",
|
||||
"xlix", "l" };
|
||||
private static String[] C_ROMAN = new String[] { "i", "ii", "iii", "iv",
|
||||
"v", "vi", "vii", "viii", "ix", "x", "xi", "xii", "xiii", "xiv",
|
||||
"xv", "xvi", "xvii", "xviii", "xix", "xx", "xxi", "xxii", "xxiii",
|
||||
"xxiv", "xxv", "xxvi", "xxvii", "xxviii", "xxix", "xxx", "xxxi",
|
||||
"xxxii", "xxxiii", "xxxiv", "xxxv", "xxxvi", "xxxvii", "xxxvii",
|
||||
"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_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_ROMAN = 1;
|
||||
|
||||
public static String getNumber(int num, int style) {
|
||||
switch (style) {
|
||||
public static String getNumber( int num, int style )
|
||||
{
|
||||
switch ( style )
|
||||
{
|
||||
case T_UPPER_ROMAN:
|
||||
return C_ROMAN[num - 1].toUpperCase();
|
||||
case T_LOWER_ROMAN:
|
|
@ -14,7 +14,7 @@
|
|||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
package org.apache.poi.hwpf.extractor;
|
||||
package org.apache.poi.hwpf.converter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
|
@ -54,7 +54,7 @@ import org.w3c.dom.Text;
|
|||
/**
|
||||
* @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
|
||||
.getLogger( WordToFoExtractor.class );
|
||||
.getLogger( WordToFoConverter.class );
|
||||
|
||||
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>
|
||||
* Usage: WordToFoExtractor infile outfile
|
||||
* Usage: WordToFoConverter infile outfile
|
||||
* </p>
|
||||
* Where infile is an input .doc file ( Word 97-2007) which will be rendered
|
||||
* as XSL-FO into outfile
|
||||
*
|
||||
*/
|
||||
public static void main( String[] args )
|
||||
{
|
||||
if ( args.length < 2 )
|
||||
{
|
||||
System.err
|
||||
.println( "Usage: WordToFoExtractor <inputFile.doc> <saveTo.fo>" );
|
||||
.println( "Usage: WordToFoConverter <inputFile.doc> <saveTo.fo>" );
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -154,7 +153,7 @@ public class WordToFoExtractor extends AbstractWordExtractor
|
|||
System.out.println( "Saving output to " + args[1] );
|
||||
try
|
||||
{
|
||||
Document doc = WordToFoExtractor.process( new File( args[0] ) );
|
||||
Document doc = WordToFoConverter.process( new File( args[0] ) );
|
||||
|
||||
FileWriter out = new FileWriter( args[1] );
|
||||
DOMSource domSource = new DOMSource( doc );
|
||||
|
@ -176,11 +175,11 @@ public class WordToFoExtractor extends AbstractWordExtractor
|
|||
static Document process( File docFile ) throws Exception
|
||||
{
|
||||
final HWPFDocumentCore hwpfDocument = WordToFoUtils.loadDoc( docFile );
|
||||
WordToFoExtractor wordToFoExtractor = new WordToFoExtractor(
|
||||
WordToFoConverter wordToFoConverter = new WordToFoConverter(
|
||||
DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
||||
.newDocument() );
|
||||
wordToFoExtractor.processDocument( hwpfDocument );
|
||||
return wordToFoExtractor.getDocument();
|
||||
wordToFoConverter.processDocument( hwpfDocument );
|
||||
return wordToFoConverter.getDocument();
|
||||
}
|
||||
|
||||
private final Stack<BlockProperies> blocksProperies = new Stack<BlockProperies>();
|
||||
|
@ -188,14 +187,14 @@ public class WordToFoExtractor extends AbstractWordExtractor
|
|||
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.
|
||||
*
|
||||
* @param document
|
||||
* XML DOM Document used as XSL FO document. Shall support
|
||||
* namespaces
|
||||
*/
|
||||
public WordToFoExtractor( Document document )
|
||||
public WordToFoConverter( Document document )
|
||||
{
|
||||
this.foDocumentFacade = new FoDocumentFacade( document );
|
||||
}
|
|
@ -14,7 +14,7 @@
|
|||
See the License for the specific language governing permissions and
|
||||
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.CharacterProperties;
|
|
@ -14,7 +14,7 @@
|
|||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
package org.apache.poi.hwpf.extractor;
|
||||
package org.apache.poi.hwpf.converter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
|
@ -44,12 +44,18 @@ import org.w3c.dom.Document;
|
|||
import org.w3c.dom.Element;
|
||||
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)
|
||||
*/
|
||||
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
|
||||
.getLogger( WordToHtmlExtractor.class );
|
||||
.getLogger( WordToHtmlConverter.class );
|
||||
|
||||
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>
|
||||
* Usage: WordToHtmlExtractor infile outfile
|
||||
* Usage: WordToHtmlConverter infile outfile
|
||||
* </p>
|
||||
* Where infile is an input .doc file ( Word 95-2007) which will be rendered
|
||||
* as HTML into outfile
|
||||
|
@ -113,7 +119,7 @@ public class WordToHtmlExtractor extends AbstractWordExtractor
|
|||
if ( args.length < 2 )
|
||||
{
|
||||
System.err
|
||||
.println( "Usage: WordToHtmlExtractor <inputFile.doc> <saveTo.html>" );
|
||||
.println( "Usage: WordToHtmlConverter <inputFile.doc> <saveTo.html>" );
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -121,7 +127,7 @@ public class WordToHtmlExtractor extends AbstractWordExtractor
|
|||
System.out.println( "Saving output to " + args[1] );
|
||||
try
|
||||
{
|
||||
Document doc = WordToHtmlExtractor.process( new File( args[0] ) );
|
||||
Document doc = WordToHtmlConverter.process( new File( args[0] ) );
|
||||
|
||||
FileWriter out = new FileWriter( args[1] );
|
||||
DOMSource domSource = new DOMSource( doc );
|
||||
|
@ -145,11 +151,11 @@ public class WordToHtmlExtractor extends AbstractWordExtractor
|
|||
static Document process( File docFile ) throws Exception
|
||||
{
|
||||
final HWPFDocumentCore wordDocument = WordToHtmlUtils.loadDoc( docFile );
|
||||
WordToHtmlExtractor wordToHtmlExtractor = new WordToHtmlExtractor(
|
||||
WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(
|
||||
DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
||||
.newDocument() );
|
||||
wordToHtmlExtractor.processDocument( wordDocument );
|
||||
return wordToHtmlExtractor.getDocument();
|
||||
wordToHtmlConverter.processDocument( wordDocument );
|
||||
return wordToHtmlConverter.getDocument();
|
||||
}
|
||||
|
||||
private final Stack<BlockProperies> blocksProperies = new Stack<BlockProperies>();
|
||||
|
@ -157,13 +163,13 @@ public class WordToHtmlExtractor extends AbstractWordExtractor
|
|||
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.
|
||||
*
|
||||
* @param document
|
||||
* XML DOM Document used as HTML document
|
||||
*/
|
||||
public WordToHtmlExtractor( Document document )
|
||||
public WordToHtmlConverter( Document document )
|
||||
{
|
||||
this.htmlDocumentFacade = new HtmlDocumentFacade( document );
|
||||
}
|
|
@ -14,7 +14,7 @@
|
|||
See the License for the specific language governing permissions and
|
||||
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.CharacterProperties;
|
|
@ -14,7 +14,7 @@
|
|||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
package org.apache.poi.hwpf.extractor;
|
||||
package org.apache.poi.hwpf.converter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
|
@ -35,7 +35,7 @@ import junit.framework.TestSuite;
|
|||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.hwpf.HWPFDocumentCore;
|
||||
|
||||
public class TestWordToExtractorSuite
|
||||
public class TestWordToConverterSuite
|
||||
{
|
||||
/**
|
||||
* YK: a quick hack to exclude failing documents from the suite.
|
||||
|
@ -87,14 +87,14 @@ public class TestWordToExtractorSuite
|
|||
}
|
||||
catch ( Exception exc )
|
||||
{
|
||||
// unable to parse file -- not WordToFoExtractor fault
|
||||
// unable to parse file -- not WordToFoConverter fault
|
||||
return;
|
||||
}
|
||||
|
||||
WordToFoExtractor wordToFoExtractor = new WordToFoExtractor(
|
||||
WordToFoConverter wordToFoConverter = new WordToFoConverter(
|
||||
DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
||||
.newDocument() );
|
||||
wordToFoExtractor.processDocument( hwpfDocument );
|
||||
wordToFoConverter.processDocument( hwpfDocument );
|
||||
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
|
||||
|
@ -103,7 +103,7 @@ public class TestWordToExtractorSuite
|
|||
transformer.setOutputProperty( OutputKeys.ENCODING, "utf-8" );
|
||||
transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
|
||||
transformer.transform(
|
||||
new DOMSource( wordToFoExtractor.getDocument() ),
|
||||
new DOMSource( wordToFoConverter.getDocument() ),
|
||||
new StreamResult( stringWriter ) );
|
||||
|
||||
if ( html )
|
|
@ -16,7 +16,7 @@
|
|||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.apache.poi.hwpf.extractor;
|
||||
package org.apache.poi.hwpf.converter;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
|
@ -32,11 +32,11 @@ import org.apache.poi.POIDataSamples;
|
|||
import org.apache.poi.hwpf.HWPFDocument;
|
||||
|
||||
/**
|
||||
* Test cases for {@link WordToFoExtractor}
|
||||
* Test cases for {@link WordToFoConverter}
|
||||
*
|
||||
* @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 )
|
||||
throws Exception
|
||||
|
@ -44,10 +44,10 @@ public class TestWordToFoExtractor extends TestCase
|
|||
HWPFDocument hwpfDocument = new HWPFDocument( POIDataSamples
|
||||
.getDocumentInstance().openResourceAsStream( sampleFileName ) );
|
||||
|
||||
WordToFoExtractor wordToFoExtractor = new WordToFoExtractor(
|
||||
WordToFoConverter wordToFoConverter = new WordToFoConverter(
|
||||
DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
||||
.newDocument() );
|
||||
wordToFoExtractor.processDocument( hwpfDocument );
|
||||
wordToFoConverter.processDocument( hwpfDocument );
|
||||
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
|
||||
|
@ -55,13 +55,22 @@ public class TestWordToFoExtractor extends TestCase
|
|||
.newTransformer();
|
||||
transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
|
||||
transformer.transform(
|
||||
new DOMSource( wordToFoExtractor.getDocument() ),
|
||||
new DOMSource( wordToFoConverter.getDocument() ),
|
||||
new StreamResult( stringWriter ) );
|
||||
|
||||
String result = stringWriter.toString();
|
||||
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
|
||||
{
|
||||
final String sampleFileName = "hyperlink.doc";
|
||||
|
@ -72,15 +81,6 @@ public class TestWordToFoExtractor extends TestCase
|
|||
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
|
||||
{
|
||||
final String sampleFileName = "pageref.doc";
|
|
@ -14,7 +14,7 @@
|
|||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
package org.apache.poi.hwpf.extractor;
|
||||
package org.apache.poi.hwpf.converter;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
|
@ -30,11 +30,11 @@ import org.apache.poi.POIDataSamples;
|
|||
import org.apache.poi.hwpf.HWPFDocument;
|
||||
|
||||
/**
|
||||
* Test cases for {@link WordToFoExtractor}
|
||||
* Test cases for {@link WordToFoConverter}
|
||||
*
|
||||
* @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 )
|
||||
throws Exception
|
||||
|
@ -42,10 +42,10 @@ public class TestWordToHtmlExtractor extends TestCase
|
|||
HWPFDocument hwpfDocument = new HWPFDocument( POIDataSamples
|
||||
.getDocumentInstance().openResourceAsStream( sampleFileName ) );
|
||||
|
||||
WordToHtmlExtractor wordToHtmlExtractor = new WordToHtmlExtractor(
|
||||
WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(
|
||||
DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
||||
.newDocument() );
|
||||
wordToHtmlExtractor.processDocument( hwpfDocument );
|
||||
wordToHtmlConverter.processDocument( hwpfDocument );
|
||||
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
|
||||
|
@ -55,7 +55,7 @@ public class TestWordToHtmlExtractor extends TestCase
|
|||
transformer.setOutputProperty( OutputKeys.ENCODING, "utf-8" );
|
||||
transformer.setOutputProperty( OutputKeys.METHOD, "html" );
|
||||
transformer.transform(
|
||||
new DOMSource( wordToHtmlExtractor.getDocument() ),
|
||||
new DOMSource( wordToHtmlConverter.getDocument() ),
|
||||
new StreamResult( stringWriter ) );
|
||||
|
||||
String result = stringWriter.toString();
|
Loading…
Reference in New Issue