]> source.dussan.org Git - poi.git/commitdiff
Partial Visio v5 pointer support
authorNick Burch <nick@apache.org>
Tue, 25 Oct 2016 07:37:00 +0000 (07:37 +0000)
committerNick Burch <nick@apache.org>
Tue, 25 Oct 2016 07:37:00 +0000 (07:37 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1766480 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerFactory.java
src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerV5.java [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java
src/scratchpad/testcases/org/apache/poi/hdgf/pointers/TestPointerFactory.java

index bf3a567778dbc9ebb07fe42d8dbb2b7bd21f8610..ddb519cef794bf0762f30c0372bbd36a7dce0223 100644 (file)
@@ -42,7 +42,14 @@ public final class PointerFactory {
 
                        return p;
                } else if(version == 5) {
-                       throw new RuntimeException("TODO Support v5 Pointers");
+            p = new PointerV5();
+            p.type = LittleEndian.getShort(data, offset+0);
+            p.format = LittleEndian.getShort(data, offset+2);
+            p.address = (int)LittleEndian.getUInt(data, offset+4);
+            p.offset = (int)LittleEndian.getUInt(data, offset+8);
+            p.length = (int)LittleEndian.getUInt(data, offset+12);
+
+            return p;
                } else {
                        throw new IllegalArgumentException("Visio files with versions below 5 are not supported, yours was " + version);
                }
diff --git a/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerV5.java b/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerV5.java
new file mode 100644 (file)
index 0000000..23c2a6c
--- /dev/null
@@ -0,0 +1,46 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hdgf.pointers;
+
+/**
+ * A Pointer from v5
+ */
+public final class PointerV5 extends Pointer {
+    // TODO Are these getters correct?
+       public boolean destinationHasStrings() {
+               return (0x40 <= format && format < 0x50);
+       }
+       public boolean destinationHasPointers() {
+               if(type == 20) return true;
+               if(format == 0x1d || format == 0x1e) return true;
+               return (0x50 <= format && format < 0x60);
+       }
+       public boolean destinationHasChunks() {
+               return (0xd0 <= format && format < 0xdf);
+       }
+
+       public boolean destinationCompressed() {
+               // Apparently, it's the second least significant bit
+               return (format & 2) > 0;
+       }
+
+       /**
+        * With v6 pointers, the on-disk size is 16 bytes
+        */
+       public int getSizeInBytes() { return 16; }
+}
index 5b7723aebe1145045468e1d6042b0b255abb1c2a..fde1479c758de426f84cbff9cf7587c30a43fafb 100644 (file)
@@ -22,6 +22,7 @@ import org.apache.poi.hdgf.streams.PointerContainingStream;
 import org.apache.poi.hdgf.streams.TrailerStream;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.POIDataSamples;
+import org.junit.Ignore;
 
 import junit.framework.TestCase;
 
@@ -91,6 +92,21 @@ public final class TestHDGFCore extends TestCase {
       assertNotNull(hdgf);
        }
 
+       /**
+        * TODO: V5 support is incomplete
+        */
+    public void TODOtestV5() throws Exception {
+        fs = new POIFSFileSystem(_dgTests.openResourceAsStream("v5_Connection_Types.vsd"));
+
+        HDGFDiagram hdgf = new HDGFDiagram(fs);
+        assertNotNull(hdgf);
+
+        VisioTextExtractor textExtractor = new VisioTextExtractor(hdgf);
+        String text = textExtractor.getText().replace("\u0000", "").trim();
+
+        assertEquals("Static to Static\n\nDynamic to Dynamic\n\nDynamic to Static", text);
+    }
+
     public void testV6NonUtf16LE() throws Exception {
                fs = new POIFSFileSystem(_dgTests.openResourceAsStream("v6-non-utf16le.vsd"));
 
index 54e8eccc7f4b20c6e30544011e1543c2d8686d90..60d12f0a8e61913392a40ad6f41ce10dc8139894 100644 (file)
@@ -23,6 +23,12 @@ import junit.framework.TestCase;
  * Tests for the pointer factory, and the pointers themselves
  */
 public final class TestPointerFactory extends TestCase {
+    // Type: 14    Addr: 011eb2ac  Offset: 1dd4    Len:  14d   Format: 52  From: 24
+    private static byte[] vp5_a = new byte[] {
+        0x14, 0, 0x52, 0, (byte)0xac, (byte)0xb2, 0x1e, 1, (byte)0xd4, 0x1d, 0, 0,
+        0x4d, 1, 0, 0
+    };
+    
        // Type: 16   Addr: 0143aff4  Offset: 80   Len: 54   Format: 46   From: 8a94
        private static byte[] vp6_a = new byte[] {
                22, 0, 0, 0, -12, -81, 67, 1, -128, 0, 0, 0, 84, 0, 0, 0, 70, 0
@@ -52,13 +58,21 @@ public final class TestPointerFactory extends TestCase {
 
        public void testCreateV5() {
                PointerFactory pf = new PointerFactory(5);
-               try {
-                       pf.createPointer(new byte[]{}, 0);
-                       fail();
-               } catch(RuntimeException e) {
-                       // Still to do
-                       assertEquals("TODO Support v5 Pointers", e.getMessage());
-               }
+               
+        Pointer a = pf.createPointer(vp5_a, 0);
+        assertEquals(0x14, a.getType());
+        assertEquals(0x011eb2ac, a.getAddress());
+        assertEquals(0x1dd4, a.getOffset());
+        assertEquals(0x14d, a.getLength());
+        assertEquals(0x52, a.getFormat());
+
+        // TODO Are these right?
+        assertTrue(a.destinationCompressed());
+        assertFalse(a.destinationHasStrings());
+        assertFalse(a.destinationHasChunks());
+        assertTrue(a.destinationHasPointers());
+
+        assertEquals(16, a.getSizeInBytes());
        }
 
        public void testCreateV6() {