1 package org.ejen.util.arl; 22 23 import java.io.StringReader ; 24 import org.apache.xml.utils.WrappedRuntimeException; 25 26 66 public class ArlUtil implements ArlParserTreeConstants, ArlParserConstants { 67 68 public static final int F_ACCEPT = 0; 69 public static final int F_REMOVE = 1; 70 public static final int F_CROSS = 2; 71 72 75 protected ArlUtil() {} 76 77 86 public static int[] process(String arl, int[] array) { 87 if (array == null) { 88 return null; 89 } 90 StringReader sr = null; 91 92 try { 93 sr = new StringReader (arl); 94 if (ArlParser.token_source == null) { 95 new ArlParser(sr); 96 } else { 97 ArlParser.ReInit(sr); 98 } 99 SimpleNode sn = ArlParser.ArlSequence(); 100 101 for (int i = 0; i < sn.jjtGetNumChildren(); i++) { 102 int flag = F_ACCEPT; 103 SimpleNode exp = (SimpleNode) (sn.jjtGetChild(i)); 104 Token t = exp.getFirstToken(); 105 106 if (t.kind >= ACCEPT && t.kind <= CROSS) { 107 if (t.kind == REMOVE) { 108 flag = F_REMOVE; 109 } else if (t.kind == CROSS) { 110 flag = F_CROSS; 111 } 112 t = t.next; 113 } 114 if (exp.jjtGetNumChildren() == 0) { 115 array[Integer.parseInt(t.image)] = flag; 116 } else { 117 exp = (SimpleNode) (exp.jjtGetChild(0)); 118 t = exp.getFirstToken().next; 119 int i1 = Integer.parseInt(t.image); 120 int i2 = Integer.parseInt(t.next.next.image); 121 122 for (int j = i1; j <= i2; j++) { 123 array[j] = flag; 124 } 125 } 126 } 127 return array; 128 } catch (Exception e) { 129 throw new WrappedRuntimeException("Bad Arl sequence: " + arl, e); 130 } 131 finally { 132 if (sr != null) { 133 try { 134 sr.close(); 135 } catch (Exception e) {} 136 finally { 137 sr = null; 138 } 139 } 140 } 141 } 142 } 143 | Popular Tags |