KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > elementprocessor > impl > poi > hssf > elements > EPRowInfo


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements;
18
19 import org.apache.cocoon.components.elementprocessor.types.Attribute;
20 import org.apache.cocoon.components.elementprocessor.types.BooleanConverter;
21 import org.apache.cocoon.components.elementprocessor.types.BooleanResult;
22 import org.apache.cocoon.components.elementprocessor.types.NumericConverter;
23 import org.apache.cocoon.components.elementprocessor.types.NumericResult;
24 import org.apache.cocoon.components.elementprocessor.types.Validator;
25
26 import java.io.IOException JavaDoc;
27
28 /**
29  * No-op implementation of ElementProcessor to handle the "RowInfo"
30  * tag
31  *
32  * This element has several attributes and has no content
33  *
34  * @author Marc Johnson (marc_johnson27591@hotmail.com)
35  * @version CVS $Id: EPRowInfo.java 30932 2004-07-29 17:35:38Z vgritsenko $
36  */

37 public class EPRowInfo extends BaseElementProcessor {
38
39     // row number
40
private NumericResult _no;
41
42     // size, in points
43
private NumericResult _unit;
44
45     // left margin, in points
46
private NumericResult _margin_a;
47
48     // right margin, in points
49
private NumericResult _margin_b;
50
51     // true if size is explicitly set
52
private BooleanResult _hard_size;
53
54     // true if row is hidden
55
private BooleanResult _hidden;
56
57     // true if row is collapsed
58
private BooleanResult _collapsed;
59
60     // outline level
61
private NumericResult _outline_level;
62
63     // rle count
64
private NumericResult _count;
65     private static final String JavaDoc _no_attribute = "No";
66     private static final String JavaDoc _unit_attribute = "Unit";
67     private static final String JavaDoc _margin_a_attribute = "MarginA";
68     private static final String JavaDoc _margin_b_attribute = "MarginB";
69     private static final String JavaDoc _hard_size_attribute = "HardSize";
70     private static final String JavaDoc _hidden_attribute = "Hidden";
71     private static final String JavaDoc _collapsed_attribute = "Collapsed";
72     private static final String JavaDoc _outline_level_attribute = "OutlineLevel";
73     private static final String JavaDoc _count_attribute = "Count";
74     private static final Validator _margin_validator = new Validator() {
75         public IOException JavaDoc validate(final Number JavaDoc number) {
76             int val = number.intValue();
77
78             return (val >= 0 && val <= 7) ? null
79                 : new IOException JavaDoc("\"" + number + "\" is not a legal value");
80         }
81     };
82     private static final Attribute[] _implied_attributes =
83         {
84             new Attribute(_hard_size_attribute, "0"),
85             new Attribute(_hidden_attribute, "0"),
86             new Attribute(_collapsed_attribute, "0"),
87             new Attribute(_outline_level_attribute, "0"),
88             new Attribute(_count_attribute, "1")};
89
90     /**
91      * constructor
92      */

93     public EPRowInfo() {
94         super(_implied_attributes);
95         _no = null;
96         _unit = null;
97         _margin_a = null;
98         _margin_b = null;
99         _hard_size = null;
100         _hidden = null;
101         _collapsed = null;
102         _outline_level = null;
103         _count = null;
104     }
105
106     /**
107      * @return row number
108      * @exception IOException
109      */

110     public int getRowNo() throws IOException JavaDoc {
111         if (_no == null) {
112             _no =
113                 NumericConverter.extractNonNegativeInteger(
114                     getValue(_no_attribute));
115         }
116         return _no.intValue();
117     }
118
119     /**
120      * @return row size in points
121      * @exception IOException
122      */

123     public double getPoints() throws IOException JavaDoc {
124         if (_unit == null) {
125             _unit = NumericConverter.extractDouble(getValue(_unit_attribute));
126         }
127         return _unit.doubleValue();
128     }
129
130     /**
131      * @return left margin
132      * @exception IOException
133      */

134     public int getLeftMargin() throws IOException JavaDoc {
135         if (_margin_a == null) {
136             _margin_a =
137                 NumericConverter.extractInteger(
138                     getValue(_margin_a_attribute),
139                     _margin_validator);
140         }
141         return _margin_a.intValue();
142     }
143
144     /**
145      * @return right margin
146      * @exception IOException
147      */

148     public int getRightMargin() throws IOException JavaDoc {
149         if (_margin_b == null) {
150             _margin_b =
151                 NumericConverter.extractInteger(
152                     getValue(_margin_b_attribute),
153                     _margin_validator);
154         }
155         return _margin_b.intValue();
156     }
157
158     /**
159      * @return hard size
160      * @exception IOException
161      */

162     public boolean getHardSize() throws IOException JavaDoc {
163         if (_hard_size == null) {
164             _hard_size =
165                 BooleanConverter.extractBoolean(getValue(_hard_size_attribute));
166         }
167         return _hard_size.booleanValue();
168     }
169
170     /**
171      * @return hidden state
172      * @exception IOException
173      */

174     public boolean getHidden() throws IOException JavaDoc {
175         if (_hidden == null) {
176             _hidden =
177                 BooleanConverter.extractBoolean(getValue(_hidden_attribute));
178         }
179         return _hidden.booleanValue();
180     }
181
182     /**
183      * @return collapsed state
184      * @exception IOException
185      */

186     public boolean getCollapsed() throws IOException JavaDoc {
187         if (_collapsed == null) {
188             _collapsed =
189                 BooleanConverter.extractBoolean(getValue(_collapsed_attribute));
190         }
191         return _collapsed.booleanValue();
192     }
193
194     /**
195      * @return outline level
196      * @exception IOException
197      */

198     public int getOutlineLevel() throws IOException JavaDoc {
199         if (_outline_level == null) {
200             _outline_level = NumericConverter.extractInteger(
201                     getValue(_outline_level_attribute));
202         }
203         return _outline_level.intValue();
204     }
205
206     /**
207      * @return rle count
208      * @exception IOException
209      */

210     public int getRLECount() throws IOException JavaDoc {
211         if (_count == null) {
212             _count =
213                 NumericConverter.extractInteger(getValue(_count_attribute));
214         }
215         return _count.intValue();
216     }
217
218     /**
219      * Set this row's height
220      * @exception IOException
221      */

222     public void endProcessing() throws IOException JavaDoc {
223         int row = getRowNo();
224
225         if (row > Short.MAX_VALUE) {
226             throw new IOException JavaDoc("Illegal row value: " + row);
227         }
228         getSheet().getRow(row).setHeight(getPoints());
229     }
230 } // end public class EPRowInfo
231
Popular Tags