1 16 17 package org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements; 18 19 20 import org.apache.cocoon.components.elementprocessor.types.NumericConverter; 21 import org.apache.cocoon.components.elementprocessor.types.Validator; 22 23 import java.io.IOException ; 24 25 38 public class Anchors 39 { 40 private static final int _component_count = 4; 41 private int[] _components = 42 new int[ _component_count ]; 43 44 public static final int ANCHOR_UNKNOWN = 0; 46 public static final int ANCHOR_PERCENTAGE_FROM_COLROW_ST = 16; 47 public static final int ANCHOR_PERCENTAGE_FROM_COLROW_END = 17; 48 public static final int ANCHOR_PTS_FROM_COLROW_START = 32; 49 public static final int ANCHOR_PTS_FROM_COLROW_END = 33; 50 public static final int ANCHOR_PTS_ABSOLUTE = 48; 51 private static final Validator _validator = 52 new Validator() 53 { 54 public IOException validate(final Number number) { 55 switch (number.intValue()) { 56 case ANCHOR_UNKNOWN : 57 case ANCHOR_PERCENTAGE_FROM_COLROW_ST : 58 case ANCHOR_PERCENTAGE_FROM_COLROW_END : 59 case ANCHOR_PTS_FROM_COLROW_START : 60 case ANCHOR_PTS_FROM_COLROW_END : 61 case ANCHOR_PTS_ABSOLUTE : 62 return null; 63 64 default : 65 return new IOException ("\"" + number 66 + "\" is not a legal value"); 67 } 68 } 69 }; 70 71 78 79 public Anchors(final String value) throws IOException { 80 if (value == null) { 81 throw new IOException ("cannot process a null anchors string"); 82 } 83 char[] input = value.trim().toCharArray(); 84 int index = 0; 85 86 for (int j = 0; j < _component_count; j++) { 87 while (index < input.length 88 && Character.isWhitespace(input[index])) { 89 ++index; 90 } 91 if (index == input.length) { 92 throw new IOException ("insufficient anchors in string"); 93 } 94 int tailIndex = index; 95 96 while (tailIndex < input.length 97 && !Character.isWhitespace(input[tailIndex])) { 98 ++tailIndex; 99 } 100 _components[j] = NumericConverter.extractInteger(new String (input, 101 index, tailIndex - index), _validator).intValue(); 102 index = tailIndex; 103 } 104 if (new String (input, index, input.length - index).trim().length() != 0) { 105 throw new IOException ("Too much data in string for " 106 + _component_count + " anchors"); 107 } 108 } 109 110 113 114 public int [] getComponents() { 115 return _components; 116 } 117 } | Popular Tags |