1 30 package com.genimen.djeneric.tools.scriptengine.core.nodes; 31 32 import java.util.HashMap ; 33 34 import com.genimen.djeneric.tools.scriptengine.core.DjScriptParserEngine; 35 import com.genimen.djeneric.tools.scriptengine.core.SimpleNode; 36 import com.genimen.djeneric.tools.scriptengine.core.util.DjScriptCompileTimeScope; 37 import com.genimen.djeneric.tools.scriptengine.core.util.DjScriptExecutionTimeScope; 38 39 public class StringNode extends SimpleNode implements ValueExpression 40 { 41 String _value = null; 42 43 public StringNode(int i) 44 { 45 super(i); 46 } 47 48 public StringNode(DjScriptParserEngine p, int i) 49 { 50 super(p, i); 51 } 52 53 public String getName() 54 { 55 return toString(); 56 } 57 58 public String toString() 59 { 60 return _value; 61 } 62 63 public void setValue(String v) 64 { 65 v = v.substring(1); 67 v = v.substring(0, v.length() - 1); 68 69 _value = translateEscapes(v); 70 } 71 72 public Object getValue(DjScriptExecutionTimeScope context) 73 { 74 return _value; 75 } 76 77 static String _froms = "ntbrf\\'\""; 78 static String _tos = "\n\t\b\r\f\\'\""; 79 80 public static String translateEscapes(String src) 81 { 82 StringBuffer sb = new StringBuffer (src); 83 84 int i = 0; 85 while (i < sb.length() - 1) 86 { 87 if (sb.charAt(i) == '\\') 88 { 89 for (int x = 0; x < _froms.length(); x++) 90 { 91 if (_froms.charAt(x) == sb.charAt(i + 1)) 92 { 93 sb.deleteCharAt(i); 94 sb.setCharAt(i, _tos.charAt(x)); 95 break; 96 } 97 } 98 } 99 i++; 100 } 101 return sb.toString(); 102 } 103 104 public void translateOql(DjScriptExecutionTimeScope ctxt, StringBuffer result, HashMap parameters) 105 { 106 result.append("\""); 107 result.append(_value); 108 result.append("\""); 109 } 110 111 public String getValidatedTypeName(DjScriptCompileTimeScope context) 112 { 113 return String .class.getName(); 114 } 115 116 } | Popular Tags |