Search in sources :

Example 11 with XWPFDocument

use of org.apache.poi.xwpf.usermodel.XWPFDocument in project poi by apache.

the class TestDocumentProtection method testShouldEnforceForReadOnly.

@Test
public void testShouldEnforceForReadOnly() throws IOException {
    //		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());
    document.close();
}
Also used : XWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument) Test(org.junit.Test)

Example 12 with XWPFDocument

use of org.apache.poi.xwpf.usermodel.XWPFDocument in project poi by apache.

the class TestDocumentProtection method testShouldEnforceForTrackedChanges.

@Test
public void testShouldEnforceForTrackedChanges() throws IOException {
    XWPFDocument document = XWPFTestDataSamples.openSampleDocument("documentProtection_no_protection.docx");
    assertFalse(document.isEnforcedTrackedChangesProtection());
    document.enforceTrackedChangesProtection();
    assertTrue(document.isEnforcedTrackedChangesProtection());
    document.close();
}
Also used : XWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument) Test(org.junit.Test)

Example 13 with XWPFDocument

use of org.apache.poi.xwpf.usermodel.XWPFDocument in project poi by apache.

the class TestDocumentProtection method testShouldReadEnforcementProperties.

@Test
public void testShouldReadEnforcementProperties() throws IOException {
    XWPFDocument documentWithoutDocumentProtectionTag = XWPFTestDataSamples.openSampleDocument("documentProtection_no_protection.docx");
    assertFalse(documentWithoutDocumentProtectionTag.isEnforcedReadonlyProtection());
    assertFalse(documentWithoutDocumentProtectionTag.isEnforcedFillingFormsProtection());
    assertFalse(documentWithoutDocumentProtectionTag.isEnforcedCommentsProtection());
    assertFalse(documentWithoutDocumentProtectionTag.isEnforcedTrackedChangesProtection());
    documentWithoutDocumentProtectionTag.close();
    XWPFDocument documentWithoutEnforcement = XWPFTestDataSamples.openSampleDocument("documentProtection_no_protection_tag_existing.docx");
    assertFalse(documentWithoutEnforcement.isEnforcedReadonlyProtection());
    assertFalse(documentWithoutEnforcement.isEnforcedFillingFormsProtection());
    assertFalse(documentWithoutEnforcement.isEnforcedCommentsProtection());
    assertFalse(documentWithoutEnforcement.isEnforcedTrackedChangesProtection());
    documentWithoutEnforcement.close();
    XWPFDocument documentWithReadonlyEnforcement = XWPFTestDataSamples.openSampleDocument("documentProtection_readonly_no_password.docx");
    assertTrue(documentWithReadonlyEnforcement.isEnforcedReadonlyProtection());
    assertFalse(documentWithReadonlyEnforcement.isEnforcedFillingFormsProtection());
    assertFalse(documentWithReadonlyEnforcement.isEnforcedCommentsProtection());
    assertFalse(documentWithReadonlyEnforcement.isEnforcedTrackedChangesProtection());
    documentWithReadonlyEnforcement.close();
    XWPFDocument documentWithFillingFormsEnforcement = XWPFTestDataSamples.openSampleDocument("documentProtection_forms_no_password.docx");
    assertTrue(documentWithFillingFormsEnforcement.isEnforcedFillingFormsProtection());
    assertFalse(documentWithFillingFormsEnforcement.isEnforcedReadonlyProtection());
    assertFalse(documentWithFillingFormsEnforcement.isEnforcedCommentsProtection());
    assertFalse(documentWithFillingFormsEnforcement.isEnforcedTrackedChangesProtection());
    documentWithFillingFormsEnforcement.close();
    XWPFDocument documentWithCommentsEnforcement = XWPFTestDataSamples.openSampleDocument("documentProtection_comments_no_password.docx");
    assertFalse(documentWithCommentsEnforcement.isEnforcedFillingFormsProtection());
    assertFalse(documentWithCommentsEnforcement.isEnforcedReadonlyProtection());
    assertTrue(documentWithCommentsEnforcement.isEnforcedCommentsProtection());
    assertFalse(documentWithCommentsEnforcement.isEnforcedTrackedChangesProtection());
    documentWithCommentsEnforcement.close();
    XWPFDocument documentWithTrackedChangesEnforcement = XWPFTestDataSamples.openSampleDocument("documentProtection_trackedChanges_no_password.docx");
    assertFalse(documentWithTrackedChangesEnforcement.isEnforcedFillingFormsProtection());
    assertFalse(documentWithTrackedChangesEnforcement.isEnforcedReadonlyProtection());
    assertFalse(documentWithTrackedChangesEnforcement.isEnforcedCommentsProtection());
    assertTrue(documentWithTrackedChangesEnforcement.isEnforcedTrackedChangesProtection());
    documentWithTrackedChangesEnforcement.close();
}
Also used : XWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument) Test(org.junit.Test)

Example 14 with XWPFDocument

use of org.apache.poi.xwpf.usermodel.XWPFDocument in project poi by apache.

the class TestDocumentProtection method testShouldEnforceForFillingForms.

@Test
public void testShouldEnforceForFillingForms() throws IOException {
    XWPFDocument document = XWPFTestDataSamples.openSampleDocument("documentProtection_no_protection.docx");
    assertFalse(document.isEnforcedFillingFormsProtection());
    document.enforceFillingFormsProtection();
    assertTrue(document.isEnforcedFillingFormsProtection());
    document.close();
}
Also used : XWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument) Test(org.junit.Test)

Example 15 with XWPFDocument

use of org.apache.poi.xwpf.usermodel.XWPFDocument in project poi by apache.

the class TestPackageCorePropertiesGetKeywords method testGetSetKeywords.

public void testGetSetKeywords() throws IOException {
    XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestPoiXMLDocumentCorePropertiesGetKeywords.docx");
    String keywords = doc.getProperties().getCoreProperties().getKeywords();
    assertEquals("extractor, test, rdf", keywords);
    doc.getProperties().getCoreProperties().setKeywords("test, keywords");
    doc = XWPFTestDataSamples.writeOutAndReadBack(doc);
    keywords = doc.getProperties().getCoreProperties().getKeywords();
    assertEquals("test, keywords", keywords);
}
Also used : XWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument)

Aggregations

XWPFDocument (org.apache.poi.xwpf.usermodel.XWPFDocument)51 Test (org.junit.Test)15 FileOutputStream (java.io.FileOutputStream)11 File (java.io.File)9 XWPFParagraph (org.apache.poi.xwpf.usermodel.XWPFParagraph)9 XWPFRun (org.apache.poi.xwpf.usermodel.XWPFRun)9 InputStream (java.io.InputStream)6 OutputStream (java.io.OutputStream)6 FileInputStream (java.io.FileInputStream)4 XWPFTable (org.apache.poi.xwpf.usermodel.XWPFTable)4 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)3 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)3 XMLSlideShow (org.apache.poi.xslf.usermodel.XMLSlideShow)3 XWPFWordExtractor (org.apache.poi.xwpf.extractor.XWPFWordExtractor)3 XWPFFooter (org.apache.poi.xwpf.usermodel.XWPFFooter)3 XWPFHeader (org.apache.poi.xwpf.usermodel.XWPFHeader)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ZipFile (java.util.zip.ZipFile)2 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)2 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)2