Examples of XWPFDocument


Examples of org.apache.poi.xwpf.usermodel.XWPFDocument

public final class TestPOIXMLProperties extends TestCase {
  private POIXMLProperties _props;
  private CoreProperties _coreProperties;

  public void setUp() {
    XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("documentProperties.docx");
    _props = sampleDoc.getProperties();
    _coreProperties = _props.getCoreProperties();
    assertNotNull(_props);
  }
View Full Code Here

Examples of org.apache.poi.xwpf.usermodel.XWPFDocument

public class TestDocumentProtection extends TestCase {

    public void testShouldReadEnforcementProperties() throws Exception {

        XWPFDocument documentWithoutDocumentProtectionTag = XWPFTestDataSamples.openSampleDocument("documentProtection_no_protection.docx");
        assertFalse(documentWithoutDocumentProtectionTag.isEnforcedReadonlyProtection());
        assertFalse(documentWithoutDocumentProtectionTag.isEnforcedFillingFormsProtection());
        assertFalse(documentWithoutDocumentProtectionTag.isEnforcedCommentsProtection());
        assertFalse(documentWithoutDocumentProtectionTag.isEnforcedTrackedChangesProtection());

        XWPFDocument documentWithoutEnforcement = XWPFTestDataSamples.openSampleDocument("documentProtection_no_protection_tag_existing.docx");
        assertFalse(documentWithoutEnforcement.isEnforcedReadonlyProtection());
        assertFalse(documentWithoutEnforcement.isEnforcedFillingFormsProtection());
        assertFalse(documentWithoutEnforcement.isEnforcedCommentsProtection());
        assertFalse(documentWithoutEnforcement.isEnforcedTrackedChangesProtection());

        XWPFDocument documentWithReadonlyEnforcement = XWPFTestDataSamples.openSampleDocument("documentProtection_readonly_no_password.docx");
        assertTrue(documentWithReadonlyEnforcement.isEnforcedReadonlyProtection());
        assertFalse(documentWithReadonlyEnforcement.isEnforcedFillingFormsProtection());
        assertFalse(documentWithReadonlyEnforcement.isEnforcedCommentsProtection());
        assertFalse(documentWithReadonlyEnforcement.isEnforcedTrackedChangesProtection());

        XWPFDocument documentWithFillingFormsEnforcement = XWPFTestDataSamples.openSampleDocument("documentProtection_forms_no_password.docx");
        assertTrue(documentWithFillingFormsEnforcement.isEnforcedFillingFormsProtection());
        assertFalse(documentWithFillingFormsEnforcement.isEnforcedReadonlyProtection());
        assertFalse(documentWithFillingFormsEnforcement.isEnforcedCommentsProtection());
        assertFalse(documentWithFillingFormsEnforcement.isEnforcedTrackedChangesProtection());

        XWPFDocument documentWithCommentsEnforcement = XWPFTestDataSamples.openSampleDocument("documentProtection_comments_no_password.docx");
        assertFalse(documentWithCommentsEnforcement.isEnforcedFillingFormsProtection());
        assertFalse(documentWithCommentsEnforcement.isEnforcedReadonlyProtection());
        assertTrue(documentWithCommentsEnforcement.isEnforcedCommentsProtection());
        assertFalse(documentWithCommentsEnforcement.isEnforcedTrackedChangesProtection());

        XWPFDocument documentWithTrackedChangesEnforcement = XWPFTestDataSamples.openSampleDocument("documentProtection_trackedChanges_no_password.docx");
        assertFalse(documentWithTrackedChangesEnforcement.isEnforcedFillingFormsProtection());
        assertFalse(documentWithTrackedChangesEnforcement.isEnforcedReadonlyProtection());
        assertFalse(documentWithTrackedChangesEnforcement.isEnforcedCommentsProtection());
        assertTrue(documentWithTrackedChangesEnforcement.isEnforcedTrackedChangesProtection());

    }
View Full Code Here

Examples of org.apache.poi.xwpf.usermodel.XWPFDocument

    }

