From 81e694bbff44431f084030cc0f915dde5f86281c Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 2 Jun 2016 22:59:47 +0000 Subject: [PATCH] Add disabled test for XWPF writing to a new stream when opened read-only git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1746653 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/POIXMLDocument.java | 1 + .../poi/xwpf/usermodel/TestXWPFDocument.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/ooxml/java/org/apache/poi/POIXMLDocument.java b/src/ooxml/java/org/apache/poi/POIXMLDocument.java index 522773eb8b..1d73329a4e 100644 --- a/src/ooxml/java/org/apache/poi/POIXMLDocument.java +++ b/src/ooxml/java/org/apache/poi/POIXMLDocument.java @@ -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 context = new HashSet(); onSave(context); context.clear(); diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java index afa0428b4a..1dbba43a69 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java @@ -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()); + } } -- 2.39.5