001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hwpf.model;
019:
020: import java.util.HashSet;
021: import java.io.IOException;
022:
023: import org.apache.poi.hwpf.model.io.*;
024:
025: import org.apache.poi.hwpf.model.types.FIBAbstractType;
026:
027: /**
028: *
029: * @author andy
030: */
031: public class FileInformationBlock extends FIBAbstractType implements
032: Cloneable {
033:
034: FIBLongHandler _longHandler;
035: FIBShortHandler _shortHandler;
036: FIBFieldHandler _fieldHandler;
037:
038: /** Creates a new instance of FileInformationBlock */
039: public FileInformationBlock(byte[] mainDocument) {
040: fillFields(mainDocument, 0);
041: }
042:
043: public void fillVariableFields(byte[] mainDocument,
044: byte[] tableStream) {
045: HashSet fieldSet = new HashSet();
046: fieldSet.add(new Integer(FIBFieldHandler.STSHF));
047: fieldSet.add(new Integer(FIBFieldHandler.CLX));
048: fieldSet.add(new Integer(FIBFieldHandler.DOP));
049: fieldSet.add(new Integer(FIBFieldHandler.PLCFBTECHPX));
050: fieldSet.add(new Integer(FIBFieldHandler.PLCFBTEPAPX));
051: fieldSet.add(new Integer(FIBFieldHandler.PLCFSED));
052: fieldSet.add(new Integer(FIBFieldHandler.PLCFLST));
053: fieldSet.add(new Integer(FIBFieldHandler.PLFLFO));
054: fieldSet.add(new Integer(FIBFieldHandler.PLCFFLDMOM));
055: fieldSet.add(new Integer(FIBFieldHandler.STTBFFFN));
056: fieldSet.add(new Integer(FIBFieldHandler.STTBSAVEDBY));
057: fieldSet.add(new Integer(FIBFieldHandler.MODIFIED));
058:
059: _shortHandler = new FIBShortHandler(mainDocument);
060: _longHandler = new FIBLongHandler(mainDocument,
061: _shortHandler.START + _shortHandler.sizeInBytes());
062: _fieldHandler = new FIBFieldHandler(mainDocument,
063: _shortHandler.START + _shortHandler.sizeInBytes()
064: + _longHandler.sizeInBytes(), tableStream,
065: fieldSet, true);
066: }
067:
068: public int getFcDop() {
069: return _fieldHandler.getFieldOffset(FIBFieldHandler.DOP);
070: }
071:
072: public void setFcDop(int fcDop) {
073: _fieldHandler.setFieldOffset(FIBFieldHandler.DOP, fcDop);
074: }
075:
076: public int getLcbDop() {
077: return _fieldHandler.getFieldSize(FIBFieldHandler.DOP);
078: }
079:
080: public void setLcbDop(int lcbDop) {
081: _fieldHandler.setFieldSize(FIBFieldHandler.DOP, lcbDop);
082: }
083:
084: public int getFcStshf() {
085: return _fieldHandler.getFieldOffset(FIBFieldHandler.STSHF);
086: }
087:
088: public int getLcbStshf() {
089: return _fieldHandler.getFieldSize(FIBFieldHandler.STSHF);
090: }
091:
092: public void setFcStshf(int fcStshf) {
093: _fieldHandler.setFieldOffset(FIBFieldHandler.STSHF, fcStshf);
094: }
095:
096: public void setLcbStshf(int lcbStshf) {
097: _fieldHandler.setFieldSize(FIBFieldHandler.STSHF, lcbStshf);
098: }
099:
100: public int getFcClx() {
101: return _fieldHandler.getFieldOffset(FIBFieldHandler.CLX);
102: }
103:
104: public int getLcbClx() {
105: return _fieldHandler.getFieldSize(FIBFieldHandler.CLX);
106: }
107:
108: public void setFcClx(int fcClx) {
109: _fieldHandler.setFieldOffset(FIBFieldHandler.CLX, fcClx);
110: }
111:
112: public void setLcbClx(int lcbClx) {
113: _fieldHandler.setFieldSize(FIBFieldHandler.CLX, lcbClx);
114: }
115:
116: public int getFcPlcfbteChpx() {
117: return _fieldHandler
118: .getFieldOffset(FIBFieldHandler.PLCFBTECHPX);
119: }
120:
121: public int getLcbPlcfbteChpx() {
122: return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFBTECHPX);
123: }
124:
125: public void setFcPlcfbteChpx(int fcPlcfBteChpx) {
126: _fieldHandler.setFieldOffset(FIBFieldHandler.PLCFBTECHPX,
127: fcPlcfBteChpx);
128: }
129:
130: public void setLcbPlcfbteChpx(int lcbPlcfBteChpx) {
131: _fieldHandler.setFieldSize(FIBFieldHandler.PLCFBTECHPX,
132: lcbPlcfBteChpx);
133: }
134:
135: public int getFcPlcfbtePapx() {
136: return _fieldHandler
137: .getFieldOffset(FIBFieldHandler.PLCFBTEPAPX);
138: }
139:
140: public int getLcbPlcfbtePapx() {
141: return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFBTEPAPX);
142: }
143:
144: public void setFcPlcfbtePapx(int fcPlcfBtePapx) {
145: _fieldHandler.setFieldOffset(FIBFieldHandler.PLCFBTEPAPX,
146: fcPlcfBtePapx);
147: }
148:
149: public void setLcbPlcfbtePapx(int lcbPlcfBtePapx) {
150: _fieldHandler.setFieldSize(FIBFieldHandler.PLCFBTEPAPX,
151: lcbPlcfBtePapx);
152: }
153:
154: public int getFcPlcfsed() {
155: return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFSED);
156: }
157:
158: public int getLcbPlcfsed() {
159: return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFSED);
160: }
161:
162: public void setFcPlcfsed(int fcPlcfSed) {
163: _fieldHandler
164: .setFieldOffset(FIBFieldHandler.PLCFSED, fcPlcfSed);
165: }
166:
167: public void setLcbPlcfsed(int lcbPlcfSed) {
168: _fieldHandler.setFieldSize(FIBFieldHandler.PLCFSED, lcbPlcfSed);
169: }
170:
171: public int getFcPlcfLst() {
172: return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFLST);
173: }
174:
175: public int getLcbPlcfLst() {
176: return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFLST);
177: }
178:
179: public void setFcPlcfLst(int fcPlcfLst) {
180: _fieldHandler
181: .setFieldOffset(FIBFieldHandler.PLCFLST, fcPlcfLst);
182: }
183:
184: public void setLcbPlcfLst(int lcbPlcfLst) {
185: _fieldHandler.setFieldSize(FIBFieldHandler.PLCFLST, lcbPlcfLst);
186: }
187:
188: public int getFcPlfLfo() {
189: return _fieldHandler.getFieldOffset(FIBFieldHandler.PLFLFO);
190: }
191:
192: public int getLcbPlfLfo() {
193: return _fieldHandler.getFieldSize(FIBFieldHandler.PLFLFO);
194: }
195:
196: public void setFcPlfLfo(int fcPlfLfo) {
197: _fieldHandler.setFieldOffset(FIBFieldHandler.PLFLFO, fcPlfLfo);
198: }
199:
200: public void setLcbPlfLfo(int lcbPlfLfo) {
201: _fieldHandler.setFieldSize(FIBFieldHandler.PLFLFO, lcbPlfLfo);
202: }
203:
204: public int getFcSttbfffn() {
205: return _fieldHandler.getFieldOffset(FIBFieldHandler.STTBFFFN);
206: }
207:
208: public int getLcbSttbfffn() {
209: return _fieldHandler.getFieldSize(FIBFieldHandler.STTBFFFN);
210: }
211:
212: public void setFcSttbfffn(int fcSttbFffn) {
213: _fieldHandler.setFieldOffset(FIBFieldHandler.STTBFFFN,
214: fcSttbFffn);
215: }
216:
217: public void setLcbSttbfffn(int lcbSttbFffn) {
218: _fieldHandler.setFieldSize(FIBFieldHandler.STTBFFFN,
219: lcbSttbFffn);
220: }
221:
222: public int getFcSttbSavedBy() {
223: return _fieldHandler
224: .getFieldOffset(FIBFieldHandler.STTBSAVEDBY);
225: }
226:
227: public int getLcbSttbSavedBy() {
228: return _fieldHandler.getFieldSize(FIBFieldHandler.STTBSAVEDBY);
229: }
230:
231: public void setFcSttbSavedBy(int fcSttbSavedBy) {
232: _fieldHandler.setFieldOffset(FIBFieldHandler.STTBSAVEDBY,
233: fcSttbSavedBy);
234: }
235:
236: public void setLcbSttbSavedBy(int fcSttbSavedBy) {
237: _fieldHandler.setFieldSize(FIBFieldHandler.STTBSAVEDBY,
238: fcSttbSavedBy);
239: }
240:
241: public int getModifiedLow() {
242: return _fieldHandler.getFieldOffset(FIBFieldHandler.PLFLFO);
243: }
244:
245: public int getModifiedHigh() {
246: return _fieldHandler.getFieldSize(FIBFieldHandler.PLFLFO);
247: }
248:
249: public void setModifiedLow(int modifiedLow) {
250: _fieldHandler.setFieldOffset(FIBFieldHandler.PLFLFO,
251: modifiedLow);
252: }
253:
254: public void setModifiedHigh(int modifiedHigh) {
255: _fieldHandler
256: .setFieldSize(FIBFieldHandler.PLFLFO, modifiedHigh);
257: }
258:
259: public void setCbMac(int cbMac) {
260: _longHandler.setLong(FIBLongHandler.CBMAC, cbMac);
261: }
262:
263: public void clearOffsetsSizes() {
264: _fieldHandler.clearFields();
265: }
266:
267: public int getFcPlcffldMom() {
268: return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDMOM);
269: }
270:
271: public int getLcbPlcffldMom() {
272: return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDMOM);
273: }
274:
275: public void writeTo(byte[] mainStream, HWPFOutputStream tableStream)
276: throws IOException {
277: //HWPFOutputStream mainDocument = sys.getStream("WordDocument");
278: //HWPFOutputStream tableStream = sys.getStream("1Table");
279:
280: super .serialize(mainStream, 0);
281:
282: int size = super .getSize();
283: _shortHandler.serialize(mainStream);
284: _longHandler.serialize(mainStream, size
285: + _shortHandler.sizeInBytes());
286: _fieldHandler.writeTo(mainStream, super .getSize()
287: + _shortHandler.sizeInBytes()
288: + _longHandler.sizeInBytes(), tableStream);
289:
290: }
291:
292: public int getSize() {
293: return super .getSize() + _shortHandler.sizeInBytes()
294: + _longHandler.sizeInBytes()
295: + _fieldHandler.sizeInBytes();
296: }
297: // public Object clone()
298: // {
299: // try
300: // {
301: // return super.clone();
302: // }
303: // catch (CloneNotSupportedException e)
304: // {
305: // e.printStackTrace();
306: // return null;
307: // }
308: // }
309: }
|