1 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 ; 29 import java.util.Hashtable ; 30 31 42 public class EPTop extends BaseElementProcessor { 43 private NumericResult _style; 44 private ColorCode _color; 45 private boolean _color_fetched; 46 private static final String _style_attribute = "Style"; 47 private static final String _color_attribute = "Color"; 48 private static final Validator _style_validator = new Validator() { 49 public IOException validate(final Number number) { 50 return BorderStyle.isValid(number.intValue()) ? null 51 : new IOException ("\"" + number + "\" is not a legal value"); 52 } 53 }; 54 55 58 public EPTop() { 59 super(null); 60 _style = null; 61 _color = null; 62 _color_fetched = false; 63 } 64 65 72 public void initialize(final Attribute[] attributes, 73 final ElementProcessor parent) throws IOException { 74 super.initialize(attributes, parent); 75 EPStyle pstyle = (EPStyle)getAncestor(EPStyle.class); 76 if (pstyle != null && pstyle.isValid()) { 77 Hashtable colorhash = pstyle.getColorHash(); 78 HSSFColor color = null; 79 80 HSSFCellStyle style = pstyle.getStyle(); 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 105 public int getStyle() throws IOException { 106 if (_style == null) { 107 _style = NumericConverter.extractInteger( 108 getValue(_style_attribute), _style_validator); 109 } 110 return _style.intValue(); 111 } 112 113 117 public ColorCode getColor() throws IOException { 118 if (!_color_fetched) { 119 String 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 } | Popular Tags |