KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hwpf > HWPFDocFixture


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        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 JavaDoc;
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 JavaDoc;
27
28
29 public class HWPFDocFixture
30 {
31   public byte[] _tableStream;
32   public byte[] _mainStream;
33   public FileInformationBlock _fib;
34
35   public HWPFDocFixture(Object JavaDoc obj)
36   {
37
38   }
39
40   public void setUp()
41   {
42     try
43     {
44       String JavaDoc filename = System.getProperty("HWPF.testdata.path");
45       if (filename == null)
46       {
47         filename = "c:";
48       }
49
50       filename = filename + "/blankplus.doc";
51
52
53       POIFSFileSystem filesystem = new POIFSFileSystem(new FileInputStream JavaDoc(
54         new File JavaDoc(filename)));
55
56       DocumentEntry documentProps =
57         (DocumentEntry) filesystem.getRoot().getEntry("WordDocument");
58       _mainStream = new byte[documentProps.getSize()];
59       filesystem.createDocumentInputStream("WordDocument").read(_mainStream);
60
61       // use the fib to determine the name of the table stream.
62
_fib = new FileInformationBlock(_mainStream);
63
64       String JavaDoc name = "0Table";
65       if (_fib.isFWhichTblStm())
66       {
67         name = "1Table";
68       }
69
70       // read in the table stream.
71
DocumentEntry tableProps =
72         (DocumentEntry) filesystem.getRoot().getEntry(name);
73       _tableStream = new byte[tableProps.getSize()];
74       filesystem.createDocumentInputStream(name).read(_tableStream);
75
76       _fib.fillVariableFields(_mainStream, _tableStream);
77     }
78     catch (Throwable JavaDoc t)
79     {
80       t.printStackTrace();
81     }
82   }
83
84   public void tearDown()
85   {
86   }
87
88 }
89
Popular Tags