diff --git a/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerFactory.java b/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerFactory.java index bf3a56777..ddb519cef 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerFactory.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerFactory.java @@ -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 index 000000000..23c2a6c47 --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerV5.java @@ -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; } +} diff --git a/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java b/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java index 5b7723aeb..fde1479c7 100644 --- a/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java +++ b/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java @@ -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")); diff --git a/src/scratchpad/testcases/org/apache/poi/hdgf/pointers/TestPointerFactory.java b/src/scratchpad/testcases/org/apache/poi/hdgf/pointers/TestPointerFactory.java index 54e8eccc7..60d12f0a8 100644 --- a/src/scratchpad/testcases/org/apache/poi/hdgf/pointers/TestPointerFactory.java +++ b/src/scratchpad/testcases/org/apache/poi/hdgf/pointers/TestPointerFactory.java @@ -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() {