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.ElementProcessor;
022:
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 org.apache.poi.hssf.util.HSSFColor;
028: import org.apache.poi.hssf.usermodel.HSSFCellStyle;
029:
030: import java.io.IOException;
031: import java.util.Hashtable;
032:
033: /**
034: * No-op implementation of ElementProcessor to handle the "Right" tag
035: *
036: * This element has two attributes and no content.
037: *
038: * This element is not used in HSSFSerializer 1.0
039: *
040: * @author Marc Johnson (marc_johnson27591@hotmail.com)
041: * @author Andrew C. Oliver (acoliver2@users.sourceforge.net)
042: * @version CVS $Id: EPRight.java 433543 2006-08-22 06:22:54Z crossley $
043: */
044: public class EPRight extends BaseElementProcessor {
045: private NumericResult _style;
046: private ColorCode _color;
047: private boolean _color_fetched;
048: private static final String _style_attribute = "Style";
049: private static final String _color_attribute = "Color";
050: private static final Validator _style_validator = new Validator() {
051: public IOException validate(final Number number) {
052: return BorderStyle.isValid(number.intValue()) ? null
053: : new IOException("\"" + number
054: + "\" is not a legal value");
055: }
056: };
057:
058: /**
059: * constructor
060: */
061: public EPRight() {
062: super (null);
063: _style = null;
064: _color = null;
065: _color_fetched = false;
066: }
067:
068: /**
069: * Override of Initialize() implementation
070: * @param attributes the array of Attribute instances; may be empty, will
071: * never be null
072: * @param parent the parent ElementProcessor; may be null
073: * @exception IOException if anything is wrong
074: */
075: public void initialize(final Attribute[] attributes,
076: final ElementProcessor parent) throws IOException {
077: super .initialize(attributes, parent);
078: EPStyle pstyle = (EPStyle) getAncestor(EPStyle.class);
079: if (pstyle != null && pstyle.isValid()) {
080: Hashtable colorhash = pstyle.getColorHash();
081: HSSFColor color = null;
082:
083: HSSFCellStyle style = pstyle.getStyle(); //oops
084: // a
085: // little
086: // confusing
087: //below is the style attribute
088: //this is an HSSFCellStyle
089: //associated with EPStyle
090: style.setBorderRight((short) getStyle());
091:
092: ColorCode colorCode = getColor();
093: if (colorCode != null) {
094: color = (HSSFColor) colorhash.get(colorCode.toString());
095: }
096: if (color == null) {
097: color = new HSSFColor.BLACK();
098: }
099: style.setRightBorderColor(color.getIndex());
100: }
101:
102: }
103:
104: /**
105: * @return style as an int from BorderStyle
106: * @exception IOException
107: */
108: public int getStyle() throws IOException {
109: if (_style == null) {
110: _style = NumericConverter.extractInteger(
111: getValue(_style_attribute), _style_validator);
112: }
113: return _style.intValue();
114: }
115:
116: /**
117: * @return color
118: * @exception IOException
119: */
120: public ColorCode getColor() throws IOException {
121: if (!_color_fetched) {
122: String colorString = getValue(_color_attribute);
123: if (colorString != null) {
124: _color = new ColorCode(colorString);
125: }
126: _color_fetched = true;
127: }
128: return _color;
129: }
130: } // end public class EPRight
|