]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - ContentUtils.java
d0ce5d1535bcf954242533f0a4d2febafdf16b55
1 package org
.argeo
.cms
.acr
;
3 import java
.io
.PrintStream
;
4 import java
.util
.function
.BiConsumer
;
6 import javax
.xml
.namespace
.QName
;
8 import org
.argeo
.api
.acr
.Content
;
10 public class ContentUtils
{
11 public static void traverse(Content content
, BiConsumer
<Content
, Integer
> doIt
) {
12 traverse(content
, doIt
, 0);
15 public static void traverse(Content content
, BiConsumer
<Content
, Integer
> doIt
, int currentDepth
) {
16 doIt
.accept(content
, currentDepth
);
17 int nextDepth
= currentDepth
+ 1;
18 for (Content child
: content
) {
19 traverse(child
, doIt
, nextDepth
);
23 public static void print(Content content
, PrintStream out
, int depth
, boolean printText
) {
24 StringBuilder sb
= new StringBuilder();
25 for (int i
= 0; i
< depth
; i
++) {
28 String prefix
= sb
.toString();
29 out
.println(prefix
+ content
.getName());
30 for (QName key
: content
.keySet()) {
31 out
.println(prefix
+ " " + key
+ "=" + content
.get(key
));
34 if (content
.hasText()) {
35 out
.println("<![CDATA[" + content
.getText().trim() + "]]>");
42 // public static <T> boolean isString(T t) {
43 // return t instanceof String;
47 * Split a path (with '/' separator) in an array of length 2, the first part
48 * being the parent path (which could be either absolute or relative), the
49 * second one being the last segment, (guaranteed to be with '/').
51 public static String
[] getParentPath(String path
) {
52 int parentIndex
= path
.lastIndexOf('/');
53 // TODO make it more robust
54 return new String
[] { parentIndex
!= 0 ? path
.substring(0, parentIndex
) : "/",
55 path
.substring(parentIndex
+ 1) };
59 private ContentUtils() {