svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.api / src / main / java / org / gvsig / expressionevaluator / ExpressionUtils.java @ 45620
History | View | Annotate | Download (21.5 KB)
1 |
package org.gvsig.expressionevaluator; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.io.File; |
5 |
import java.net.MalformedURLException; |
6 |
import java.net.URL; |
7 |
import java.util.List; |
8 |
import java.util.regex.Matcher; |
9 |
import java.util.regex.Pattern; |
10 |
import org.apache.commons.lang3.ArrayUtils; |
11 |
import org.apache.commons.lang3.StringUtils; |
12 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
13 |
import static org.gvsig.expressionevaluator.ExpressionEvaluatorManager.DYNAMICTEXT_ENDTAG; |
14 |
import static org.gvsig.expressionevaluator.ExpressionEvaluatorManager.DYNAMICTEXT_STARTTAG; |
15 |
import org.gvsig.expressionevaluator.spi.DynObjectSymbolTable; |
16 |
import org.gvsig.tools.dynobject.DynObject; |
17 |
import org.gvsig.tools.util.ListBuilder; |
18 |
|
19 |
/**
|
20 |
*
|
21 |
* @author gvSIG Team
|
22 |
*/
|
23 |
@SuppressWarnings("UseSpecificCatch") |
24 |
public class ExpressionUtils { |
25 |
|
26 |
public static boolean isEmpty(Expression expression) { |
27 |
return expression == null || expression.isEmpty(); |
28 |
} |
29 |
|
30 |
public static boolean isPhraseEmpty(Expression expression) { |
31 |
return expression == null || expression.isPhraseEmpty(); |
32 |
} |
33 |
|
34 |
public static Expression defaultIfEmpty(Expression expression, Expression defaultValue) { |
35 |
if( expression==null || expression.isEmpty() ) { |
36 |
return defaultValue;
|
37 |
} |
38 |
return expression;
|
39 |
} |
40 |
|
41 |
public static Expression defaultNullIfEmpty(Expression expression) { |
42 |
if( expression==null || expression.isEmpty() ) { |
43 |
return null; |
44 |
} |
45 |
return expression;
|
46 |
} |
47 |
|
48 |
public static Expression defaultIfPhraseEmpty(Expression expression, Expression defaultValue) { |
49 |
if( expression==null || expression.isPhraseEmpty() ) { |
50 |
return defaultValue;
|
51 |
} |
52 |
return expression;
|
53 |
} |
54 |
|
55 |
public static Expression defaultNullIfPhraseEmpty(Expression expression) { |
56 |
if( expression==null || expression.isPhraseEmpty() ) { |
57 |
return null; |
58 |
} |
59 |
return expression;
|
60 |
} |
61 |
|
62 |
public static Expression createExpression() { |
63 |
Expression expression = ExpressionEvaluatorLocator.getManager().createExpression();
|
64 |
return expression;
|
65 |
} |
66 |
|
67 |
public static Expression createExpression(String phrase) { |
68 |
if( StringUtils.isBlank(phrase) ) {
|
69 |
return null; |
70 |
} |
71 |
Expression expression = ExpressionEvaluatorLocator.getManager().createExpression();
|
72 |
expression.setPhrase(phrase); |
73 |
return expression;
|
74 |
} |
75 |
|
76 |
// public static Expression createExpression(String phrase, String code, Script... scripts) {
|
77 |
// Expression expression = ExpressionEvaluatorLocator.getManager().createExpression();
|
78 |
// expression.setPhrase(phrase);
|
79 |
// expression.setUserScript(code);
|
80 |
// for (Script script : scripts) {
|
81 |
// expression.addScript(script);
|
82 |
// }
|
83 |
// return expression;
|
84 |
// }
|
85 |
//
|
86 |
// public static Expression createExpression(String phrase, String code, String languaje, Script... scripts) {
|
87 |
// Expression expression = ExpressionEvaluatorLocator.getManager().createExpression();
|
88 |
// expression.setPhrase(phrase);
|
89 |
// expression.setUserScript(code, languaje);
|
90 |
// for (Script script : scripts) {
|
91 |
// expression.addScript(script);
|
92 |
// }
|
93 |
// return expression;
|
94 |
// }
|
95 |
|
96 |
public static ExpressionBuilder createExpressionBuilder() { |
97 |
ExpressionBuilder builder = ExpressionEvaluatorLocator.getManager().createExpressionBuilder(); |
98 |
return builder;
|
99 |
} |
100 |
|
101 |
public static Code compile(String expression) { |
102 |
if( StringUtils.isBlank(expression) ) {
|
103 |
return null; |
104 |
} |
105 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
106 |
Code code = manager.compile(expression); |
107 |
return code;
|
108 |
} |
109 |
|
110 |
public static Object evaluate(String expression) { |
111 |
return evaluate(null, expression); |
112 |
} |
113 |
|
114 |
public static Object evaluate(SymbolTable symbolTable, String expression) { |
115 |
if( StringUtils.isBlank(expression) ) {
|
116 |
return null; |
117 |
} |
118 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
119 |
Object x = manager.evaluate(symbolTable, expression);
|
120 |
return x;
|
121 |
} |
122 |
|
123 |
public static Object evaluate(SymbolTable symbolTable, Code code) { |
124 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
125 |
Object x = manager.evaluate(symbolTable, code);
|
126 |
return x;
|
127 |
} |
128 |
|
129 |
public static Code optimize(SymbolTable symbolTable, Code code) { |
130 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
131 |
code = manager.optimize(symbolTable, code); |
132 |
return code;
|
133 |
} |
134 |
|
135 |
public static String toString(Value value, Formatter formatter) { |
136 |
if( value == null ) { |
137 |
return null; |
138 |
} |
139 |
if( formatter==null ) { |
140 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
141 |
formatter = manager.getExpressionBuilderFormatter(); |
142 |
} |
143 |
return value.toString(formatter);
|
144 |
} |
145 |
|
146 |
public static String toString(Value value) { |
147 |
return toString(value, null); |
148 |
} |
149 |
|
150 |
public static String toString(Code code, Formatter formatter) { |
151 |
if( code == null ) { |
152 |
return null; |
153 |
} |
154 |
if( formatter==null ) { |
155 |
formatter = Code.EMPTY_FORMATTER; |
156 |
} |
157 |
return code.toString(formatter);
|
158 |
} |
159 |
|
160 |
public static String toString(Code code) { |
161 |
return toString(code, null); |
162 |
} |
163 |
|
164 |
public static Expression createExpressionFromJSON(String json) { |
165 |
Expression expression = ExpressionUtils.createExpression();
|
166 |
expression.fromJSON(json); |
167 |
return expression;
|
168 |
} |
169 |
|
170 |
public static MutableSymbolTable createSymbolTable() { |
171 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
172 |
MutableSymbolTable symbolTable = manager.createSymbolTable(); |
173 |
return symbolTable;
|
174 |
} |
175 |
|
176 |
public static MutableSymbolTable createSymbolTable(DynObject obj) { |
177 |
DynObjectSymbolTable symbolTable = new DynObjectSymbolTable(obj);
|
178 |
return symbolTable;
|
179 |
} |
180 |
|
181 |
public static String surroundByDynamicTextTag(String source) { |
182 |
return surroundByDynamicTextTag(source, true); |
183 |
} |
184 |
|
185 |
public static String surroundByDynamicTextTag(String source, boolean insert) { |
186 |
if( source==null ) { |
187 |
return null; |
188 |
} |
189 |
if( insert ) {
|
190 |
return DYNAMICTEXT_STARTTAG+ "=" + source + DYNAMICTEXT_ENDTAG; |
191 |
} |
192 |
return DYNAMICTEXT_STARTTAG + source + DYNAMICTEXT_ENDTAG;
|
193 |
} |
194 |
|
195 |
public static boolean isDynamicText(String source) { |
196 |
if( !source.contains(DYNAMICTEXT_STARTTAG) ) {
|
197 |
return false; |
198 |
} |
199 |
String[] sources = StringUtils.substringsBetween(source, DYNAMICTEXT_STARTTAG, DYNAMICTEXT_ENDTAG); |
200 |
if( ArrayUtils.isEmpty(sources) ) {
|
201 |
return false; |
202 |
} |
203 |
return true; |
204 |
} |
205 |
|
206 |
public static String evaluateDynamicText(String source) { |
207 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
208 |
return manager.evaluateDynamicText(source);
|
209 |
} |
210 |
|
211 |
public static String evaluateDynamicText(SymbolTable symbolTable, String source) { |
212 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
213 |
return manager.evaluateDynamicText(symbolTable, source);
|
214 |
} |
215 |
|
216 |
public static File evaluateFilename(File source) { |
217 |
return evaluateFilename(null, source); |
218 |
} |
219 |
|
220 |
public static URL evaluateURL(URL source) { |
221 |
return evaluateURL(null, source); |
222 |
} |
223 |
|
224 |
public static boolean isDynamicFilename(File source) { |
225 |
if( source == null ) { |
226 |
return false; |
227 |
} |
228 |
return isDynamicText(source.getPath());
|
229 |
} |
230 |
|
231 |
public static boolean isDynamicURL(URL source) { |
232 |
if( source == null ) { |
233 |
return false; |
234 |
} |
235 |
return isDynamicText(source.toString());
|
236 |
} |
237 |
|
238 |
public static File createDynamicFile(Value builder) { |
239 |
File f = new File(surroundByDynamicTextTag(builder.toString())); |
240 |
return f;
|
241 |
} |
242 |
|
243 |
public static File createDynamicFile(String expression) { |
244 |
File f = new File(surroundByDynamicTextTag(expression)); |
245 |
return f;
|
246 |
} |
247 |
|
248 |
@SuppressWarnings("StringEquality") |
249 |
public static File evaluateFilename(SymbolTable symbolTable, File source) { |
250 |
String src = source.getPath();
|
251 |
if( !isDynamicText(src) ) {
|
252 |
return source;
|
253 |
} |
254 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
255 |
String r = manager.evaluateDynamicText(symbolTable, src);
|
256 |
if( r == src ) { // !!! I compare that it is the same pointer, it is what I want. |
257 |
return source;
|
258 |
} |
259 |
File f = new File(r); |
260 |
return f;
|
261 |
} |
262 |
|
263 |
@SuppressWarnings("StringEquality") |
264 |
public static URL evaluateURL(SymbolTable symbolTable, URL source) { |
265 |
String src = source.toString();
|
266 |
if( !isDynamicText(src) ) {
|
267 |
return source;
|
268 |
} |
269 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
270 |
String r = manager.evaluateDynamicText(symbolTable, src);
|
271 |
if( r == src ) { // !!! I compare that it is the same pointer, it is what I want. |
272 |
return source;
|
273 |
} |
274 |
try {
|
275 |
URL url = new URL(r); |
276 |
return url;
|
277 |
} catch (MalformedURLException ex) { |
278 |
return source;
|
279 |
} |
280 |
} |
281 |
|
282 |
public static int parseInt(String s) throws NumberFormatException { |
283 |
if( StringUtils.isBlank(s) ) {
|
284 |
throw new NumberFormatException("Can't get integer from a blank string."); |
285 |
} |
286 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
287 |
SymbolTable symbolTable = null; //manager.getInmutableSymbolTable(); |
288 |
Object x;
|
289 |
try {
|
290 |
x = manager.evaluate(symbolTable, s); |
291 |
if( x instanceof Number ) { |
292 |
return ((Number) x).intValue(); |
293 |
} |
294 |
} catch(Exception ex) { |
295 |
NumberFormatException ex1 = new NumberFormatException("Can't get integer from '"+s+"'."); |
296 |
ex1.initCause(ex); |
297 |
throw ex;
|
298 |
} |
299 |
if( x == null ) { |
300 |
throw new NumberFormatException("Can't get integer from '"+s+"' value is null."); |
301 |
} |
302 |
throw new NumberFormatException("Can't get integer from '"+s+"' value is a "+x.getClass().getSimpleName()+"."); |
303 |
} |
304 |
|
305 |
public static long parseLong(String s) throws NumberFormatException { |
306 |
if( StringUtils.isBlank(s) ) {
|
307 |
throw new NumberFormatException("Can't get long from a blank string."); |
308 |
} |
309 |
try {
|
310 |
int value = Integer.parseInt(s); |
311 |
return value;
|
312 |
} catch(Exception ex) { |
313 |
|
314 |
} |
315 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
316 |
SymbolTable symbolTable = null; //manager.getInmutableSymbolTable(); |
317 |
Object x;
|
318 |
try {
|
319 |
x = manager.evaluate(symbolTable, s); |
320 |
if( x instanceof Number ) { |
321 |
return ((Number) x).longValue(); |
322 |
} |
323 |
} catch(Exception ex) { |
324 |
NumberFormatException ex1 = new NumberFormatException("Can't get long from '"+s+"'."); |
325 |
ex1.initCause(ex); |
326 |
throw ex;
|
327 |
} |
328 |
if( x == null ) { |
329 |
throw new NumberFormatException("Can't get long from '"+s+"' value is null."); |
330 |
} |
331 |
throw new NumberFormatException("Can't get long from '"+s+"' value is a "+x.getClass().getSimpleName()+"."); |
332 |
} |
333 |
|
334 |
public static double parseDouble(String s) throws NumberFormatException { |
335 |
if( StringUtils.isBlank(s) ) {
|
336 |
throw new NumberFormatException("Can't get double from a blank string."); |
337 |
} |
338 |
try {
|
339 |
double value = Double.parseDouble(s); |
340 |
return value;
|
341 |
} catch(Exception ex) { |
342 |
|
343 |
} |
344 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
345 |
SymbolTable symbolTable = null; //manager.getInmutableSymbolTable(); |
346 |
Object x;
|
347 |
try {
|
348 |
x = manager.evaluate(symbolTable, s); |
349 |
if( x instanceof Number ) { |
350 |
return ((Number) x).doubleValue(); |
351 |
} |
352 |
} catch(Exception ex) { |
353 |
NumberFormatException ex1 = new NumberFormatException("Can't get double from '"+s+"'."); |
354 |
ex1.initCause(ex); |
355 |
throw ex;
|
356 |
} |
357 |
if( x == null ) { |
358 |
throw new NumberFormatException("Can't get double from '"+s+"' value is null."); |
359 |
} |
360 |
throw new NumberFormatException("Can't get double from '"+s+"' value is a "+x.getClass().getSimpleName()+"."); |
361 |
} |
362 |
|
363 |
public static Compiler createCompiler() { |
364 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
365 |
Compiler compiler = manager.createCompiler();
|
366 |
return compiler;
|
367 |
} |
368 |
|
369 |
public static Interpreter createInterpreter() { |
370 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
371 |
Interpreter interpreter = manager.createInterpreter(); |
372 |
return interpreter;
|
373 |
} |
374 |
|
375 |
public static Optimizer createOptimizer() { |
376 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
377 |
Optimizer optimizer = manager.createOptimizer(); |
378 |
return optimizer;
|
379 |
} |
380 |
|
381 |
public static String repr(Object value) { |
382 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
383 |
ReprMethod method = manager.getReprMethod(value); |
384 |
return method.repr(value);
|
385 |
} |
386 |
|
387 |
public static CodeBuilder createCodeBuilder() { |
388 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
389 |
return manager.createCodeBuilder();
|
390 |
} |
391 |
|
392 |
private static final List<String> TRUE_VALUES = ListBuilder.create("true","on","t", "1", "-1" ); |
393 |
private static final List<String> FALSE_VALUES = ListBuilder.create("false","off","f", "0" ); |
394 |
|
395 |
public static boolean parseBoolean(SymbolTable symbolTable, String expression, boolean defaultValue) { |
396 |
expression = StringUtils.trimToNull(expression); |
397 |
if( StringUtils.isBlank(expression) ) {
|
398 |
return defaultValue;
|
399 |
} |
400 |
if( TRUE_VALUES.contains(expression.toLowerCase())) {
|
401 |
return true; |
402 |
} |
403 |
if( FALSE_VALUES.contains(expression.toLowerCase())) {
|
404 |
return false; |
405 |
} |
406 |
try {
|
407 |
return (boolean) ExpressionUtils.evaluate(symbolTable, expression); |
408 |
} catch(Exception ex) { |
409 |
return defaultValue;
|
410 |
} |
411 |
} |
412 |
|
413 |
public static boolean parseBoolean(String expression) { |
414 |
expression = StringUtils.trimToNull(expression); |
415 |
if( StringUtils.isBlank(expression) ) {
|
416 |
throw new IllegalArgumentException("Can't get boolean from a blank string."); |
417 |
} |
418 |
if( TRUE_VALUES.contains(expression.toLowerCase())) {
|
419 |
return true; |
420 |
} |
421 |
if( FALSE_VALUES.contains(expression.toLowerCase())) {
|
422 |
return false; |
423 |
} |
424 |
Object x;
|
425 |
try {
|
426 |
x = ExpressionUtils.evaluate(null, expression);
|
427 |
return (boolean) x; |
428 |
} catch(Exception ex) { |
429 |
IllegalArgumentException ex1 = new IllegalArgumentException("Can't get boolean from '"+expression+"'."); |
430 |
ex1.initCause(ex); |
431 |
throw ex;
|
432 |
} |
433 |
} |
434 |
|
435 |
public static int parseInt(SymbolTable symbolTable, String expression, int defaultValue) { |
436 |
if( StringUtils.isBlank(expression) ) {
|
437 |
return defaultValue;
|
438 |
} |
439 |
try {
|
440 |
int value = Integer.parseInt(expression); |
441 |
return value;
|
442 |
} catch(Exception ex) { |
443 |
|
444 |
} |
445 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
446 |
Object x;
|
447 |
try {
|
448 |
x = manager.evaluate(symbolTable, expression); |
449 |
if( x instanceof Number ) { |
450 |
return ((Number) x).intValue(); |
451 |
} |
452 |
} catch(Exception ex) { |
453 |
} |
454 |
return defaultValue;
|
455 |
} |
456 |
|
457 |
public static long parseLong(SymbolTable symbolTable, String expression, long defaultValue) { |
458 |
if( StringUtils.isBlank(expression) ) {
|
459 |
return defaultValue;
|
460 |
} |
461 |
try {
|
462 |
int value = Integer.parseInt(expression); |
463 |
return value;
|
464 |
} catch(Exception ex) { |
465 |
|
466 |
} |
467 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
468 |
Object x;
|
469 |
try {
|
470 |
x = manager.evaluate(symbolTable, expression); |
471 |
if( x instanceof Number ) { |
472 |
return ((Number) x).longValue(); |
473 |
} |
474 |
} catch(Exception ex) { |
475 |
} |
476 |
return defaultValue;
|
477 |
} |
478 |
|
479 |
public static double parseDouble(SymbolTable symbolTable, String expression, double defaultValue) { |
480 |
if( StringUtils.isBlank(expression) ) {
|
481 |
return defaultValue;
|
482 |
} |
483 |
try {
|
484 |
double value = Double.parseDouble(expression); |
485 |
return value;
|
486 |
} catch(Exception ex) { |
487 |
|
488 |
} |
489 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
490 |
Object x;
|
491 |
try {
|
492 |
x = manager.evaluate(symbolTable, expression); |
493 |
if( x instanceof Number ) { |
494 |
return ((Number) x).doubleValue(); |
495 |
} |
496 |
} catch(Exception ex) { |
497 |
} |
498 |
return defaultValue;
|
499 |
} |
500 |
|
501 |
private static final Pattern COLOR_PATTERN3 = Pattern.compile("COLOR[(][ ]*(?<R>[0-9]{1,3})[ ]*,[ ]*(?<G>[0-9]{1,3})[ ]*,[ ]*(?<A>[0-9]{1,3})[ ]*[)]", Pattern.CASE_INSENSITIVE); |
502 |
private static final Pattern COLOR_PATTERN4 = Pattern.compile("COLOR[(][ ]*(?<R>[0-9]{1,3})[ ]*,[ ]*(?<G>[0-9]{1,3})[ ]*,[ ]*(?<B>[0-9]{1,3})[ ]*,[ ]*(?<A>[0-9]{1,3})[ ]*[)]", Pattern.CASE_INSENSITIVE); |
503 |
|
504 |
public static Color parseColor(SymbolTable symbolTable, String expression, Color defaultValue) { |
505 |
if( StringUtils.isBlank(expression) ) {
|
506 |
return defaultValue;
|
507 |
} |
508 |
try {
|
509 |
if( StringUtils.startsWithIgnoreCase(expression, "color(") && |
510 |
StringUtils.endsWithIgnoreCase(expression, ")")) {
|
511 |
Matcher m = COLOR_PATTERN4.matcher(expression);
|
512 |
if( m != null && m.matches()) { |
513 |
Color color = new Color( |
514 |
Integer.valueOf(m.group("R")), |
515 |
Integer.valueOf(m.group("G")), |
516 |
Integer.valueOf(m.group("B")), |
517 |
Integer.valueOf(m.group("A")) |
518 |
); |
519 |
return color;
|
520 |
} |
521 |
m = COLOR_PATTERN3.matcher(expression); |
522 |
if( m != null && m.matches()) { |
523 |
Color color = new Color( |
524 |
Integer.valueOf(m.group("R")), |
525 |
Integer.valueOf(m.group("G")), |
526 |
Integer.valueOf(m.group("B")), |
527 |
Integer.valueOf(m.group("A")) |
528 |
); |
529 |
return color;
|
530 |
} |
531 |
} |
532 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
533 |
Object x;
|
534 |
x = manager.evaluate(symbolTable, expression); |
535 |
if( x instanceof Color ) { |
536 |
return (Color) x; |
537 |
} |
538 |
if( x instanceof Number ) { |
539 |
return new Color(((Number) x).intValue()); |
540 |
} |
541 |
} catch(Exception ex) { |
542 |
} |
543 |
return defaultValue;
|
544 |
} |
545 |
|
546 |
public static Color parseColor(String expression) { |
547 |
if( StringUtils.isBlank(expression) ) {
|
548 |
throw new IllegalArgumentException("Can't get color from a blank string."); |
549 |
} |
550 |
Object x;
|
551 |
try {
|
552 |
if( StringUtils.startsWithIgnoreCase(expression, "color(") && |
553 |
StringUtils.endsWithIgnoreCase(expression, ")")) {
|
554 |
Matcher m = COLOR_PATTERN4.matcher(expression);
|
555 |
if( m != null && m.matches()) { |
556 |
Color color = new Color( |
557 |
Integer.valueOf(m.group("R")), |
558 |
Integer.valueOf(m.group("G")), |
559 |
Integer.valueOf(m.group("B")), |
560 |
Integer.valueOf(m.group("A")) |
561 |
); |
562 |
return color;
|
563 |
} |
564 |
m = COLOR_PATTERN3.matcher(expression); |
565 |
if( m != null && m.matches()) { |
566 |
Color color = new Color( |
567 |
Integer.valueOf(m.group("R")), |
568 |
Integer.valueOf(m.group("G")), |
569 |
Integer.valueOf(m.group("B")), |
570 |
Integer.valueOf(m.group("A")) |
571 |
); |
572 |
return color;
|
573 |
} |
574 |
} |
575 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
576 |
x = manager.evaluate(null, expression);
|
577 |
if( x instanceof Color ) { |
578 |
return (Color) x; |
579 |
} |
580 |
if( x instanceof Number ) { |
581 |
return new Color(((Number) x).intValue()); |
582 |
} |
583 |
} catch(Exception ex) { |
584 |
IllegalArgumentException ex1 = new IllegalArgumentException("Can't get color from '"+expression+"'."); |
585 |
ex1.initCause(ex); |
586 |
throw ex;
|
587 |
} |
588 |
if( x == null ) { |
589 |
throw new IllegalArgumentException("Can't get double from '"+expression+"' value is null."); |
590 |
} |
591 |
throw new IllegalArgumentException("Can't get double from '"+expression+"' value is a "+x.getClass().getSimpleName()+"."); |
592 |
} |
593 |
|
594 |
} |
595 |
|