KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.ByteArrayOutputStream JavaDoc;
21 import java.util.Arrays JavaDoc;
22
23 import org.apache.poi.hwpf.sprm.SprmBuffer;
24
25 /**
26  * Represents a lightweight node in the Trees used to store content
27  * properties.
28  *
29  * @author Ryan Ackley
30  */

31 public abstract class PropertyNode implements Comparable JavaDoc, Cloneable JavaDoc
32 {
33   protected Object JavaDoc _buf;
34   private int _cpStart;
35   private int _cpEnd;
36
37
38   /**
39    * @param fcStart The start of the text for this property.
40    * @param fcEnd The end of the text for this property.
41    * @param buf FIXME: Old documentation is: "grpprl The property description in compressed form."
42    */

43   protected PropertyNode(int fcStart, int fcEnd, Object JavaDoc buf)
44   {
45       _cpStart = fcStart;
46       _cpEnd = fcEnd;
47       _buf = buf;
48
49   }
50
51   /**
52    * @return The offset of this property's text.
53    */

54   public int getStart()
55   {
56       return _cpStart;
57   }
58
59   public void setStart(int start)
60   {
61     _cpStart = start;
62   }
63
64   /**
65    * @return The offset of the end of this property's text.
66    */

67   public int getEnd()
68   {
69     return _cpEnd;
70   }
71
72   public void setEnd(int end)
73   {
74     _cpEnd = end;
75   }
76
77   /**
78    * Adjust for a deletion that can span multiple PropertyNodes.
79    * @param start
80    * @param length
81    */

82   public void adjustForDelete(int start, int length)
83   {
84     int end = start + length;
85
86     if (_cpEnd > start)
87     {
88       if (_cpStart < end)
89       {
90         _cpEnd = end >= _cpEnd ? start : _cpEnd - length;
91         _cpStart = Math.min(start, _cpStart);
92       }
93       else
94       {
95         _cpEnd -= length;
96         _cpStart -= length;
97       }
98     }
99   }
100
101   protected boolean limitsAreEqual(Object JavaDoc o)
102   {
103     return ((PropertyNode)o).getStart() == _cpStart &&
104            ((PropertyNode)o).getEnd() == _cpEnd;
105
106   }
107
108   public boolean equals(Object JavaDoc o)
109   {
110     if (limitsAreEqual(o))
111     {
112       Object JavaDoc testBuf = ((PropertyNode)o)._buf;
113       if (testBuf instanceof byte[] && _buf instanceof byte[])
114       {
115         return Arrays.equals((byte[])testBuf, (byte[])_buf);
116       }
117       return _buf.equals(testBuf);
118     }
119     return false;
120   }
121
122   public Object JavaDoc clone()
123     throws CloneNotSupportedException JavaDoc
124   {
125     return super.clone();
126   }
127
128   /**
129    * Used for sorting in collections.
130    */

131   public int compareTo(Object JavaDoc o)
132   {
133       int cpEnd = ((PropertyNode)o).getEnd();
134       if(_cpEnd == cpEnd)
135       {
136         return 0;
137       }
138       else if(_cpEnd < cpEnd)
139       {
140         return -1;
141       }
142       else
143       {
144         return 1;
145       }
146   }
147
148
149
150
151
152 }
153
Popular Tags