X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.api.acr%2Fsrc%2Forg%2Fargeo%2Fapi%2Facr%2FContent.java;h=df5c149e6fc1fc696187d197766ad5f9cf0c2c52;hb=5724ab347ddfba8f2b21cdcc2fa0b8e1e2b4e527;hp=b605fa1e0062140b18fd5b1784fe8ea0fd6171bc;hpb=d2bca81ff63496bf1d879f4cbcd6a531f598e69c;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 b605fa1e0..df5c149e6 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(); @@ -82,25 +84,11 @@ public interface Content extends Iterable, Map { } List res = getMultiple(key, type); return res; -// if (res == null) -// return null; -// else { -// if (res.isEmpty()) -// throw new IllegalStateException("Metadata " + key + " is not availabel as list of type " + type); -// return res.get(); -// } } /* * CONTENT OPERATIONS */ -// default CompletionStage edit(Consumer work) { -// return CompletableFuture.supplyAsync(() -> { -// work.accept(this); -// return this; -// }).minimalCompletionStage(); -// } - Content add(QName name, QName... classes); default Content add(String name, QName... classes) { @@ -128,6 +116,14 @@ public interface Content extends Iterable, Map { return true; } + /** AND */ + default boolean isContentClass(QNamed... contentClass) { + List lst = new ArrayList<>(); + for (QNamed qNamed : contentClass) + lst.add(qNamed.qName()); + return isContentClass(lst.toArray(new QName[lst.size()])); + } + /** OR */ default boolean hasContentClass(QName... contentClass) { List contentClasses = getContentClasses(); @@ -138,8 +134,12 @@ public interface Content extends Iterable, Map { return false; } - default boolean hasContentClass(QNamed contentClass) { - return hasContentClass(contentClass.qName()); + /** OR */ + default boolean hasContentClass(QNamed... contentClass) { + List lst = new ArrayList<>(); + for (QNamed qNamed : contentClass) + lst.add(qNamed.qName()); + return hasContentClass(lst.toArray(new QName[lst.size()])); } /* @@ -210,6 +210,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()) @@ -230,29 +238,51 @@ public interface Content extends Iterable, Map { /* * ATTR AS STRING */ + /** + * Convenience method returning an attribute as a {@link String}. + * + * @param key the attribute name + * @return the attribute value as a {@link String} or null. + * + * @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); } + /** + * Convenience method returning an attribute as a {@link String}. + * + * @param key the attribute name + * @return the attribute value as a {@link String} or null. + * + * @see Object#toString() + */ default String attr(QNamed key) { return attr(key.qName()); } + /** + * Convenience method returning an attribute as a {@link String}. + * + * @param key the attribute name + * @return the attribute value as a {@link String} or null. + * + * @see Object#toString() + */ default String attr(String key) { return attr(unqualified(key)); } -// -// default String attr(Object key) { -// return key != null ? attr(key.toString()) : attr(null); -// } -// -// default A get(Object key, Class clss) { -// return key != null ? get(key.toString(), clss) : get(null, clss); -// } + + /* + * CONTEXT + */ + /** + * A content within this repository + * + * @param path either an absolute path or a path relative to this content + */ + Optional getContent(String path); /* * EXPERIMENTAL UNSUPPORTED