KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements;
17
18 import org.apache.cocoon.components.elementprocessor.types.Attribute;
19 import org.apache.cocoon.components.elementprocessor.ElementProcessor;
20
21 import org.apache.cocoon.components.elementprocessor.types.NumericConverter;
22 import org.apache.cocoon.components.elementprocessor.types.NumericResult;
23 import org.apache.cocoon.components.elementprocessor.types.Validator;
24
25 import org.apache.poi.hssf.util.HSSFColor;
26 import org.apache.poi.hssf.usermodel.HSSFCellStyle;
27
28 import java.io.IOException JavaDoc;
29 import java.util.Hashtable JavaDoc;
30
31 /**
32  * No-op implementation of ElementProcessor to handle the "Top" tag
33  *
34  * This element has two attributes and no content.
35  *
36  * This element is not used in HSSFSerializer 1.0
37  *
38  * @author Marc Johnson (marc_johnson27591@hotmail.com)
39  * @author Andrew C. Oliver (acoliver2@users.sourceforge.net)
40  * @version CVS $Id: EPTop.java 30932 2004-07-29 17:35:38Z vgritsenko $
41  */

42 public class EPTop extends BaseElementProcessor {
43     private NumericResult _style;
44     private ColorCode _color;
45     private boolean _color_fetched;
46     private static final String JavaDoc _style_attribute = "Style";
47     private static final String JavaDoc _color_attribute = "Color";
48     private static final Validator _style_validator = new Validator() {
49         public IOException JavaDoc validate(final Number JavaDoc number) {
50             return BorderStyle.isValid(number.intValue()) ? null
51                 : new IOException JavaDoc("\"" + number + "\" is not a legal value");
52         }
53     };
54
55     /**
56      * constructor
57      */

58     public EPTop() {
59         super(null);
60         _style = null;
61         _color = null;
62         _color_fetched = false;
63     }
64
65     /**
66      * Override of Initialize() implementation
67      * @param attributes the array of Attribute instances; may be empty, will
68      * never be null
69      * @param parent the parent ElementProcessor; may be null
70      * @exception IOException if anything is wrong
71      */

72     public void initialize(final Attribute[] attributes,
73                 final ElementProcessor parent) throws IOException JavaDoc {
74         super.initialize(attributes, parent);
75         EPStyle pstyle = (EPStyle)getAncestor(EPStyle.class);
76         if (pstyle != null && pstyle.isValid()) {
77             Hashtable JavaDoc colorhash = pstyle.getColorHash();
78             HSSFColor color = null;
79
80             HSSFCellStyle style = pstyle.getStyle(); //oops
81
// a
82
// little
83
// confusing
84
//below is the style attribute
85
//this is an HSSFCellStyle
86
//associated with EPStyle
87
style.setBorderTop((short)getStyle());
88
89             ColorCode colorCode = getColor();
90             if (colorCode != null) {
91                 color = (HSSFColor)colorhash.get(colorCode.toString());
92             }
93             if (color == null)
94                 color = new HSSFColor.BLACK();
95
96             style.setTopBorderColor(color.getIndex());
97         }
98
99     }
100
101     /**
102      * @return style as an int from BorderStyle
103      * @exception IOException
104      */

105     public int getStyle() throws IOException JavaDoc {
106         if (_style == null) {
107             _style = NumericConverter.extractInteger(
108                     getValue(_style_attribute), _style_validator);
109         }
110         return _style.intValue();
111     }
112
113     /**
114      * @return color (may be null)
115      * @exception IOException
116      */

117     public ColorCode getColor() throws IOException JavaDoc {
118         if (!_color_fetched) {
119             String JavaDoc colorString = getValue(_color_attribute);
120
121             if (colorString != null) {
122                 _color = new ColorCode(colorString);
123             }
124             _color_fetched = true;
125         }
126         return _color;
127     }
128 } // end public class EPTop
129
Popular Tags