]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.api.acr/src/org/argeo/api/acr/Content.java
Improve JTS support
[lgpl/argeo-commons.git] / org.argeo.api.acr / src / org / argeo / api / acr / Content.java
index 4956037c8ab268dfc38e101681337e4353bce477..33ddeecedb2d07018cbdbd3d8248193350be3b1b 100644 (file)
@@ -16,6 +16,8 @@ import javax.xml.namespace.QName;
  * A semi-structured content, with attributes, within a hierarchical structure.
  */
 public interface Content extends Iterable<Content>, Map<QName, Object> {
+       /** The base of a repository path. */
+       String ROOT_PATH = "/";
 
        QName getName();
 
@@ -87,12 +89,29 @@ public interface Content extends Iterable<Content>, Map<QName, Object> {
        /*
         * CONTENT OPERATIONS
         */
+       /** Adds a new empty {@link Content} to this {@link Content}. */
        Content add(QName name, QName... classes);
 
+       /**
+        * Adds a new {@link Content} to this {@link Content}, setting the provided
+        * attributes. The provided attributes can be used as hints by the
+        * implementation. In particular, setting {@link DName#getcontenttype} will
+        * imply that this content has a file semantic.
+        */
+       default Content add(QName name, Map<QName, Object> attrs, QName... classes) {
+               Content child = add(name, classes);
+               putAll(attrs);
+               return child;
+       }
+
        default Content add(String name, QName... classes) {
                return add(unqualified(name), classes);
        }
 
+       default Content add(String name, Map<QName, Object> attrs, QName... classes) {
+               return add(unqualified(name), attrs, classes);
+       }
+
        void remove();
 
        /*
@@ -208,6 +227,14 @@ public interface Content extends Iterable<Content>, Map<QName, Object> {
                return res;
        }
 
+       default List<Content> children(QNamed name) {
+               return children(name.qName());
+       }
+
+       default Optional<Content> soleChild(QNamed name) {
+               return soleChild(name.qName());
+       }
+
        default Optional<Content> soleChild(QName name) {
                List<Content> res = children(name);
                if (res.isEmpty())
@@ -237,11 +264,7 @@ public interface Content extends Iterable<Content>, Map<QName, Object> {
         * @see Object#toString()
         */
        default String attr(QName key) {
-               // TODO check String type?
-               Object obj = get(key);
-               if (obj == null)
-                       return null;
-               return obj.toString();
+               return get(key, String.class).orElse(null);
        }
 
        /**
@@ -274,9 +297,9 @@ public interface Content extends Iterable<Content>, Map<QName, Object> {
        /**
         * A content within this repository
         * 
-        * @param path either an abolute path or a path relative to this content
+        * @param path either an absolute path or a path relative to this content
         */
-       Content getContent(String path);
+       Optional<Content> getContent(String path);
 
        /*
         * EXPERIMENTAL UNSUPPORTED