X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.jcr%2Fsrc%2Forg%2Fargeo%2Fjcr%2FJcr.java;h=2ff49e7ce92c988902a54d613acd6e39ef39ea08;hb=705b111ed306ae7daefb7d02247a7e677aea1cbd;hp=49b008d70751e24e4f362c9e5e2b9caab66f06cc;hpb=d1f34e253307b336ee3256a50c1cc4f4e96a2770;p=gpl%2Fargeo-jcr.git diff --git a/org.argeo.cms.jcr/src/org/argeo/jcr/Jcr.java b/org.argeo.cms.jcr/src/org/argeo/jcr/Jcr.java index 49b008d..2ff49e7 100644 --- a/org.argeo.cms.jcr/src/org/argeo/jcr/Jcr.java +++ b/org.argeo.cms.jcr/src/org/argeo/jcr/Jcr.java @@ -609,6 +609,23 @@ public class Jcr { } } + /** + * Retrieve a {@link PropertyType#DATE} property as an {@link Instant}. + * + * @return the property value, or null if not found. + */ + public static Instant getAsInstant(Node node, String property) { + try { + if (!node.hasProperty(property)) + return null; + Calendar calendar = node.getProperty(property).getDate(); + return calendar.getTime().toInstant(); + } catch (RepositoryException e) { + throw new JcrException("Cannot get property " + property + " of " + node + " as an instant.", e); + } + + } + /** * Get a multiple property as a list, doing a best effort to cast it as the * target list.