]> source.dussan.org Git - poi.git/commitdiff
Add disabled test for XWPF writing to a new stream when opened read-only
authorNick Burch <nick@apache.org>
Thu, 2 Jun 2016 22:59:47 +0000 (22:59 +0000)
committerNick Burch <nick@apache.org>
Thu, 2 Jun 2016 22:59:47 +0000 (22:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1746653 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/POIXMLDocument.java
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java

index 522773eb8b613d20a34c74325a72cea18648ba6f..1d73329a4e690c408bca2cacb18d56dd11f27142 100644 (file)
@@ -174,6 +174,7 @@ public abstract class POIXMLDocument extends POIXMLDocumentPart implements Close
      */
     public final void write(OutputStream stream) throws IOException {
         //force all children to commit their changes into the underlying OOXML Package
+        // TODO Shouldn't they be committing to the new one instead?
         Set<PackagePart> context = new HashSet<PackagePart>();
         onSave(context);
         context.clear();
index afa0428b4a2a5e5336d58e0e478c91ba051bad61..1dbba43a690b48c3f6d5a9447c61ea87bb5c85de 100644 (file)
@@ -19,22 +19,27 @@ package org.apache.poi.xwpf.usermodel;
 
 import static org.junit.Assert.*;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Arrays;
 import java.util.List;
 
+import org.apache.poi.POIDataSamples;
 import org.apache.poi.POIXMLDocumentPart;
 import org.apache.poi.POIXMLProperties;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.PackageAccess;
 import org.apache.poi.openxml4j.opc.PackagePart;
 import org.apache.poi.openxml4j.opc.PackagePartName;
 import org.apache.poi.openxml4j.opc.PackageRelationship;
 import org.apache.poi.openxml4j.opc.PackagingURIHelper;
 import org.apache.poi.openxml4j.opc.TargetMode;
 import org.apache.poi.xwpf.XWPFTestDataSamples;
+import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
 import org.apache.xmlbeans.XmlCursor;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
 
@@ -423,4 +428,21 @@ public final class TestXWPFDocument {
                assertTrue(docx.isEnforcedProtection());
                docx.close();
        }
+       
+       @Test
+       @Ignore("XWPF should be able to write to a new Stream when opened Read-Only")
+       public void testWriteFromReadOnlyOPC() throws Exception {
+           OPCPackage opc = OPCPackage.open(
+                   POIDataSamples.getDocumentInstance().getFile("SampleDoc.docx"),
+                   PackageAccess.READ
+           );
+           XWPFDocument doc = new XWPFDocument(opc);
+           XWPFWordExtractor ext = new XWPFWordExtractor(doc);
+           String origText = ext.getText();
+           
+           doc = XWPFTestDataSamples.writeOutAndReadBack(doc);
+           ext = new XWPFWordExtractor(doc);
+           
+           assertEquals(origText, ext.getText());
+       }
 }