Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java @ 5608:62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
pattern obeys to java.text.SimpleDateFormat.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Tue, 09 Apr 2013 12:00:52 +0200 |
parents | 7e837c5c377b |
children | ce982943ab46 |
comparison
equal
deleted
inserted
replaced
5607:6e0d122904f9 | 5608:62513c9183ba |
---|---|
1 package de.intevation.flys.artifacts.datacage.templating; | 1 package de.intevation.flys.artifacts.datacage.templating; |
2 | 2 |
3 import java.text.SimpleDateFormat; | |
3 import java.util.ArrayList; | 4 import java.util.ArrayList; |
4 import java.util.Collection; | 5 import java.util.Collection; |
6 import java.util.Date; | |
5 import java.util.List; | 7 import java.util.List; |
6 import java.util.Map; | 8 import java.util.Map; |
7 | 9 |
8 import javax.xml.namespace.QName; | 10 import javax.xml.namespace.QName; |
9 | 11 |
86 | 88 |
87 addFunction("has-result", 0, new XPathFunction() { | 89 addFunction("has-result", 0, new XPathFunction() { |
88 @Override | 90 @Override |
89 public Object evaluate(List args) throws XPathFunctionException { | 91 public Object evaluate(List args) throws XPathFunctionException { |
90 return FunctionResolver.this.buildHelper.hasResult(); | 92 return FunctionResolver.this.buildHelper.hasResult(); |
93 } | |
94 }); | |
95 | |
96 addFunction("date-format", 2, new XPathFunction() { | |
97 @Override | |
98 public Object evaluate(List args) throws XPathFunctionException { | |
99 return dateFormat(args); | |
91 } | 100 } |
92 }); | 101 }); |
93 } | 102 } |
94 | 103 |
95 /** | 104 /** |
276 (String)needle, (String)replacement); | 285 (String)needle, (String)replacement); |
277 } else { | 286 } else { |
278 return haystack; | 287 return haystack; |
279 } | 288 } |
280 } | 289 } |
290 | |
291 public Object dateFormat(List args) throws XPathFunctionException { | |
292 Object pattern = args.get(0); | |
293 Object date = args.get(1); | |
294 if (pattern instanceof String && date instanceof Date) { | |
295 try { | |
296 // TODO: Take locale into account. | |
297 return new SimpleDateFormat((String)pattern).format((Date)date); | |
298 } | |
299 catch (IllegalArgumentException iae) { | |
300 throw new XPathFunctionException(iae); | |
301 } | |
302 } | |
303 return ""; | |
304 } | |
281 } | 305 } |
282 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 306 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |