01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17: package org.apache.poi.hdgf.chunks;
18:
19: import org.apache.poi.util.LittleEndian;
20:
21: /**
22: * A chunk header
23: */
24: public abstract class ChunkHeader {
25: protected int type;
26: protected int id;
27: protected int length;
28: protected int unknown1;
29:
30: /**
31: * Creates the appropriate ChunkHeader for the Chunk Header at
32: * the given location, for the given document version.
33: */
34: public static ChunkHeader createChunkHeader(int documentVersion,
35: byte[] data, int offset) {
36: if (documentVersion >= 6) {
37: ChunkHeaderV6 ch;
38: if (documentVersion > 6) {
39: ch = new ChunkHeaderV11();
40: } else {
41: ch = new ChunkHeaderV6();
42: }
43: ch.type = (int) LittleEndian.getUInt(data, offset + 0);
44: ch.id = (int) LittleEndian.getUInt(data, offset + 4);
45: ch.unknown1 = (int) LittleEndian.getUInt(data, offset + 8);
46: ch.length = (int) LittleEndian.getUInt(data, offset + 12);
47: ch.unknown2 = LittleEndian.getShort(data, offset + 16);
48: ch.unknown3 = (short) LittleEndian.getUnsignedByte(data,
49: offset + 18);
50:
51: return ch;
52: } else if (documentVersion == 5) {
53: throw new RuntimeException("TODO");
54: } else {
55: throw new IllegalArgumentException(
56: "Visio files with versions below 5 are not supported, yours was "
57: + documentVersion);
58: }
59: }
60:
61: public abstract int getSizeInBytes();
62:
63: public abstract boolean hasTrailer();
64:
65: public abstract boolean hasSeparator();
66:
67: /**
68: * Returns the ID/IX of the chunk
69: */
70: public int getId() {
71: return id;
72: }
73:
74: /**
75: * Returns the length of the trunk, excluding the length
76: * of the header, trailer or separator.
77: */
78: public int getLength() {
79: return length;
80: }
81:
82: /**
83: * Returns the type of the chunk, which affects the
84: * mandatory information
85: */
86: public int getType() {
87: return type;
88: }
89:
90: public int getUnknown1() {
91: return unknown1;
92: }
93: }
|