001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017: package org.apache.poi.hdgf.dev;
018:
019: import java.io.FileInputStream;
020:
021: import org.apache.poi.hdgf.HDGFDiagram;
022: import org.apache.poi.hdgf.chunks.Chunk;
023: import org.apache.poi.hdgf.chunks.Chunk.Command;
024: import org.apache.poi.hdgf.pointers.Pointer;
025: import org.apache.poi.hdgf.streams.ChunkStream;
026: import org.apache.poi.hdgf.streams.PointerContainingStream;
027: import org.apache.poi.hdgf.streams.Stream;
028: import org.apache.poi.poifs.filesystem.POIFSFileSystem;
029:
030: /**
031: * Developer helper class to dump out the pointer+stream structure
032: * of a Visio file
033: */
034: public class VSDDumper {
035: public static void main(String[] args) throws Exception {
036: if (args.length == 0) {
037: System.err.println("Use:");
038: System.err.println(" VSDDumper <filename>");
039: System.exit(1);
040: }
041:
042: HDGFDiagram hdgf = new HDGFDiagram(new POIFSFileSystem(
043: new FileInputStream(args[0])));
044:
045: System.out.println("Opened " + args[0]);
046: System.out.println("The document claims a size of "
047: + hdgf.getDocumentSize() + " ("
048: + Long.toHexString(hdgf.getDocumentSize()) + ")");
049: System.out.println();
050:
051: dumpStream(hdgf.getTrailerStream(), 0);
052: }
053:
054: public static void dumpStream(Stream stream, int indent) {
055: String ind = "";
056: for (int i = 0; i < indent; i++) {
057: ind += " ";
058: }
059: String ind2 = ind + " ";
060: String ind3 = ind2 + " ";
061:
062: Pointer ptr = stream.getPointer();
063: System.out.println(ind + "Stream at\t" + ptr.getOffset()
064: + " - " + Integer.toHexString(ptr.getOffset()));
065: System.out.println(ind + " Type is\t" + ptr.getType() + " - "
066: + Integer.toHexString(ptr.getType()));
067: System.out.println(ind + " Format is\t" + ptr.getFormat()
068: + " - " + Integer.toHexString(ptr.getFormat()));
069: System.out.println(ind + " Length is\t" + ptr.getLength()
070: + " - " + Integer.toHexString(ptr.getLength()));
071: if (ptr.destinationCompressed()) {
072: int decompLen = stream._getContentsLength();
073: System.out.println(ind + " DC.Length is\t" + decompLen
074: + " - " + Integer.toHexString(decompLen));
075: }
076: System.out.println(ind + " Compressed is\t"
077: + ptr.destinationCompressed());
078: System.out.println(ind + " Stream is\t"
079: + stream.getClass().getName());
080:
081: byte[] db = stream._getStore()._getContents();
082: String ds = "";
083: if (db.length >= 8) {
084: for (int i = 0; i < 8; i++) {
085: if (i > 0)
086: ds += ", ";
087: ds += db[i];
088: }
089: }
090: System.out.println(ind + " First few bytes are\t" + ds);
091:
092: if (stream instanceof PointerContainingStream) {
093: PointerContainingStream pcs = (PointerContainingStream) stream;
094: System.out.println(ind + " Has "
095: + pcs.getPointedToStreams().length + " children:");
096:
097: for (int i = 0; i < pcs.getPointedToStreams().length; i++) {
098: dumpStream(pcs.getPointedToStreams()[i], (indent + 1));
099: }
100: }
101: if (stream instanceof ChunkStream) {
102: ChunkStream cs = (ChunkStream) stream;
103: System.out.println(ind + " Has " + cs.getChunks().length
104: + " chunks:");
105:
106: for (int i = 0; i < cs.getChunks().length; i++) {
107: Chunk chunk = cs.getChunks()[i];
108: System.out.println(ind2 + "" + chunk.getName());
109: System.out
110: .println(ind2
111: + " Length is "
112: + chunk._getContents().length
113: + " ("
114: + Integer.toHexString(chunk
115: ._getContents().length) + ")");
116: System.out.println(ind2 + " OD Size is "
117: + chunk.getOnDiskSize() + " ("
118: + Integer.toHexString(chunk.getOnDiskSize())
119: + ")");
120: System.out.println(ind2 + " T / S is "
121: + chunk.getTrailer() + " / "
122: + chunk.getSeparator());
123: System.out.println(ind2 + " Holds "
124: + chunk.getCommands().length + " commands");
125: for (int j = 0; j < chunk.getCommands().length; j++) {
126: Command command = chunk.getCommands()[j];
127: System.out.println(ind3 + ""
128: + command.getDefinition().getName() + " "
129: + command.getValue());
130: }
131: }
132: }
133: }
134: }
|