1 package com.genimen.djeneric.repository.oql.core.nodes; 2 3 import java.util.HashMap ; 4 5 import com.genimen.djeneric.repository.oql.core.DjOqlParserEngine; 6 import com.genimen.djeneric.repository.oql.core.SimpleNode; 7 8 public class StringNode extends SimpleNode implements ValueExpression 9 { 10 String _value = null; 11 12 public StringNode(int i) 13 { 14 super(i); 15 } 16 17 public StringNode(DjOqlParserEngine p, int i) 18 { 19 super(p, i); 20 } 21 22 public String getName() 23 { 24 return toString(); 25 } 26 27 public String toString() 28 { 29 return _value; 30 } 31 32 public void setValue(String v) 33 { 34 v = v.substring(1); 36 v = v.substring(0, v.length() - 1); 37 38 _value = translateEscapes(v); 39 } 40 41 public Object getValue(MatchingContext context) 42 { 43 return _value; 44 } 45 46 public Object getValue() 47 { 48 return _value; 49 } 50 51 static String _froms = "ntbrf\\'\""; 52 static String _tos = "\n\t\b\r\f\\'\""; 53 54 public static String translateEscapes(String src) 55 { 56 StringBuffer sb = new StringBuffer (src); 57 58 int i = 0; 59 while (i < sb.length() - 1) 60 { 61 if (sb.charAt(i) == '\\') 62 { 63 for (int x = 0; x < _froms.length(); x++) 64 { 65 if (_froms.charAt(x) == sb.charAt(i + 1)) 66 { 67 sb.deleteCharAt(i); 68 sb.setCharAt(i, _tos.charAt(x)); 69 break; 70 } 71 } 72 } 73 i++; 74 } 75 return sb.toString(); 76 } 77 78 public void translate(StringBuffer result, HashMap path2AliasMapping) 79 { 80 appendOpenBrackets(result); 81 result.append("'" + _value + "'"); 82 appendCloseBrackets(result); 83 } 84 } | Popular Tags |