001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements;
019:
020: import org.apache.cocoon.components.elementprocessor.types.Attribute;
021: import org.apache.cocoon.components.elementprocessor.types.BooleanConverter;
022: import org.apache.cocoon.components.elementprocessor.types.BooleanResult;
023: import org.apache.cocoon.components.elementprocessor.types.NumericConverter;
024: import org.apache.cocoon.components.elementprocessor.types.NumericResult;
025: import org.apache.cocoon.components.elementprocessor.types.Validator;
026:
027: import java.io.IOException;
028:
029: /**
030: * No-op implementation of ElementProcessor to handle the "ColInfo"
031: * tag
032: *
033: * This element has several attributes and has no content
034: *
035: * @author Marc Johnson (marc_johnson27591@hotmail.com)
036: * @version CVS $Id: EPColInfo.java 433543 2006-08-22 06:22:54Z crossley $
037: */
038: public class EPColInfo extends BaseElementProcessor {
039:
040: // column number
041: private NumericResult _no;
042:
043: // size, in points
044: private NumericResult _unit;
045:
046: // top margin, in points
047: private NumericResult _margin_a;
048:
049: // bottom margin, in points
050: private NumericResult _margin_b;
051:
052: // true if size is explicitly set
053: private BooleanResult _hard_size;
054:
055: // true if column is hidden
056: private BooleanResult _hidden;
057:
058: // true if column is collapsed
059: private BooleanResult _collapsed;
060:
061: // outline level
062: private NumericResult _outline_level;
063:
064: // rle count
065: private NumericResult _count;
066: private static final String _no_attribute = "No";
067: private static final String _unit_attribute = "Unit";
068: private static final String _margin_a_attribute = "MarginA";
069: private static final String _margin_b_attribute = "MarginB";
070: private static final String _hard_size_attribute = "HardSize";
071: private static final String _hidden_attribute = "Hidden";
072: private static final String _collapsed_attribute = "Collapsed";
073: private static final String _outline_level_attribute = "OutlineLevel";
074: private static final String _count_attribute = "Count";
075: private static final Validator _margin_validator = new Validator() {
076: public IOException validate(final Number number) {
077: int val = number.intValue();
078:
079: return (val >= 0 && val <= 7) ? null : new IOException("\""
080: + number + "\" is not a legal value");
081: }
082: };
083:
084: private static final Attribute[] _implied_attributes = {
085: new Attribute(_hard_size_attribute, "0"),
086: new Attribute(_hidden_attribute, "0"),
087: new Attribute(_collapsed_attribute, "0"),
088: new Attribute(_outline_level_attribute, "0"),
089: new Attribute(_count_attribute, "1") };
090:
091: /**
092: * constructor
093: */
094: public EPColInfo() {
095: super (_implied_attributes);
096: _no = null;
097: _unit = null;
098: _margin_a = null;
099: _margin_b = null;
100: _hard_size = null;
101: _hidden = null;
102: _collapsed = null;
103: _outline_level = null;
104: _count = null;
105: }
106:
107: /**
108: * @return column number
109: * @exception IOException
110: */
111: public int getColumnNo() throws IOException {
112: if (_no == null) {
113: _no = NumericConverter
114: .extractNonNegativeInteger(getValue(_no_attribute));
115: }
116: return _no.intValue();
117: }
118:
119: /**
120: * @return column size in points
121: * @exception IOException
122: */
123: public double getPoints() throws IOException {
124: if (_unit == null) {
125: _unit = NumericConverter
126: .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 {
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 {
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 {
160: if (_hard_size == null) {
161: _hard_size = BooleanConverter
162: .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 {
172: if (_hidden == null) {
173: _hidden = BooleanConverter
174: .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 {
184: if (_collapsed == null) {
185: _collapsed = BooleanConverter
186: .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 {
196: if (_outline_level == null) {
197: _outline_level = NumericConverter
198: .extractInteger(getValue(_outline_level_attribute));
199: }
200: return _outline_level.intValue();
201: }
202:
203: /**
204: * @return rle count
205: * @exception IOException
206: */
207: public int getRLECount() throws IOException {
208: if (_count == null) {
209: _count = NumericConverter
210: .extractInteger(getValue(_count_attribute));
211: }
212: return _count.intValue();
213: }
214:
215: /**
216: * Set this column's width
217: * @exception IOException
218: */
219: public void endProcessing() throws IOException {
220: getSheet().setColumnWidth(getColumnNo(), getPoints());
221: }
222: } // end public class EPColInfo
|