KickJava   Java API By Example, From Geeks To Geeks.

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


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.ElementProcessor;
21
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 org.apache.poi.hssf.util.HSSFColor;
27 import org.apache.poi.hssf.usermodel.HSSFCellStyle;
28
29 import java.io.IOException JavaDoc;
30 import java.util.Hashtable JavaDoc;
31
32 /**
33  * No-op implementation of ElementProcessor to handle the "Bottom" tag
34  *
35  * This element has two attributes and no content.
36  *
37  * This element is not used in HSSFSerializer 1.0
38  *
39  * @author Marc Johnson (marc_johnson27591@hotmail.com)
40  * @author Andrew C. Oliver (acoliver2@users.sourceforge.net)
41  * @version CVS $Id: EPBottom.java 37191 2004-08-30 10:15:06Z antonio $
42  */

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

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

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

108     public int getStyle() throws IOException JavaDoc {
109         if (_style == null) {
110             _style =
111                 NumericConverter.extractInteger(getValue(_style_attribute),
112                                                 _style_validator);
113         }
114         return _style.intValue();
115     }
116
117     /**
118      * @return color
119      *
120      * @exception IOException
121      */

122     public ColorCode getColor() throws IOException JavaDoc {
123         if (!_color_fetched) {
124             String JavaDoc colorString = getValue(_color_attribute);
125         if (colorString != null) {
126             _color = new ColorCode(colorString);
127         }
128         _color_fetched = true;
129         }
130         return _color;
131     }
132 } // end public class EPBottom
133
Popular Tags