01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: 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.ElementProcessor;
21: import org.apache.cocoon.components.elementprocessor.types.NumericConverter;
22: import org.apache.cocoon.components.elementprocessor.types.NumericResult;
23:
24: import java.io.IOException;
25:
26: /**
27: * No-op implementation of ElementProcessor to handle the "Cols" tag
28: *
29: * This element has an attribute (DefaultSizePts) and is a container
30: * element
31: *
32: * @author Marc Johnson (marc_johnson27591@hotmail.com)
33: * @version CVS $Id: EPCols.java 433543 2006-08-22 06:22:54Z crossley $
34: */
35: public class EPCols extends BaseElementProcessor {
36: private NumericResult _default_size_pts;
37: private boolean _default_size_pts_fetched;
38: private static final String _default_size_pts_attribute = "DefaultSizePts";
39:
40: // package scope so test code can access
41: static final String DEFAULT_SIZE_PTS = "40.0";
42:
43: /**
44: * constructor
45: */
46: public EPCols() {
47: super (null);
48: _default_size_pts = null;
49: _default_size_pts_fetched = false;
50: }
51:
52: /**
53: * get the default size of columns, in points
54: * @return size in points
55: * @exception IOException if the attribute is malformed
56: * @exception NullPointerException if the attribute is missing
57: */
58: public double getDefaultSizePts() throws IOException,
59: NullPointerException {
60: if (!_default_size_pts_fetched) {
61: String value = getValue(_default_size_pts_attribute);
62:
63: if (value == null || value.trim().length() == 0) {
64: value = DEFAULT_SIZE_PTS;
65: }
66: _default_size_pts = NumericConverter.extractDouble(value);
67: _default_size_pts_fetched = true;
68: }
69: return _default_size_pts.doubleValue();
70: }
71:
72: /**
73: * Override of Initialize() implementation
74: * @param attributes the array of Attribute instances; may be empty, will
75: * never be null
76: * @param parent the parent ElementProcessor; may be null
77: * @exception IOException if anything is wrong
78: */
79: public void initialize(final Attribute[] attributes,
80: final ElementProcessor parent) throws IOException {
81: super .initialize(attributes, parent);
82: getSheet().setDefaultColumnWidth(getDefaultSizePts());
83: }
84: } // end public class EPCols
|