KickJava   Java API By Example, From Geeks To Geeks.

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


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 "ColInfo"
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: EPColInfo.java 30932 2004-07-29 17:35:38Z vgritsenko $
36  */

37 public class EPColInfo extends BaseElementProcessor {
38
39     // column number
40
private NumericResult _no;
41
42     // size, in points
43
private NumericResult _unit;
44
45     // top margin, in points
46
private NumericResult _margin_a;
47
48     // bottom 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 column is hidden
55
private BooleanResult _hidden;
56
57     // true if column 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
83     private static final Attribute[] _implied_attributes =
84         {
85             new Attribute(_hard_size_attribute, "0"),
86             new Attribute(_hidden_attribute, "0"),
87             new Attribute(_collapsed_attribute, "0"),
88             new Attribute(_outline_level_attribute, "0"),
89             new Attribute(_count_attribute, "1")
90         };
91
92     /**
93      * constructor
94      */

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

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

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

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

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

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

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

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

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

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

220     public void endProcessing() throws IOException JavaDoc {
221         getSheet().setColumnWidth(getColumnNo(), getPoints());
222     }
223 } // end public class EPColInfo
224
Popular Tags