1 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 ; 30 import java.util.Hashtable ; 31 32 43 public class EPBottom extends BaseElementProcessor { 44 private NumericResult _style; 45 private ColorCode _color; 46 private boolean _color_fetched; 47 private static final String _style_attribute = "Style"; 48 private static final String _color_attribute = "Color"; 49 private static final Validator _style_validator = new Validator() 50 { 51 public IOException validate(final Number number) { 52 return BorderStyle.isValid(number.intValue()) ? null 53 : new IOException ("\"" + number + "\" is not a legal value"); 54 } 55 }; 56 57 60 public EPBottom() { 61 super(null); 62 _style = null; 63 _color = null; 64 _color_fetched = false; 65 } 66 67 76 77 public void initialize(final Attribute [] attributes, 78 final ElementProcessor parent) throws IOException { 79 super.initialize(attributes, parent); 80 EPStyle pstyle = (EPStyle) getAncestor(EPStyle.class); 81 if (pstyle != null && pstyle.isValid()) { 82 Hashtable colorhash = pstyle.getColorHash(); 83 HSSFColor color = null; 84 85 HSSFCellStyle style = pstyle.getStyle(); 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 108 public int getStyle() throws IOException { 109 if (_style == null) { 110 _style = 111 NumericConverter.extractInteger(getValue(_style_attribute), 112 _style_validator); 113 } 114 return _style.intValue(); 115 } 116 117 122 public ColorCode getColor() throws IOException { 123 if (!_color_fetched) { 124 String colorString = getValue(_color_attribute); 125 if (colorString != null) { 126 _color = new ColorCode(colorString); 127 } 128 _color_fetched = true; 129 } 130 return _color; 131 } 132 } | Popular Tags |