Add hasProperty
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 25 Jun 2023 05:43:28 +0000 (07:43 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 25 Jun 2023 05:43:28 +0000 (07:43 +0200)
org.argeo.cms.jcr/src/org/argeo/jcr/Jcr.java

index 88f534503d5a142e5a4d87d4deec57a0e5c24979..bdeaac707511d554403fcea465b8fc80780f9de5 100644 (file)
@@ -431,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
         * <code>null</code>.
@@ -603,6 +617,7 @@ public class Jcr {
                }
        }
 
+       @SuppressWarnings("unchecked")
        public static <T> T getAs(Node node, String property, Class<T> clss) {
                if (String.class.isAssignableFrom(clss)) {
                        return (T) get(node, property);