X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=inline;f=org.argeo.cms.jcr%2Fsrc%2Forg%2Fargeo%2Fjcr%2FJcr.java;h=bdeaac707511d554403fcea465b8fc80780f9de5;hb=87547963e298202bcae9cf81bc88c44feddac5f4;hp=49b008d70751e24e4f362c9e5e2b9caab66f06cc;hpb=bce03099b0d2f1758e7a3d74fba339d0200924d5;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..bdeaac7 100644
--- a/org.argeo.cms.jcr/src/org/argeo/jcr/Jcr.java
+++ b/org.argeo.cms.jcr/src/org/argeo/jcr/Jcr.java
@@ -49,11 +49,15 @@ public class Jcr {
/**
* The name of a node which will be serialized as XML text, as per section 7.3.1
* of the JCR 2.0 specifications.
+ *
+ * @see Workspace#NAME_JCR_XMLTEXT
*/
public final static String JCR_XMLTEXT = "jcr:xmltext";
/**
* The name of a property which will be serialized as XML text, as per section
* 7.3.1 of the JCR 2.0 specifications.
+ *
+ * @see Workspace#NAME_JCR_XMLCHARACTERS
*/
public final static String JCR_XMLCHARACTERS = "jcr:xmlcharacters";
/**
@@ -427,6 +431,20 @@ public class Jcr {
}
}
+ /**
+ * Whether this node has this property.
+ *
+ * @see Node#hasProperty(String)
+ * @throws JcrException caused by {@link RepositoryException}
+ */
+ public static boolean hasProperty(Node node, String property) {
+ try {
+ return node.hasProperty(property);
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot check whether " + node + " has property " + property, e);
+ }
+ }
+
/**
* Set a property to the given value, or remove it if the value is
* null
.
@@ -599,6 +617,7 @@ public class Jcr {
}
}
+ @SuppressWarnings("unchecked")
public static T getAs(Node node, String property, Class clss) {
if (String.class.isAssignableFrom(clss)) {
return (T) get(node, property);
@@ -609,6 +628,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.