Search in sources :

Example 1 with HWPFDocumentCore

use of org.apache.poi.hwpf.HWPFDocumentCore in project poi by apache.

the class HWPFLister method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        System.err.println("Use:");
        System.err.println("\tHWPFLister <filename>\n" + "\t\t[--dop]\n" + "\t\t[--textPieces] [--textPiecesText]\n" + "\t\t[--chpx] [--chpxProperties] [--chpxSprms]\n" + "\t\t[--papx] [--papxProperties] [--papxSprms]\n" + "\t\t[--paragraphs] [--paragraphsText]\n" + "\t\t[--bookmarks]\n" + "\t\t[--escher]\n" + "\t\t[--fields]\n" + "\t\t[--pictures]\n" + "\t\t[--officeDrawings]\n" + "\t\t[--styles]\n" + "\t\t[--writereadback]\n");
        System.exit(1);
    }
    boolean outputDop = false;
    boolean outputTextPieces = false;
    boolean outputTextPiecesText = false;
    boolean outputChpx = false;
    boolean outputChpxProperties = false;
    boolean outputChpxSprms = false;
    boolean outputParagraphs = false;
    boolean outputParagraphsText = false;
    boolean outputPapx = false;
    boolean outputPapxSprms = false;
    boolean outputPapxProperties = false;
    boolean outputBookmarks = false;
    boolean outputEscher = false;
    boolean outputFields = false;
    boolean outputPictures = false;
    boolean outputOfficeDrawings = false;
    boolean outputStyles = false;
    boolean writereadback = false;
    for (String arg : Arrays.asList(args).subList(1, args.length)) {
        if ("--dop".equals(arg))
            outputDop = true;
        if ("--textPieces".equals(arg))
            outputTextPieces = true;
        if ("--textPiecesText".equals(arg))
            outputTextPiecesText = true;
        if ("--chpx".equals(arg))
            outputChpx = true;
        if ("--chpxProperties".equals(arg))
            outputChpxProperties = true;
        if ("--chpxSprms".equals(arg))
            outputChpxSprms = true;
        if ("--paragraphs".equals(arg))
            outputParagraphs = true;
        if ("--paragraphsText".equals(arg))
            outputParagraphsText = true;
        if ("--papx".equals(arg))
            outputPapx = true;
        if ("--papxProperties".equals(arg))
            outputPapxProperties = true;
        if ("--papxSprms".equals(arg))
            outputPapxSprms = true;
        if ("--bookmarks".equals(arg))
            outputBookmarks = true;
        if ("--escher".equals(arg))
            outputEscher = true;
        if ("--fields".equals(arg))
            outputFields = true;
        if ("--pictures".equals(arg))
            outputPictures = true;
        if ("--officeDrawings".equals(arg))
            outputOfficeDrawings = true;
        if ("--styles".equals(arg))
            outputStyles = true;
        if ("--writereadback".equals(arg))
            writereadback = true;
    }
    HWPFDocumentCore doc = loadDoc(new File(args[0]));
    if (writereadback)
        doc = writeOutAndReadBack(doc);
    HWPFDocumentCore original;
    {
        System.setProperty("org.apache.poi.hwpf.preserveBinTables", Boolean.TRUE.toString());
        System.setProperty("org.apache.poi.hwpf.preserveTextTable", Boolean.TRUE.toString());
        original = loadDoc(new File(args[0]));
        if (writereadback)
            original = writeOutAndReadBack(original);
    }
    HWPFLister listerOriginal = new HWPFLister(original);
    HWPFLister listerRebuilded = new HWPFLister(doc);
    System.out.println("== OLE streams ==");
    listerOriginal.dumpFileSystem();
    System.out.println("== FIB (original) ==");
    listerOriginal.dumpFIB();
    if (outputDop) {
        System.out.println("== Document properties ==");
        listerOriginal.dumpDop();
    }
    if (outputTextPieces) {
        System.out.println("== Text pieces (original) ==");
        listerOriginal.dumpTextPieces(outputTextPiecesText);
    }
    if (outputChpx) {
        System.out.println("== CHPX (original) ==");
        listerOriginal.dumpChpx(outputChpxProperties, outputChpxSprms);
        System.out.println("== CHPX (rebuilded) ==");
        listerRebuilded.dumpChpx(outputChpxProperties, outputChpxSprms);
    }
    if (outputPapx) {
        System.out.println("== PAPX (original) ==");
        listerOriginal.dumpPapx(outputPapxProperties, outputPapxSprms);
        System.out.println("== PAPX (rebuilded) ==");
        listerRebuilded.dumpPapx(outputPapxProperties, outputPapxSprms);
    }
    if (outputParagraphs) {
        System.out.println("== Text paragraphs (original) ==");
        listerRebuilded.dumpParagraphs(true);
        System.out.println("== DOM paragraphs (rebuilded) ==");
        listerRebuilded.dumpParagraphsDom(outputParagraphsText);
    }
    if (outputBookmarks) {
        System.out.println("== BOOKMARKS (rebuilded) ==");
        listerRebuilded.dumpBookmarks();
    }
    if (outputEscher) {
        System.out.println("== ESCHER PROPERTIES (rebuilded) ==");
        listerRebuilded.dumpEscher();
    }
    if (outputFields) {
        System.out.println("== FIELDS (rebuilded) ==");
        listerRebuilded.dumpFields();
    }
    if (outputOfficeDrawings) {
        System.out.println("== OFFICE DRAWINGS (rebuilded) ==");
        listerRebuilded.dumpOfficeDrawings();
    }
    if (outputPictures) {
        System.out.println("== PICTURES (rebuilded) ==");
        listerRebuilded.dumpPictures();
    }
    if (outputStyles) {
        System.out.println("== STYLES (rebuilded) ==");
        listerRebuilded.dumpStyles();
    }
}
Also used : HWPFDocumentCore(org.apache.poi.hwpf.HWPFDocumentCore) File(java.io.File)

