X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.api.acr%2Fsrc%2Forg%2Fargeo%2Fapi%2Facr%2FContent.java;h=f7600f540e63ea3b20311c94f2824cd2c7703151;hb=7b9869409642fbad1d219b2f7caec25b7a35c4aa;hp=865705f64cde265bfc08dbb8862a91f526a4429a;hpb=9ece61bb03dd788ac5f2e26ef33c0b4e3859d4d9;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.api.acr/src/org/argeo/api/acr/Content.java b/org.argeo.api.acr/src/org/argeo/api/acr/Content.java index 865705f64..f7600f540 100644 --- a/org.argeo.api.acr/src/org/argeo/api/acr/Content.java +++ b/org.argeo.api.acr/src/org/argeo/api/acr/Content.java @@ -16,6 +16,8 @@ import javax.xml.namespace.QName; * A semi-structured content, with attributes, within a hierarchical structure. */ public interface Content extends Iterable, Map { + /** The base of a repository path. */ + String ROOT_PATH = "/"; QName getName(); @@ -87,12 +89,29 @@ public interface Content extends Iterable, Map { /* * 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 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 attrs, QName... classes) { + return add(unqualified(name), attrs, classes); + } + void remove(); /* @@ -208,6 +227,14 @@ public interface Content extends Iterable, Map { return res; } + default List children(QNamed name) { + return children(name.qName()); + } + + default Optional soleChild(QNamed name) { + return soleChild(name.qName()); + } + default Optional soleChild(QName name) { List res = children(name); if (res.isEmpty()) @@ -217,6 +244,10 @@ public interface Content extends Iterable, Map { return Optional.of(res.get(0)); } + default Content soleOrAddChild(QName name, QName... classes) { + return soleChild(name).orElseGet(() -> this.add(name, classes)); + } + default Content child(QName name) { return soleChild(name).orElseThrow(); } @@ -270,9 +301,9 @@ public interface Content extends Iterable, Map { /** * 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 getContent(String path); /* * EXPERIMENTAL UNSUPPORTED