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 "RowInfo"
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: EPRowInfo.java 433543 2006-08-22 06:22:54Z crossley $
037: */
038: public class EPRowInfo extends BaseElementProcessor {
039:
040: // row number
041: private NumericResult _no;
042:
043: // size, in points
044: private NumericResult _unit;
045:
046: // left margin, in points
047: private NumericResult _margin_a;
048:
049: // right 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 row is hidden
056: private BooleanResult _hidden;
057:
058: // true if row 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: private static final Attribute[] _implied_attributes = {
084: new Attribute(_hard_size_attribute, "0"),
085: new Attribute(_hidden_attribute, "0"),
086: new Attribute(_collapsed_attribute, "0"),
087: new Attribute(_outline_level_attribute, "0"),
088: new Attribute(_count_attribute, "1") };
089:
090: /**
091: * constructor
092: */
093: public EPRowInfo() {
094: super (_implied_attributes);
095: _no = null;
096: _unit = null;
097: _margin_a = null;
098: _margin_b = null;
099: _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 {
111: if (_no == null) {
112: _no = NumericConverter
113: .extractNonNegativeInteger(getValue(_no_attribute));
114: }
115: return _no.intValue();
116: }
117:
118: /**
119: * @return row size in points
120: * @exception IOException
121: */
122: public double getPoints() throws IOException {
123: if (_unit == null) {
124: _unit = NumericConverter
125: .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 {
135: if (_margin_a == null) {
136: _margin_a = NumericConverter.extractInteger(
137: getValue(_margin_a_attribute), _margin_validator);
138: }
139: return _margin_a.intValue();
140: }
141:
142: /**
143: * @return right margin
144: * @exception IOException
145: */
146: public int getRightMargin() throws IOException {
147: if (_margin_b == null) {
148: _margin_b = NumericConverter.extractInteger(
149: getValue(_margin_b_attribute), _margin_validator);
150: }
151: return _margin_b.intValue();
152: }
153:
154: /**
155: * @return hard size
156: * @exception IOException
157: */
158: public boolean getHardSize() throws IOException {
159: if (_hard_size == null) {
160: _hard_size = BooleanConverter
161: .extractBoolean(getValue(_hard_size_attribute));
162: }
163: return _hard_size.booleanValue();
164: }
165:
166: /**
167: * @return hidden state
168: * @exception IOException
169: */
170: public boolean getHidden() throws IOException {
171: if (_hidden == null) {
172: _hidden = BooleanConverter
173: .extractBoolean(getValue(_hidden_attribute));
174: }
175: return _hidden.booleanValue();
176: }
177:
178: /**
179: * @return collapsed state
180: * @exception IOException
181: */
182: public boolean getCollapsed() throws IOException {
183: if (_collapsed == null) {
184: _collapsed = BooleanConverter
185: .extractBoolean(getValue(_collapsed_attribute));
186: }
187: return _collapsed.booleanValue();
188: }
189:
190: /**
191: * @return outline level
192: * @exception IOException
193: */
194: public int getOutlineLevel() throws IOException {
195: if (_outline_level == null) {
196: _outline_level = NumericConverter
197: .extractInteger(getValue(_outline_level_attribute));
198: }
199: return _outline_level.intValue();
200: }
201:
202: /**
203: * @return rle count
204: * @exception IOException
205: */
206: public int getRLECount() throws IOException {
207: if (_count == null) {
208: _count = NumericConverter
209: .extractInteger(getValue(_count_attribute));
210: }
211: return _count.intValue();
212: }
213:
214: /**
215: * Set this row's height
216: * @exception IOException
217: */
218: public void endProcessing() throws IOException {
219: int row = getRowNo();
220:
221: if (row > Short.MAX_VALUE) {
222: throw new IOException("Illegal row value: " + row);
223: }
224: getSheet().getRow(row).setHeight(getPoints());
225: }
226: } // end public class EPRowInfo
|