Mercurial > dive4elements > river
changeset 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 | 6e0d122904f9 |
children | 80e8ef91223c |
files | flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java |
diffstat | 1 files changed, 24 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java Tue Apr 09 11:53:47 2013 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java Tue Apr 09 12:00:52 2013 +0200 @@ -1,7 +1,9 @@ package de.intevation.flys.artifacts.datacage.templating; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; +import java.util.Date; import java.util.List; import java.util.Map; @@ -90,6 +92,13 @@ return FunctionResolver.this.buildHelper.hasResult(); } }); + + addFunction("date-format", 2, new XPathFunction() { + @Override + public Object evaluate(List args) throws XPathFunctionException { + return dateFormat(args); + } + }); } /** @@ -278,5 +287,20 @@ return haystack; } } + + public Object dateFormat(List args) throws XPathFunctionException { + Object pattern = args.get(0); + Object date = args.get(1); + if (pattern instanceof String && date instanceof Date) { + try { + // TODO: Take locale into account. + return new SimpleDateFormat((String)pattern).format((Date)date); + } + catch (IllegalArgumentException iae) { + throw new XPathFunctionException(iae); + } + } + return ""; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :