You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2016/10/25 07:37:00 UTC

svn commit: r1766480 - in /poi/trunk/src/scratchpad: src/org/apache/poi/hdgf/pointers/ testcases/org/apache/poi/hdgf/ testcases/org/apache/poi/hdgf/pointers/

Author: nick
Date: Tue Oct 25 07:37:00 2016
New Revision: 1766480

URL: http://svn.apache.org/viewvc?rev=1766480&view=rev
Log:
Partial Visio v5 pointer support

Added:
    poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerV5.java   (with props)
Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerFactory.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/pointers/TestPointerFactory.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerFactory.java?rev=1766480&r1=1766479&r2=1766480&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerFactory.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerFactory.java Tue Oct 25 07:37:00 2016
@@ -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);
 		}

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerV5.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerV5.java?rev=1766480&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerV5.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerV5.java Tue Oct 25 07:37:00 2016
@@ -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; }
+}

Propchange: poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerV5.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java?rev=1766480&r1=1766479&r2=1766480&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java Tue Oct 25 07:37:00 2016
@@ -22,6 +22,7 @@ import org.apache.poi.hdgf.streams.Point
 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
       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"));
 

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/pointers/TestPointerFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/pointers/TestPointerFactory.java?rev=1766480&r1=1766479&r2=1766480&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/pointers/TestPointerFactory.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/pointers/TestPointerFactory.java Tue Oct 25 07:37:00 2016
@@ -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 ex
 
 	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() {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org