1 16 17 package org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements; 18 19 import java.util.Hashtable ; 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.ElementProcessor; 24 import org.apache.cocoon.components.elementprocessor.types.Attribute; 25 26 import org.apache.poi.hssf.usermodel.HSSFCellStyle; 27 import org.apache.poi.hssf.util.Region; 28 29 30 import java.io.IOException ; 31 32 43 public class EPStyleRegion extends BaseElementProcessor { 44 private static final String _start_col_attribute = "startCol"; 45 private static final String _start_row_attribute = "startRow"; 46 private static final String _end_col_attribute = "endCol"; 47 private static final String _end_row_attribute = "endRow"; 48 private NumericResult _start_col; 49 private NumericResult _start_row; 50 private NumericResult _end_col; 51 private NumericResult _end_row; 52 53 private HSSFCellStyle _style; 54 private Hashtable colorhash; 55 56 private boolean invalid; 57 58 private int MAX_AREA = 2001; 62 63 66 public EPStyleRegion() { 67 super(null); 68 _start_col = null; 69 _start_row = null; 70 _end_col = null; 71 _end_row = null; 72 } 73 74 81 public void initialize(final Attribute[] attributes, 82 final ElementProcessor parent) throws IOException { 83 super.initialize(attributes, parent); 84 85 Region region = new Region(getStartRow(), (short)getStartCol(), 86 getEndRow(), (short)getEndCol()); 87 88 92 getLogger().debug("region area is " + region.getArea()); 93 if (region.getArea() < MAX_AREA) { 94 getLogger().debug("region added"); 98 _style = getSheet().addStyleRegion(region); } else { 100 invalid = true; 101 } 102 colorhash = ((EPStyles)parent).getColorHash(); 103 } 104 105 109 public int getStartRow() throws IOException { 110 if (_start_row == null) { 111 _start_row = NumericConverter.extractNonNegativeInteger( 112 getValue(_start_row_attribute)); 113 } 114 return _start_row.intValue(); 115 } 116 117 121 public int getStartCol() throws IOException { 122 if (_start_col == null) { 123 _start_col = NumericConverter.extractNonNegativeInteger( 124 getValue(_start_col_attribute)); 125 } 126 return _start_col.intValue(); 127 } 128 129 133 public int getEndRow() throws IOException { 134 if (_end_row == null) { 135 _end_row = NumericConverter.extractNonNegativeInteger( 136 getValue(_end_row_attribute)); 137 } 138 return _end_row.intValue(); 139 } 140 141 145 public int getEndCol() throws IOException { 146 if (_end_col == null) { 147 _end_col = NumericConverter.extractNonNegativeInteger( 148 getValue(_end_col_attribute)); 149 } 150 return _end_col.intValue(); 151 } 152 153 156 public HSSFCellStyle getStyle() { 157 return _style; 158 } 159 160 165 public Hashtable getColorHash() { 166 return colorhash; 167 } 168 169 173 public boolean isValid() { 174 return (!invalid); 175 } 176 177 } | Popular Tags |