]> source.dussan.org Git - poi.git/commitdiff
Patch from rojotek from github-18 - Handle documents with a picture-only header
authorNick Burch <nick@apache.org>
Tue, 24 Feb 2015 12:09:30 +0000 (12:09 +0000)
committerNick Burch <nick@apache.org>
Tue, 24 Feb 2015 12:09:30 +0000 (12:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1661908 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
test-data/document/zero-length.docx [new file with mode: 0644]

index 9adc397048c839e08265265ff747aa492e545552..6a28db2a87062ffdeca3fac5447e20ea830af949 100644 (file)
@@ -92,7 +92,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
     /**
      * Keeps track on all id-values used in this document and included parts, like headers, footers, etc.
      */
-    private IdentifierManager drawingIdManager = new IdentifierManager(1L,4294967295L);
+    private IdentifierManager drawingIdManager = new IdentifierManager(0L,4294967295L);
     protected List<XWPFFooter> footers = new ArrayList<XWPFFooter>();
     protected List<XWPFHeader> headers = new ArrayList<XWPFHeader>();
     protected List<XWPFComment> comments = new ArrayList<XWPFComment>();
index 7621404b8d08c504d66b7a244c6e852bafb47cd8..85da27b9e6b04fdec99652c840288884c32a874b 100644 (file)
@@ -337,6 +337,21 @@ public final class TestXWPFDocument extends TestCase {
            
            doc.getPackage().revert();
        }
+    public void testZeroLengthLibreOfficeDocumentWithWaterMarkHeader() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("zero-length.docx");
+        POIXMLProperties properties = doc.getProperties();
+
+        assertNotNull(properties.getCoreProperties());
+
+        XWPFHeader headerArray = doc.getHeaderArray(0);
+        assertEquals(1, headerArray.getAllPictures().size());
+        assertEquals("image1.png", headerArray.pictures.get(0).getFileName());
+        assertEquals("", headerArray.getText());
+
+        POIXMLProperties.ExtendedProperties extendedProperties = properties.getExtendedProperties();
+        assertNotNull(extendedProperties);
+        assertEquals(0, extendedProperties.getUnderlyingProperties().getCharacters());
+    }
 
     public void testSettings(){
         XWPFSettings settings = new XWPFSettings();
diff --git a/test-data/document/zero-length.docx b/test-data/document/zero-length.docx
new file mode 100644 (file)
index 0000000..eb34b47
Binary files /dev/null and b/test-data/document/zero-length.docx differ