1 16 17 package org.apache.taglibs.standard.lang.jpath.expression; 18 19 20 27 public class EvaluationException extends Exception { 28 29 protected boolean specialConstructor; 30 public String image; 31 protected SimpleNode node; 32 33 36 protected String eol = System.getProperty("line.separator", "\n"); 37 38 44 public EvaluationException() { 45 46 super(); 47 48 specialConstructor = false; 49 } 50 51 58 public EvaluationException(String message) { 59 60 super(message); 61 62 specialConstructor = false; 63 } 64 65 73 public EvaluationException(SimpleNode currentNode, String message) { 74 75 super(message); 76 77 specialConstructor = true; 78 node = currentNode; 79 } 80 81 93 public String getMessage() { 94 95 if (!specialConstructor) { 96 return super.getMessage(); 97 } 98 99 String expected = ""; 100 int maxSize = 1; 101 String retval = eol + "Encountered \""; 102 103 retval += super.getMessage(); 104 retval += "\"" + eol; 105 retval += "at : " + eol; 106 retval += node.rootOriginalString() + eol; 107 108 for (int i = 0; i < node.firstToken.beginColumn - 1; i++) { 109 retval += " "; 110 } 111 112 for (int i = 0; i 113 < node.lastToken.endColumn 114 - (node.firstToken.beginColumn - 1); i++) { 115 retval += "^"; 116 } 117 118 retval += eol; 119 retval += "beginning at column " + node.firstToken.beginColumn + "." 120 + eol; 121 retval += "ending at column " + node.lastToken.endColumn + "." + eol; 122 123 return retval; 124 } 125 126 135 protected String add_escapes(String str) { 136 137 StringBuffer retval = new StringBuffer (); 138 char ch; 139 140 for (int i = 0; i < str.length(); i++) { 141 switch (str.charAt(i)) { 142 143 case 0 : 144 continue; 145 case '\b' : 146 retval.append("\\b"); 147 148 continue; 149 case '\t' : 150 retval.append("\\t"); 151 152 continue; 153 case '\n' : 154 retval.append("\\n"); 155 156 continue; 157 case '\f' : 158 retval.append("\\f"); 159 160 continue; 161 case '\r' : 162 retval.append("\\r"); 163 164 continue; 165 case '\"' : 166 retval.append("\\\""); 167 168 continue; 169 case '\'' : 170 retval.append("\\\'"); 171 172 continue; 173 case '\\' : 174 retval.append("\\\\"); 175 176 continue; 177 default : 178 if ((ch = str.charAt(i)) < 0x20 || (ch > 0x7e)) { 179 String s = "0000" + Integer.toString(ch, 16); 180 181 retval.append("\\u" 182 + s.substring(s.length() - 4, s.length())); 183 } else { 184 retval.append(ch); 185 } 186 187 continue; 188 } 189 } 190 191 return retval.toString(); 192 } 193 } 194 | Popular Tags |