Example 2 with HWPFDocumentCore

use of org.apache.poi.hwpf.HWPFDocumentCore in project poi by apache.

the class TestWordToConverterSuite method testText.

@Test
public void testText() throws Exception {
    HWPFDocumentCore wordDocument;
    try {
        wordDocument = AbstractWordUtils.loadDoc(child);
    } catch (Exception exc) {
        return;
    }
    WordToTextConverter wordToTextConverter = new WordToTextConverter(XMLHelper.getDocumentBuilderFactory().newDocumentBuilder().newDocument());
    wordToTextConverter.processDocument(wordDocument);
    StringWriter stringWriter = new StringWriter();
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty(OutputKeys.METHOD, "text");
    transformer.transform(new DOMSource(wordToTextConverter.getDocument()), new StreamResult(stringWriter));
    // no exceptions
    assertNotNull(stringWriter.toString());
}
Also used : HWPFDocumentCore(org.apache.poi.hwpf.HWPFDocumentCore) DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) Test(org.junit.Test)

Example 3 with HWPFDocumentCore

use of org.apache.poi.hwpf.HWPFDocumentCore in project poi by apache.

the class WordToHtmlConverter method process.

static Document process(File docFile) throws IOException, ParserConfigurationException {
    final HWPFDocumentCore wordDocument = AbstractWordUtils.loadDoc(docFile);
    WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(XMLHelper.getDocumentBuilderFactory().newDocumentBuilder().newDocument());
    wordToHtmlConverter.processDocument(wordDocument);
    return wordToHtmlConverter.getDocument();
}
Also used : HWPFDocumentCore(org.apache.poi.hwpf.HWPFDocumentCore)

Example 4 with HWPFDocumentCore

use of org.apache.poi.hwpf.HWPFDocumentCore in project poi by apache.

the class WordToTextConverter method process.

static Document process(File docFile) throws Exception {
    final HWPFDocumentCore wordDocument = AbstractWordUtils.loadDoc(docFile);
    WordToTextConverter wordToTextConverter = new WordToTextConverter(XMLHelper.getDocumentBuilderFactory().newDocumentBuilder().newDocument());
    wordToTextConverter.processDocument(wordDocument);
    return wordToTextConverter.getDocument();
}
Also used : HWPFDocumentCore(org.apache.poi.hwpf.HWPFDocumentCore)

Example 5 with HWPFDocumentCore

use of org.apache.poi.hwpf.HWPFDocumentCore in project poi by apache.

the class WordToFoConverter method process.

static Document process(File docFile) throws Exception {
    final HWPFDocumentCore hwpfDocument = WordToFoUtils.loadDoc(docFile);
    WordToFoConverter wordToFoConverter = new WordToFoConverter(XMLHelper.getDocumentBuilderFactory().newDocumentBuilder().newDocument());
    wordToFoConverter.processDocument(hwpfDocument);
    return wordToFoConverter.getDocument();
}
Also used : HWPFDocumentCore(org.apache.poi.hwpf.HWPFDocumentCore)

Aggregations

HWPFDocumentCore (org.apache.poi.hwpf.HWPFDocumentCore)8 StringWriter (java.io.StringWriter)3 Transformer (javax.xml.transform.Transformer)3 DOMSource (javax.xml.transform.dom.DOMSource)3 StreamResult (javax.xml.transform.stream.StreamResult)3 Test (org.junit.Test)3 File (java.io.File)1 NoSuchElementException (java.util.NoSuchElementException)1 LFO (org.apache.poi.hwpf.model.LFO)1 ListLevel (org.apache.poi.hwpf.model.ListLevel)1 ListTables (org.apache.poi.hwpf.model.ListTables)1 StyleSheet (org.apache.poi.hwpf.model.StyleSheet)1 Internal (org.apache.poi.util.Internal)1