Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java @ 7969:912cf4ec09d1
Datacage function resolver: Declare static functions static.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 26 Jun 2014 13:00:18 +0200 |
parents | 09c9920e6f24 |
children | e4606eae8ea5 |
comparison
equal
deleted
inserted
replaced
7968:09c9920e6f24 | 7969:912cf4ec09d1 |
---|---|
253 ? entry.find(arity) | 253 ? entry.find(arity) |
254 : null; | 254 : null; |
255 } | 255 } |
256 | 256 |
257 /** Implementation of case-ignoring dc:contains. */ | 257 /** Implementation of case-ignoring dc:contains. */ |
258 public Object contains(List args) throws XPathFunctionException { | 258 public static Object contains(List args) throws XPathFunctionException { |
259 Object haystack = args.get(0); | 259 Object haystack = args.get(0); |
260 Object needle = args.get(1); | 260 Object needle = args.get(1); |
261 | 261 |
262 if (needle instanceof String && !(haystack instanceof String)) { | 262 if (needle instanceof String && !(haystack instanceof String)) { |
263 needle = ((String)needle).toUpperCase(); | 263 needle = ((String)needle).toUpperCase(); |
297 } | 297 } |
298 | 298 |
299 /** Implementation for getting the minimum value of location or distance | 299 /** Implementation for getting the minimum value of location or distance |
300 * dc:fromValue. | 300 * dc:fromValue. |
301 */ | 301 */ |
302 public Object fromValue(List args) throws XPathFunctionException { | 302 public static Object fromValue(List args) throws XPathFunctionException { |
303 Object mode = args.get(0); | 303 Object mode = args.get(0); |
304 Object locations = args.get(1); | 304 Object locations = args.get(1); |
305 Object from = args.get(2); | 305 Object from = args.get(2); |
306 | 306 |
307 if ((mode instanceof String && mode.equals("location")) || | 307 if ((mode instanceof String && mode.equals("location")) || |
343 } | 343 } |
344 | 344 |
345 /** Implementation for getting the maximum value of location or distance | 345 /** Implementation for getting the maximum value of location or distance |
346 * dc:toValue. | 346 * dc:toValue. |
347 */ | 347 */ |
348 public Object toValue(List args) throws XPathFunctionException { | 348 public static Object toValue(List args) throws XPathFunctionException { |
349 Object mode = args.get(0); | 349 Object mode = args.get(0); |
350 Object locations = args.get(1); | 350 Object locations = args.get(1); |
351 Object to = args.get(2); | 351 Object to = args.get(2); |
352 | 352 |
353 if ((mode instanceof String && mode.equals("location")) || | 353 if ((mode instanceof String && mode.equals("location")) || |
391 } | 391 } |
392 | 392 |
393 /** Implementation for doing a string replace | 393 /** Implementation for doing a string replace |
394 * dc:replace . | 394 * dc:replace . |
395 */ | 395 */ |
396 public Object replace(List args) throws XPathFunctionException { | 396 public static Object replace(List args) throws XPathFunctionException { |
397 Object haystack = args.get(0); | 397 Object haystack = args.get(0); |
398 Object needle = args.get(1); | 398 Object needle = args.get(1); |
399 Object replacement = args.get(2); | 399 Object replacement = args.get(2); |
400 | 400 |
401 if (needle instanceof String | 401 if (needle instanceof String |
408 } | 408 } |
409 | 409 |
410 /** Implementation for doing a string replace | 410 /** Implementation for doing a string replace |
411 * dc:replace-all | 411 * dc:replace-all |
412 */ | 412 */ |
413 public Object replaceAll(List args) throws XPathFunctionException { | 413 public static Object replaceAll(List args) throws XPathFunctionException { |
414 Object haystack = args.get(0); | 414 Object haystack = args.get(0); |
415 Object needle = args.get(1); | 415 Object needle = args.get(1); |
416 Object replacement = args.get(2); | 416 Object replacement = args.get(2); |
417 | 417 |
418 if (needle instanceof String | 418 if (needle instanceof String |
422 (String)needle, (String)replacement); | 422 (String)needle, (String)replacement); |
423 } | 423 } |
424 return haystack; | 424 return haystack; |
425 } | 425 } |
426 | 426 |
427 public Object dateFormat(List args) throws XPathFunctionException { | 427 public static Object dateFormat(List args) throws XPathFunctionException { |
428 Object pattern = args.get(0); | 428 Object pattern = args.get(0); |
429 Object date = args.get(1); | 429 Object date = args.get(1); |
430 | 430 |
431 try { | 431 try { |
432 // Oracle does not return a date object but an oracle.sql.TIMESTAMP | 432 // Oracle does not return a date object but an oracle.sql.TIMESTAMP |
447 } | 447 } |
448 } | 448 } |
449 return ""; | 449 return ""; |
450 } | 450 } |
451 | 451 |
452 public Set<String> allStateSuccessors(String artifactName, String stateId) { | 452 public static Set<String> allStateSuccessors(String artifactName, String stateId) { |
453 GlobalContext gc = RiverContextFactory.getGlobalContext(); | 453 GlobalContext gc = RiverContextFactory.getGlobalContext(); |
454 if (gc == null) { | 454 if (gc == null) { |
455 return Collections.<String>emptySet(); | 455 return Collections.<String>emptySet(); |
456 } | 456 } |
457 Object o = gc.get(RiverContext.TRANSITION_ENGINE_KEY); | 457 Object o = gc.get(RiverContext.TRANSITION_ENGINE_KEY); |
460 return te.allRecursiveSuccessorStateIds(artifactName, stateId); | 460 return te.allRecursiveSuccessorStateIds(artifactName, stateId); |
461 } | 461 } |
462 return Collections.<String>emptySet(); | 462 return Collections.<String>emptySet(); |
463 } | 463 } |
464 | 464 |
465 public Collection<String> findAll(String needle, String haystack) { | 465 public static Collection<String> findAll(String needle, String haystack) { |
466 | 466 |
467 ArrayList<String> result = new ArrayList<String>(); | 467 ArrayList<String> result = new ArrayList<String>(); |
468 | 468 |
469 Pattern pattern = Pattern.compile(needle); | 469 Pattern pattern = Pattern.compile(needle); |
470 Matcher matcher = pattern.matcher(haystack); | 470 Matcher matcher = pattern.matcher(haystack); |
472 result.add(matcher.group()); | 472 result.add(matcher.group()); |
473 } | 473 } |
474 return result; | 474 return result; |
475 } | 475 } |
476 | 476 |
477 public Number maxNumber(Object list) { | 477 public static Number maxNumber(Object list) { |
478 if (list instanceof Collection) { | 478 if (list instanceof Collection) { |
479 Collection collection = (Collection)list; | 479 Collection collection = (Collection)list; |
480 double max = -Double.MAX_VALUE; | 480 double max = -Double.MAX_VALUE; |
481 for (Object x: collection) { | 481 for (Object x: collection) { |
482 Number n; | 482 Number n; |
512 return list instanceof Number | 512 return list instanceof Number |
513 ? (Number)list | 513 ? (Number)list |
514 : Double.valueOf(Double.MAX_VALUE); | 514 : Double.valueOf(Double.MAX_VALUE); |
515 } | 515 } |
516 | 516 |
517 public Number minNumber(Object list) { | 517 public static Number minNumber(Object list) { |
518 if (list instanceof Collection) { | 518 if (list instanceof Collection) { |
519 Collection collection = (Collection)list; | 519 Collection collection = (Collection)list; |
520 double min = Double.MAX_VALUE; | 520 double min = Double.MAX_VALUE; |
521 for (Object x: collection) { | 521 for (Object x: collection) { |
522 Number n; | 522 Number n; |