Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java @ 8460:081a57c80540
Accept number as argument in dc:date-format().
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 30 Oct 2014 14:17:49 +0100 |
parents | e4606eae8ea5 |
children | 5e38e2924c07 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java Thu Oct 30 14:10:41 2014 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java Thu Oct 30 14:17:49 2014 +0100 @@ -429,23 +429,33 @@ Object date = args.get(1); try { - // Oracle does not return a date object but an oracle.sql.TIMESTAMP - Method meth = date.getClass().getMethod("dateValue", new Class[] {}); - date = meth.invoke(date, new Object [] {}); - } catch (IllegalArgumentException e) { - } catch (IllegalAccessException e) { - } catch (InvocationTargetException e) { - } catch (NoSuchMethodException e) { - } - if (pattern instanceof String && date instanceof Date) { + // TODO: Take locale into account. + SimpleDateFormat format = new SimpleDateFormat((String)pattern); + + if (date instanceof Number) { + return format.format(new Date(((Number)date).longValue())); + } + try { - // TODO: Take locale into account. - return new SimpleDateFormat((String)pattern).format((Date)date); + /* Oracle does not return a date object but + an oracle.sql.TIMESTAMP */ + Method meth = date.getClass() + .getMethod("dateValue", new Class[] {}); + date = meth.invoke(date, new Object[] {}); + } catch (IllegalArgumentException e) { + } catch (IllegalAccessException e) { + } catch (InvocationTargetException e) { + } catch (NoSuchMethodException e) { } - catch (IllegalArgumentException iae) { - throw new XPathFunctionException(iae); + + if (date instanceof Date) { + return format.format((Date)date); } } + catch (IllegalArgumentException iae) { + log.error(iae.getMessage()); + } + return ""; }