KickJava   Java API By Example, From Geeks To Geeks.

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


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.model;
19
20 import java.util.HashSet JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Arrays JavaDoc;
23 import java.io.IOException JavaDoc;
24
25 import org.apache.poi.hwpf.model.io.HWPFOutputStream;
26
27 import org.apache.poi.util.LittleEndian;
28
29 public class FIBFieldHandler
30 {
31   public static final int STSHFORIG = 0;
32   public static final int STSHF = 1;
33   public static final int PLCFFNDREF = 2;
34   public static final int PLCFFNDTXT = 3;
35   public static final int PLCFANDREF = 4;
36   public static final int PLCFANDTXT = 5;
37   public static final int PLCFSED = 6;
38   public static final int PLCFPAD = 7;
39   public static final int PLCFPHE = 8;
40   public static final int STTBGLSY = 9;
41   public static final int PLCFGLSY = 10;
42   public static final int PLCFHDD = 11;
43   public static final int PLCFBTECHPX = 12;
44   public static final int PLCFBTEPAPX = 13;
45   public static final int PLCFSEA = 14;
46   public static final int STTBFFFN = 15;
47   public static final int PLCFFLDMOM = 16;
48   public static final int PLCFFLDHDR = 17;
49   public static final int PLCFFLDFTN = 18;
50   public static final int PLCFFLDATN = 19;
51   public static final int PLCFFLDMCR = 20;
52   public static final int STTBFBKMK = 21;
53   public static final int PLCFBKF = 22;
54   public static final int PLCFBKL = 23;
55   public static final int CMDS = 24;
56   public static final int PLCMCR = 25;
57   public static final int STTBFMCR = 26;
58   public static final int PRDRVR = 27;
59   public static final int PRENVPORT = 28;
60   public static final int PRENVLAND = 29;
61   public static final int WSS = 30;
62   public static final int DOP = 31;
63   public static final int STTBFASSOC = 32;
64   public static final int CLX = 33;
65   public static final int PLCFPGDFTN = 34;
66   public static final int AUTOSAVESOURCE = 35;
67   public static final int GRPXSTATNOWNERS = 36;//validated
68
public static final int STTBFATNBKMK = 37;
69   public static final int PLCFDOAMOM = 38;
70   public static final int PLCDOAHDR = 39;
71   public static final int PLCSPAMOM = 40;
72   public static final int PLCSPAHDR = 41;
73   public static final int PLCFATNBKF = 42;
74   public static final int PLCFATNBKL = 43;
75   public static final int PMS = 44;
76   public static final int FORMFLDSTTBS = 45;
77   public static final int PLCFENDREF = 46;
78   public static final int PLCFENDTXT = 47;
79   public static final int PLCFFLDEDN = 48;
80   public static final int PLCFPGDEDN = 49;
81   public static final int DGGINFO = 50;
82   public static final int STTBFRMARK = 51;
83   public static final int STTBCAPTION = 52;
84   public static final int STTBAUTOCAPTION = 53;
85   public static final int PLCFWKB = 54;
86   public static final int PLCFSPL = 55;
87   public static final int PLCFTXBXTXT = 56;
88   public static final int PLCFFLDTXBX = 57;//validated
89
public static final int PLCFHDRTXBXTXT = 58;
90   public static final int PLCFFLDHDRTXBX = 59;
91   public static final int STWUSER = 60;
92   public static final int STTBTTMBD = 61;
93   public static final int UNUSED = 62;
94   public static final int PGDMOTHER = 63;
95   public static final int BKDMOTHER = 64;
96   public static final int PGDFTN = 65;
97   public static final int BKDFTN = 66;
98   public static final int PGDEDN = 67;
99   public static final int BKDEDN = 68;
100   public static final int STTBFINTFLD = 69;
101   public static final int ROUTESLIP = 70;
102   public static final int STTBSAVEDBY = 71;
103   public static final int STTBFNM = 72;
104   public static final int PLCFLST = 73;
105   public static final int PLFLFO = 74;
106   public static final int PLCFTXBXBKD = 75;//validated
107
public static final int PLCFTXBXHDRBKD = 76;
108   public static final int DOCUNDO = 77;
109   public static final int RGBUSE = 78;
110   public static final int USP = 79;
111   public static final int USKF = 80;
112   public static final int PLCUPCRGBUSE = 81;
113   public static final int PLCUPCUSP = 82;
114   public static final int STTBGLSYSTYLE = 83;
115   public static final int PLGOSL = 84;
116   public static final int PLCOCX = 85;
117   public static final int PLCFBTELVC = 86;
118   public static final int MODIFIED = 87;
119   public static final int PLCFLVC = 88;
120   public static final int PLCASUMY = 89;
121   public static final int PLCFGRAM = 90;
122   public static final int STTBLISTNAMES = 91;
123   public static final int STTBFUSSR = 92;
124
125   private static final int FIELD_SIZE = LittleEndian.INT_SIZE * 2;
126
127   private HashMap JavaDoc _unknownMap = new HashMap JavaDoc();
128   private int[] _fields;
129
130
131   public FIBFieldHandler(byte[] mainStream, int offset, byte[] tableStream,
132                          HashSet JavaDoc offsetList, boolean areKnown)
133   {
134     int numFields = LittleEndian.getShort(mainStream, offset);
135     offset += LittleEndian.SHORT_SIZE;
136     _fields = new int[numFields * 2];
137
138     for (int x = 0; x < numFields; x++)
139     {
140       int fieldOffset = (x * FIELD_SIZE) + offset;
141       int dsOffset = LittleEndian.getInt(mainStream, fieldOffset);
142       fieldOffset += LittleEndian.INT_SIZE;
143       int dsSize = LittleEndian.getInt(mainStream, fieldOffset);
144
145       if (offsetList.contains(new Integer JavaDoc(x)) ^ areKnown)
146       {
147         if (dsSize > 0)
148         {
149           UnhandledDataStructure unhandled = new UnhandledDataStructure(
150             tableStream, dsOffset, dsSize);
151           _unknownMap.put(new Integer JavaDoc(x), unhandled);
152         }
153       }
154       _fields[x*2] = dsOffset;
155       _fields[(x*2) + 1] = dsSize;
156     }
157   }
158
159   public void clearFields()
160   {
161     Arrays.fill(_fields, 0);
162   }
163
164   public int getFieldOffset(int field)
165   {
166     return _fields[field*2];
167   }
168
169   public int getFieldSize(int field)
170   {
171     return _fields[(field*2) + 1];
172   }
173
174   public void setFieldOffset(int field, int offset)
175   {
176     _fields[field*2] = offset;
177   }
178
179   public void setFieldSize(int field, int size)
180   {
181     _fields[(field*2) + 1] = size;
182   }
183
184   public int sizeInBytes()
185   {
186     return (_fields.length * LittleEndian.INT_SIZE) + LittleEndian.SHORT_SIZE;
187   }
188
189   void writeTo(byte[] mainStream, int offset, HWPFOutputStream tableStream)
190     throws IOException JavaDoc
191   {
192     int length = _fields.length/2;
193     LittleEndian.putShort(mainStream, offset, (short)length);
194     offset += LittleEndian.SHORT_SIZE;
195
196     for (int x = 0; x < length; x++)
197     {
198       UnhandledDataStructure ds = (UnhandledDataStructure)_unknownMap.get(new Integer JavaDoc(x));
199       if (ds != null)
200       {
201         LittleEndian.putInt(mainStream, offset, tableStream.getOffset());
202         offset += LittleEndian.INT_SIZE;
203         byte[] buf = ds.getBuf();
204         tableStream.write(buf);
205         LittleEndian.putInt(mainStream, offset, buf.length);
206         offset += LittleEndian.INT_SIZE;
207       }
208       else
209       {
210         LittleEndian.putInt(mainStream, offset, _fields[x * 2]);
211         offset += LittleEndian.INT_SIZE;
212         LittleEndian.putInt(mainStream, offset, _fields[(x * 2) + 1]);
213         offset += LittleEndian.INT_SIZE;
214       }
215     }
216   }
217 }
218
Popular Tags