1 17 18 package com.finalist.jag.template.parser; 19 20 import com.finalist.jag.util.*; 21 22 import java.io.*; 23 24 25 32 public class JagBlockImpl implements JagBlock, Serializable { 33 34 35 private JagBlockImpl down; 36 37 38 private JagBlockImpl right; 39 40 41 private String text = ""; 42 43 44 private int type; 45 46 47 private int startPos; 48 49 50 private int endPos; 51 52 53 private static boolean verboseStringConversion = false; 54 55 56 private static String [] tokenNames = null; 57 58 59 64 public void addChild(JagBlock node) { 65 if (node == null) return; 66 67 JagBlockImpl t = this.down; 68 69 if (t != null) { 70 while (t.right != null) { 71 t = t.right; 72 } 73 74 t.right = (JagBlockImpl) node; 75 } 76 else { 77 this.down = (JagBlockImpl) node; 78 } 79 } 80 81 82 89 public boolean equals(JagBlock t) { 90 if (t == null) return false; 91 92 return this.getText().equals(t.getText()) 93 && (this.getType() == t.getType()); 94 } 95 96 97 102 public JagBlock getFirstChild() { 103 return down; 104 } 105 106 107 112 public JagBlock getNextSibling() { 113 return right; 114 } 115 116 117 122 public String getText() { 123 return text; 124 } 125 126 127 132 public int getType() { 133 return type; 134 } 135 136 137 142 public int getStartPos() { 143 return startPos; 144 } 145 146 147 152 public int getEndPos() { 153 return endPos; 154 } 155 156 157 165 public void initialize(int t, String txt) { 166 setType(t); 167 setText(txt); 168 } 169 170 171 178 public void initialize(JagBlock t) { 179 initialize(t.getType(), t.getText()); 180 } 181 182 183 184 public void removeChildren() { 185 down = null; 186 } 187 188 189 194 public void setFirstChild(JagBlock c) { 195 down = (JagBlockImpl) c; 196 } 197 198 199 206 public void setNextSibling(JagBlock n) { 207 right = (JagBlockImpl) n; 208 } 209 210 211 216 public void setText(String text) { 217 this.text = text; 218 } 219 220 221 226 public void setType(int type) { 227 this.type = type; 228 } 229 230 231 236 public void setStartPos(int startPos) { 237 this.startPos = startPos; 238 } 239 240 241 246 public void setEndPos(int endPos) { 247 this.endPos = endPos; 248 } 249 250 251 259 public static void setVerboseStringConversion(boolean verbose, String [] names) { 260 verboseStringConversion = verbose; 261 tokenNames = names; 262 } 263 264 265 272 public String toString() { 273 StringBuffer b = new StringBuffer (); 274 275 if (verboseStringConversion && !getText() 277 .equalsIgnoreCase(tokenNames[getType()]) && !getText() 278 .equalsIgnoreCase(Tools 279 .stripFrontBack(tokenNames[getType()], "\"", "\""))) { 280 b.append('['); 281 b.append(getText()); 282 b.append(",<"); 283 b.append(tokenNames[getType()]); 284 b.append(">]"); 285 return b.toString(); 286 } 287 return getText(); 288 } 289 } 290 291 ; 292 | Popular Tags |