KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.poi.util.LittleEndian;
22
23 /**
24  * Represents an FKP data structure. This data structure is used to store the
25  * grpprls of the paragraph and character properties of the document. A grpprl
26  * is a list of sprms(decompression operations) to perform on a parent style.
27  *
28  * The style properties for paragraph and character runs
29  * are stored in fkps. There are PAP fkps for paragraph properties and CHP fkps
30  * for character run properties. The first part of the fkp for both CHP and PAP
31  * fkps consists of an array of 4 byte int offsets in the main stream for that
32  * Paragraph's or Character run's text. The ending offset is the next
33  * value in the array. For example, if an fkp has X number of Paragraph's
34  * stored in it then there are (x + 1) 4 byte ints in the beginning array. The
35  * number X is determined by the last byte in a 512 byte fkp.
36  *
37  * CHP and PAP fkps also store the compressed styles(grpprl) that correspond to
38  * the offsets on the front of the fkp. The offset of the grpprls is determined
39  * differently for CHP fkps and PAP fkps.
40  *
41  * @author Ryan Ackley
42  */

43 public abstract class FormattedDiskPage
44 {
45     protected byte[] _fkp;
46     protected int _crun;
47     protected int _offset;
48
49
50     public FormattedDiskPage()
51     {
52
53     }
54
55     /**
56      * Uses a 512-byte array to create a FKP
57      */

58     public FormattedDiskPage(byte[] documentStream, int offset)
59     {
60         _crun = LittleEndian.getUnsignedByte(documentStream, offset + 511);
61         _fkp = documentStream;
62         _offset = offset;
63     }
64     /**
65      * Used to get a text offset corresponding to a grpprl in this fkp.
66      * @param index The index of the property in this FKP
67      * @return an int representing an offset in the "WordDocument" stream
68      */

69     protected int getStart(int index)
70     {
71         return LittleEndian.getInt(_fkp, _offset + (index * 4));
72     }
73     /**
74      * Used to get the end of the text corresponding to a grpprl in this fkp.
75      * @param index The index of the property in this fkp.
76      * @return an int representing an offset in the "WordDocument" stream
77      */

78     protected int getEnd(int index)
79     {
80         return LittleEndian.getInt(_fkp, _offset + ((index + 1) * 4));
81     }
82     /**
83      * Used to get the total number of grrprl's stored int this FKP
84      * @return The number of grpprls in this FKP
85      */

86     public int size()
87     {
88         return _crun;
89     }
90
91     protected abstract byte[] getGrpprl(int index);
92 }
93
Popular Tags