Package org.apache.poi.xwpf.usermodel

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


    }

    @Test
    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


        assertTrue(document.isEnforcedReadonlyProtection());
    }

    @Test
    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

        assertTrue(document.isEnforcedFillingFormsProtection());
    }

    @Test
    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

        assertTrue(document.isEnforcedCommentsProtection());
    }

    @Test
    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

        assertTrue(document.isEnforcedTrackedChangesProtection());
    }

    @Test
    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

        assertFalse(document.isEnforcedReadonlyProtection());
    }

    @Test
    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 = TempFile.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

        assertTrue(document.isEnforcedCommentsProtection());
    }

    @Test
    public void testUpdateFields() throws Exception {
        XWPFDocument doc = new XWPFDocument();
        assertFalse(doc.isEnforcedUpdateFields());
        doc.enforceUpdateFields();
        assertTrue(doc.isEnforcedUpdateFields());
    }
View Full Code Here

        assertEquals("64CEED7E", CryptoFunctions.xorHashPassword("Example"));
        // check leading 0
        assertEquals("0005CB00", CryptoFunctions.xorHashPassword("34579"));

        // test document write protection with password
        XWPFDocument document = XWPFTestDataSamples.openSampleDocument("bug56076.docx");
        boolean isValid = document.validateProtectionPassword("Example");
        assertTrue(isValid);
    }
View Full Code Here

    }

    @Test
    public void bug56076_write() throws Exception {
        // test document write protection with password
        XWPFDocument document = new XWPFDocument();
        document.enforceCommentsProtection("Example", HashAlgorithm.sha512);
        document = XWPFTestDataSamples.writeOutAndReadBack(document);
        boolean isValid = document.validateProtectionPassword("Example");
        assertTrue(isValid);
    }
View Full Code Here

  
  private XWPFDocument document;
  private boolean fetchHyperlinks = false;
 
  public XWPFWordExtractor(OPCPackage container) throws XmlException, OpenXML4JException, IOException {
    this(new XWPFDocument(container));
  }
View Full Code Here

TOP

Related Classes of org.apache.poi.xwpf.usermodel.XWPFDocument

Copyright © 2018 www.massapicom. 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.