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:
18: package org.apache.poi.hwpf;
19:
20: import java.io.FileInputStream;
21:
22: import org.apache.poi.poifs.filesystem.POIFSFileSystem;
23: import org.apache.poi.poifs.filesystem.DocumentEntry;
24:
25: import org.apache.poi.hwpf.model.*;
26: import java.io.File;
27:
28: public class HWPFDocFixture {
29: public byte[] _tableStream;
30: public byte[] _mainStream;
31: public FileInformationBlock _fib;
32:
33: public HWPFDocFixture(Object obj) {
34:
35: }
36:
37: public void setUp() {
38: try {
39: String filename = System.getProperty("HWPF.testdata.path");
40: if (filename == null) {
41: filename = "c:";
42: }
43:
44: filename = filename + "/test.doc";
45:
46: POIFSFileSystem filesystem = new POIFSFileSystem(
47: new FileInputStream(new File(filename)));
48:
49: DocumentEntry documentProps = (DocumentEntry) filesystem
50: .getRoot().getEntry("WordDocument");
51: _mainStream = new byte[documentProps.getSize()];
52: filesystem.createDocumentInputStream("WordDocument").read(
53: _mainStream);
54:
55: // use the fib to determine the name of the table stream.
56: _fib = new FileInformationBlock(_mainStream);
57:
58: String name = "0Table";
59: if (_fib.isFWhichTblStm()) {
60: name = "1Table";
61: }
62:
63: // read in the table stream.
64: DocumentEntry tableProps = (DocumentEntry) filesystem
65: .getRoot().getEntry(name);
66: _tableStream = new byte[tableProps.getSize()];
67: filesystem.createDocumentInputStream(name).read(
68: _tableStream);
69:
70: _fib.fillVariableFields(_mainStream, _tableStream);
71: } catch (Throwable t) {
72: t.printStackTrace();
73: }
74: }
75:
76: public void tearDown() {
77: }
78:
79: }
|