Improve ACR
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 24 Sep 2023 09:34:12 +0000 (11:34 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 24 Sep 2023 09:34:12 +0000 (11:34 +0200)
org.argeo.api.acr/src/org/argeo/api/acr/DName.java
org.argeo.api.acr/src/org/argeo/api/acr/QNamed.java
org.argeo.api.acr/src/org/argeo/api/acr/search/ContentFilter.java

index be065a8d96750ef8d0e2399be80bf3b0753e49a6..d39f35d86ff96104d8693477e8f77cb70034ac1d 100644 (file)
@@ -23,15 +23,38 @@ public enum DName implements QNamed
        // RFC4918 (WebDav) value used as CR class
        collection, //
 
-       // RFC3744 (ACL) properties uase as CR attr
+       // RFC3744 (ACL) properties used as CR attr
        owner, //
        group, //
+
+       // RFC3253 (versioning) properties used as CR attr
+       checkedOut("checked-out"), //
+       checkedIn("checked-in"), //
        //
        ;
 
        public final static String WEBDAV_NAMESPACE_URI = "DAV:";
        public final static String WEBDAV_DEFAULT_PREFIX = "D";
 
+       private final String localName;
+
+       private DName(String localName) {
+               assert localName != null;
+               this.localName = localName;
+       }
+
+       private DName() {
+               this.localName = null;
+       }
+
+       @Override
+       public String localName() {
+               if (localName != null)
+                       return localName;
+               else
+                       return name();
+       }
+
        @Override
        public String getNamespace() {
                return WEBDAV_NAMESPACE_URI;
index 73ae4f02ead43b8c69038712e6e3a17477090ffe..9852a602a339e3b8f796a2c85186933e53f4dd69 100644 (file)
@@ -15,23 +15,52 @@ public interface QNamed extends Supplier<String> {
                return name();
        }
 
+       /**
+        * A {@link QName} corresponding to this definition. Calls
+        * {@link #createQName()} by default, but it could return a cached value.
+        */
        default QName qName() {
-               return new ContentName(getNamespace(), localName(), getDefaultPrefix());
+               return createQName();
        }
 
+       /**
+        * A prefixed representation of this qualified name within the provided
+        * {@link NamespaceContext}.
+        */
        default String get(NamespaceContext namespaceContext) {
                return namespaceContext.getPrefix(getNamespace()) + ":" + localName();
        }
 
-       /** This qualified named with its default prefix. If it is unqualified this method should be overridden, or QNamed.Unqualified be used. */
+       /**
+        * Create a {@link QName} corresponding on this definition. Can typically be
+        * used to cache the {@link QName} in enums.
+        */
+       default QName createQName() {
+               return new ContentName(getNamespace(), localName(), getDefaultPrefix());
+       }
+
+       /**
+        * This qualified named with its default prefix. If it is unqualified this
+        * method should be overridden, or QNamed.Unqualified be used.
+        */
        default String get() {
                return getDefaultPrefix() + ":" + localName();
        }
 
+       /** The namespace URI of this qualified name. */
        String getNamespace();
 
+       /**
+        * The default prefix of this qualified name, as expected to be found in
+        * {@link RuntimeNamespaceContext}.
+        */
        String getDefaultPrefix();
 
+       /** Compares to a plain {@link QName}. */
+       default boolean equals(QName qName) {
+               return qName().equals(qName);
+       }
+
        /** To be used by enums without namespace (typically XML attributes). */
        static interface Unqualified extends QNamed {
                @Override
index 45f2d848c4183754c3935e73bdc77d0c1f5d4590..55ed21531348373a686344374cebdd8252976157 100644 (file)
@@ -74,10 +74,18 @@ public abstract class ContentFilter<COMPOSITION extends Composition> implements
        }
 
        public COMPOSITION eq(QNamed attr, Object value) {
-               addConstraint(new Eq(attr.qName(), value));
+               return eq(attr.qName(), value);
+       }
+
+       public COMPOSITION isDefined(QName attr) {
+               addConstraint(new IsDefined(attr));
                return composition;
        }
 
+       public COMPOSITION isDefined(QNamed attr) {
+               return isDefined(attr.qName());
+       }
+
        /*
         * UTILITIES
         */
@@ -148,6 +156,19 @@ public abstract class ContentFilter<COMPOSITION extends Composition> implements
 
        }
 
+       public static class IsDefined implements Constraint {
+               final QName prop;
+
+               public IsDefined(QName prop) {
+                       super();
+                       this.prop = prop;
+               }
+
+               public QName getProp() {
+                       return prop;
+               }
+       }
+
        public static class IsContentClass implements Constraint {
                final QName[] contentClasses;