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);
}
--- /dev/null
+/* ====================================================================
+ 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; }
+}
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;
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"));
* 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
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() {