Search in sources :

Example 6 with HWPFDocumentCore

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

the class TestWordToConverterSuite method testFo.

@Test
public void testFo() throws Exception {
    HWPFDocumentCore hwpfDocument;
    try {
        hwpfDocument = AbstractWordUtils.loadDoc(child);
    } catch (Exception exc) {
        return;
    }
    WordToFoConverter wordToFoConverter = new WordToFoConverter(XMLHelper.getDocumentBuilderFactory().newDocumentBuilder().newDocument());
    wordToFoConverter.processDocument(hwpfDocument);
    StringWriter stringWriter = new StringWriter();
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
    transformer.setOutputProperty(OutputKeys.INDENT, "false");
    transformer.transform(new DOMSource(wordToFoConverter.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 7 with HWPFDocumentCore

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

the class TestWordToConverterSuite method testHtml.

@Test
public void testHtml() throws Exception {
    HWPFDocumentCore hwpfDocument;
    try {
        hwpfDocument = AbstractWordUtils.loadDoc(child);
    } catch (Exception exc) {
        return;
    }
    WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(XMLHelper.getDocumentBuilderFactory().newDocumentBuilder().newDocument());
    wordToHtmlConverter.processDocument(hwpfDocument);
    StringWriter stringWriter = new StringWriter();
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
    transformer.setOutputProperty(OutputKeys.INDENT, "false");
    transformer.setOutputProperty(OutputKeys.METHOD, "html");
    transformer.transform(new DOMSource(wordToHtmlConverter.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 8 with HWPFDocumentCore

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

the class Paragraph method newParagraph.

@Internal
public static Paragraph newParagraph(Range parent, PAPX papx) {
    HWPFDocumentCore doc = parent._doc;
    ListTables listTables = doc.getListTables();
    StyleSheet styleSheet = doc.getStyleSheet();
    ParagraphProperties properties = new ParagraphProperties();
    properties.setIstd(papx.getIstd());
    properties = newParagraph_applyStyleProperties(styleSheet, papx, properties);
    properties = ParagraphSprmUncompressor.uncompressPAP(properties, papx.getGrpprl(), 2);
    if (properties.getIlfo() != 0 && listTables != null) {
        LFO lfo = null;
        try {
            lfo = listTables.getLfo(properties.getIlfo());
        } catch (NoSuchElementException exc) {
            log.log(POILogger.WARN, "Paragraph refers to LFO #", properties.getIlfo(), " that does not exists");
        }
        if (lfo != null) {
            final ListLevel listLevel = listTables.getLevel(lfo.getLsid(), properties.getIlvl());
            if (listLevel != null && listLevel.getGrpprlPapx() != null) {
                properties = ParagraphSprmUncompressor.uncompressPAP(properties, listLevel.getGrpprlPapx(), 0);
                // reapply style and local PAPX properties
                properties = newParagraph_applyStyleProperties(styleSheet, papx, properties);
                properties = ParagraphSprmUncompressor.uncompressPAP(properties, papx.getGrpprl(), 2);
            }
        }
    }
    if (properties.getIlfo() > 0)
        return new ListEntry(papx, properties, parent);
    return new Paragraph(papx, properties, parent);
}
Also used : HWPFDocumentCore(org.apache.poi.hwpf.HWPFDocumentCore) StyleSheet(org.apache.poi.hwpf.model.StyleSheet) LFO(org.apache.poi.hwpf.model.LFO) ListTables(org.apache.poi.hwpf.model.ListTables) NoSuchElementException(java.util.NoSuchElementException) ListLevel(org.apache.poi.hwpf.model.ListLevel) Internal(org.apache.poi.util.Internal)

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