    public void testShouldEnforceForReadOnly() throws Exception {
        //    XWPFDocument document = createDocumentFromSampleFile("test-data/document/documentProtection_no_protection.docx");
        XWPFDocument document = XWPFTestDataSamples.openSampleDocument("documentProtection_no_protection.docx");
        assertFalse(document.isEnforcedReadonlyProtection());

        document.enforceReadonlyProtection();

        assertTrue(document.isEnforcedReadonlyProtection());
    }
View Full Code Here

Examples of org.apache.poi.xwpf.usermodel.XWPFDocument

        assertTrue(document.isEnforcedReadonlyProtection());
    }

    public void testShouldEnforceForFillingForms() throws Exception {
        XWPFDocument document = XWPFTestDataSamples.openSampleDocument("documentProtection_no_protection.docx");
        assertFalse(document.isEnforcedFillingFormsProtection());

        document.enforceFillingFormsProtection();

        assertTrue(document.isEnforcedFillingFormsProtection());
    }
View Full Code Here

Examples of org.apache.poi.xwpf.usermodel.XWPFDocument

        assertTrue(document.isEnforcedFillingFormsProtection());
    }

    public void testShouldEnforceForComments() throws Exception {
        XWPFDocument document = XWPFTestDataSamples.openSampleDocument("documentProtection_no_protection.docx");
        assertFalse(document.isEnforcedCommentsProtection());

        document.enforceCommentsProtection();

        assertTrue(document.isEnforcedCommentsProtection());
    }
View Full Code Here

Examples of org.apache.poi.xwpf.usermodel.XWPFDocument

        assertTrue(document.isEnforcedCommentsProtection());
    }

    public void testShouldEnforceForTrackedChanges() throws Exception {
        XWPFDocument document = XWPFTestDataSamples.openSampleDocument("documentProtection_no_protection.docx");
        assertFalse(document.isEnforcedTrackedChangesProtection());

        document.enforceTrackedChangesProtection();

        assertTrue(document.isEnforcedTrackedChangesProtection());
    }
View Full Code Here

Examples of org.apache.poi.xwpf.usermodel.XWPFDocument

        assertTrue(document.isEnforcedTrackedChangesProtection());
    }

    public void testShouldUnsetEnforcement() throws Exception {
        XWPFDocument document = XWPFTestDataSamples.openSampleDocument("documentProtection_readonly_no_password.docx");
        assertTrue(document.isEnforcedReadonlyProtection());

        document.removeProtectionEnforcement();

        assertFalse(document.isEnforcedReadonlyProtection());
    }
View Full Code Here

Examples of org.apache.poi.xwpf.usermodel.XWPFDocument

        assertFalse(document.isEnforcedReadonlyProtection());
    }

    public void testIntegration() throws Exception {
        XWPFDocument doc = new XWPFDocument();

        XWPFParagraph p1 = doc.createParagraph();

        XWPFRun r1 = p1.createRun();
        r1.setText("Lorem ipsum dolor sit amet.");
        doc.enforceCommentsProtection();

        File tempFile = File.createTempFile("documentProtectionFile", ".docx");
        FileOutputStream out = new FileOutputStream(tempFile);

        doc.write(out);
        out.close();

        FileInputStream inputStream = new FileInputStream(tempFile);
        XWPFDocument document = new XWPFDocument(inputStream);
        inputStream.close();

        assertTrue(document.isEnforcedCommentsProtection());
    }
View Full Code Here

Examples of org.apache.poi.xwpf.usermodel.XWPFDocument

import org.apache.poi.xwpf.usermodel.XWPFRelation;

public final class TestXWPFDocument extends TestCase {

  public void testContainsMainContentType() throws Exception {
    XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
    OPCPackage pack = doc.getPackage();

    boolean found = false;
    for(PackagePart part : pack.getParts()) {
      if(part.getContentType().equals(XWPFRelation.DOCUMENT.getContentType())) {
        found = true;
View Full Code Here

Examples of org.apache.poi.xwpf.usermodel.XWPFDocument

    }
    assertTrue(found);
  }

  public void testOpen() throws Exception {
    XWPFDocument xml;

    // Simple file
    xml = XWPFTestDataSamples.openSampleDocument("sample.docx");
    // Check it has key parts
    assertNotNull(xml.getDocument());
    assertNotNull(xml.getDocument().getBody());
    assertNotNull(xml.getStyle());

    // Complex file
    xml = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx");
    assertNotNull(xml.getDocument());
    assertNotNull(xml.getDocument().getBody());
    assertNotNull(xml.getStyle());
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.