KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hwpf > model > FileInformationBlock


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
19 package org.apache.poi.hwpf.model;
20
21 import java.lang.reflect.AccessibleObject JavaDoc;
22 import java.lang.reflect.Field JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.io.IOException JavaDoc;
25
26 import org.apache.poi.util.BitField;
27 import org.apache.poi.util.LittleEndian;
28 import org.apache.poi.hwpf.model.io.*;
29
30
31 import org.apache.poi.hwpf.model.types.FIBAbstractType;
32
33 /**
34  *
35  * @author andy
36  */

37 public class FileInformationBlock extends FIBAbstractType
38   implements Cloneable JavaDoc
39 {
40
41     FIBLongHandler _longHandler;
42     FIBShortHandler _shortHandler;
43     FIBFieldHandler _fieldHandler;
44
45     /** Creates a new instance of FileInformationBlock */
46     public FileInformationBlock(byte[] mainDocument)
47     {
48         fillFields(mainDocument, 0);
49     }
50
51     public void fillVariableFields(byte[] mainDocument, byte[] tableStream)
52     {
53       HashSet JavaDoc fieldSet = new HashSet JavaDoc();
54       fieldSet.add(new Integer JavaDoc(FIBFieldHandler.STSHF));
55       fieldSet.add(new Integer JavaDoc(FIBFieldHandler.CLX));
56       fieldSet.add(new Integer JavaDoc(FIBFieldHandler.DOP));
57       fieldSet.add(new Integer JavaDoc(FIBFieldHandler.PLCFBTECHPX));
58       fieldSet.add(new Integer JavaDoc(FIBFieldHandler.PLCFBTEPAPX));
59       fieldSet.add(new Integer JavaDoc(FIBFieldHandler.PLCFSED));
60       fieldSet.add(new Integer JavaDoc(FIBFieldHandler.PLCFLST));
61       fieldSet.add(new Integer JavaDoc(FIBFieldHandler.PLFLFO));
62       fieldSet.add(new Integer JavaDoc(FIBFieldHandler.PLCFFLDMOM));
63       fieldSet.add(new Integer JavaDoc(FIBFieldHandler.STTBFFFN));
64       fieldSet.add(new Integer JavaDoc(FIBFieldHandler.MODIFIED));
65
66
67       _shortHandler = new FIBShortHandler(mainDocument);
68       _longHandler = new FIBLongHandler(mainDocument, _shortHandler.START + _shortHandler.sizeInBytes());
69       _fieldHandler = new FIBFieldHandler(mainDocument,
70                                           _shortHandler.START + _shortHandler.sizeInBytes() + _longHandler.sizeInBytes(),
71                                           tableStream, fieldSet, true);
72     }
73
74     public int getFcDop()
75     {
76       return _fieldHandler.getFieldOffset(FIBFieldHandler.DOP);
77     }
78
79     public void setFcDop(int fcDop)
80     {
81       _fieldHandler.setFieldOffset(FIBFieldHandler.DOP, fcDop);
82     }
83
84     public int getLcbDop()
85     {
86       return _fieldHandler.getFieldSize(FIBFieldHandler.DOP);
87     }
88
89     public void setLcbDop(int lcbDop)
90     {
91       _fieldHandler.setFieldSize(FIBFieldHandler.DOP, lcbDop);
92     }
93
94     public int getFcStshf()
95     {
96       return _fieldHandler.getFieldOffset(FIBFieldHandler.STSHF);
97     }
98
99     public int getLcbStshf()
100     {
101       return _fieldHandler.getFieldSize(FIBFieldHandler.STSHF);
102     }
103
104     public void setFcStshf(int fcStshf)
105     {
106       _fieldHandler.setFieldOffset(FIBFieldHandler.STSHF, fcStshf);
107     }
108
109     public void setLcbStshf(int lcbStshf)
110     {
111       _fieldHandler.setFieldSize(FIBFieldHandler.STSHF, lcbStshf);
112     }
113
114     public int getFcClx()
115     {
116       return _fieldHandler.getFieldOffset(FIBFieldHandler.CLX);
117     }
118
119     public int getLcbClx()
120     {
121       return _fieldHandler.getFieldSize(FIBFieldHandler.CLX);
122     }
123
124     public void setFcClx(int fcClx)
125     {
126       _fieldHandler.setFieldOffset(FIBFieldHandler.CLX, fcClx);
127     }
128
129     public void setLcbClx(int lcbClx)
130     {
131       _fieldHandler.setFieldSize(FIBFieldHandler.CLX, lcbClx);
132     }
133
134     public int getFcPlcfbteChpx()
135     {
136       return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFBTECHPX);
137     }
138
139     public int getLcbPlcfbteChpx()
140     {
141       return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFBTECHPX);
142     }
143
144     public void setFcPlcfbteChpx(int fcPlcfBteChpx)
145     {
146       _fieldHandler.setFieldOffset(FIBFieldHandler.PLCFBTECHPX, fcPlcfBteChpx);
147     }
148
149     public void setLcbPlcfbteChpx(int lcbPlcfBteChpx)
150     {
151       _fieldHandler.setFieldSize(FIBFieldHandler.PLCFBTECHPX, lcbPlcfBteChpx);
152     }
153
154     public int getFcPlcfbtePapx()
155     {
156       return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFBTEPAPX);
157     }
158
159     public int getLcbPlcfbtePapx()
160     {
161       return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFBTEPAPX);
162     }
163
164     public void setFcPlcfbtePapx(int fcPlcfBtePapx)
165     {
166       _fieldHandler.setFieldOffset(FIBFieldHandler.PLCFBTEPAPX, fcPlcfBtePapx);
167     }
168
169     public void setLcbPlcfbtePapx(int lcbPlcfBtePapx)
170     {
171       _fieldHandler.setFieldSize(FIBFieldHandler.PLCFBTEPAPX, lcbPlcfBtePapx);
172     }
173
174     public int getFcPlcfsed()
175     {
176       return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFSED);
177     }
178
179     public int getLcbPlcfsed()
180     {
181       return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFSED);
182     }
183
184     public void setFcPlcfsed(int fcPlcfSed)
185     {
186       _fieldHandler.setFieldOffset(FIBFieldHandler.PLCFSED, fcPlcfSed);
187     }
188
189     public void setLcbPlcfsed(int lcbPlcfSed)
190     {
191       _fieldHandler.setFieldSize(FIBFieldHandler.PLCFSED, lcbPlcfSed);
192     }
193
194     public int getFcPlcfLst()
195     {
196       return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFLST);
197     }
198
199     public int getLcbPlcfLst()
200     {
201       return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFLST);
202     }
203
204     public void setFcPlcfLst(int fcPlcfLst)
205     {
206       _fieldHandler.setFieldOffset(FIBFieldHandler.PLCFLST, fcPlcfLst);
207     }
208
209     public void setLcbPlcfLst(int lcbPlcfLst)
210     {
211       _fieldHandler.setFieldSize(FIBFieldHandler.PLCFLST, lcbPlcfLst);
212     }
213
214     public int getFcPlfLfo()
215     {
216       return _fieldHandler.getFieldOffset(FIBFieldHandler.PLFLFO);
217     }
218
219     public int getLcbPlfLfo()
220     {
221       return _fieldHandler.getFieldSize(FIBFieldHandler.PLFLFO);
222     }
223
224     public void setFcPlfLfo(int fcPlfLfo)
225     {
226       _fieldHandler.setFieldOffset(FIBFieldHandler.PLFLFO, fcPlfLfo);
227     }
228
229     public void setLcbPlfLfo(int lcbPlfLfo)
230     {
231       _fieldHandler.setFieldSize(FIBFieldHandler.PLFLFO, lcbPlfLfo);
232     }
233
234     public int getFcSttbfffn()
235     {
236       return _fieldHandler.getFieldOffset(FIBFieldHandler.STTBFFFN);
237     }
238
239     public int getLcbSttbfffn()
240     {
241       return _fieldHandler.getFieldSize(FIBFieldHandler.STTBFFFN);
242     }
243
244     public void setFcSttbfffn(int fcSttbFffn)
245     {
246       _fieldHandler.setFieldOffset(FIBFieldHandler.STTBFFFN, fcSttbFffn);
247     }
248
249     public void setLcbSttbfffn(int lcbSttbFffn)
250     {
251       _fieldHandler.setFieldSize(FIBFieldHandler.STTBFFFN, lcbSttbFffn);
252     }
253
254     public int getModifiedLow()
255     {
256       return _fieldHandler.getFieldOffset(FIBFieldHandler.PLFLFO);
257     }
258
259     public int getModifiedHigh()
260     {
261       return _fieldHandler.getFieldSize(FIBFieldHandler.PLFLFO);
262     }
263
264     public void setModifiedLow(int modifiedLow)
265     {
266       _fieldHandler.setFieldOffset(FIBFieldHandler.PLFLFO, modifiedLow);
267     }
268
269     public void setModifiedHigh(int modifiedHigh)
270     {
271       _fieldHandler.setFieldSize(FIBFieldHandler.PLFLFO, modifiedHigh);
272     }
273
274     public void setCbMac(int cbMac)
275     {
276       _longHandler.setLong(FIBLongHandler.CBMAC, cbMac);
277     }
278
279     public void clearOffsetsSizes()
280     {
281       _fieldHandler.clearFields();
282     }
283
284     public int getFcPlcffldMom()
285     {
286       return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDMOM);
287     }
288
289     public int getLcbPlcffldMom()
290     {
291       return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDMOM);
292     }
293
294     public void writeTo (byte[] mainStream, HWPFOutputStream tableStream)
295       throws IOException JavaDoc
296     {
297       //HWPFOutputStream mainDocument = sys.getStream("WordDocument");
298
//HWPFOutputStream tableStream = sys.getStream("1Table");
299

300       super.serialize(mainStream, 0);
301
302       int size = super.getSize();
303       _shortHandler.serialize(mainStream);
304       _longHandler.serialize(mainStream, size + _shortHandler.sizeInBytes());
305       _fieldHandler.writeTo(mainStream,
306         super.getSize() + _shortHandler.sizeInBytes() + _longHandler.sizeInBytes(), tableStream);
307
308     }
309
310     public int getSize()
311     {
312       return super.getSize() + _shortHandler.sizeInBytes() +
313         _longHandler.sizeInBytes() + _fieldHandler.sizeInBytes();
314     }
315 // public Object clone()
316
// {
317
// try
318
// {
319
// return super.clone();
320
// }
321
// catch (CloneNotSupportedException e)
322
// {
323
// e.printStackTrace();
324
// return null;
325
// }
326
// }
327
}
328
329
Popular Tags