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.pointers;
18:
19: import org.apache.poi.util.LittleEndian;
20:
21: /**
22: * Factor class to create the appropriate pointers, based on the version
23: * of the file
24: */
25: public class PointerFactory {
26: private int version;
27:
28: public PointerFactory(int version) {
29: this .version = version;
30: }
31:
32: public int getVersion() {
33: return version;
34: }
35:
36: public Pointer createPointer(byte[] data, int offset) {
37: Pointer p;
38: if (version >= 6) {
39: p = new PointerV6();
40: p.type = LittleEndian.getInt(data, offset + 0);
41: p.address = (int) LittleEndian.getUInt(data, offset + 4);
42: p.offset = (int) LittleEndian.getUInt(data, offset + 8);
43: p.length = (int) LittleEndian.getUInt(data, offset + 12);
44: p.format = LittleEndian.getShort(data, offset + 16);
45:
46: return p;
47: } else if (version == 5) {
48: throw new RuntimeException("TODO");
49: } else {
50: throw new IllegalArgumentException(
51: "Visio files with versions below 5 are not supported, yours was "
52: + version);
53: }
54: }
55: }
|