SitecatalystJsonItemWriter.java
2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.TidyJsonItemWriter
* javax.jcr.Node
* javax.jcr.NodeIterator
* javax.jcr.Property
* javax.jcr.PropertyIterator
* javax.jcr.RepositoryException
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.io.JSONWriter
*/
package com.day.cq.analytics.sitecatalyst.util;
import com.day.cq.commons.TidyJsonItemWriter;
import java.util.HashSet;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.RepositoryException;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.io.JSONWriter;
public class SitecatalystJsonItemWriter
extends TidyJsonItemWriter {
public SitecatalystJsonItemWriter() {
super(new HashSet());
}
protected void dump(Node node, JSONWriter w, int currentRecursionLevel, int maxRecursionLevels) throws RepositoryException, JSONException {
Node n;
Property prop;
boolean isArray = true;
NodeIterator children = node.getNodes();
if (!children.hasNext()) {
isArray = false;
}
while (children.hasNext()) {
Node n2 = children.nextNode();
if (n2.getName().matches("\\d+")) continue;
isArray = false;
break;
}
PropertyIterator props = node.getProperties();
if (isArray && props.hasNext()) {
while (props.hasNext()) {
prop = props.nextProperty();
if (prop.getName().matches("jcr:.+")) continue;
isArray = false;
break;
}
}
if (isArray) {
w.array();
if (this.recursionLevelActive(currentRecursionLevel, maxRecursionLevels)) {
children = node.getNodes();
while (children.hasNext()) {
n = children.nextNode();
this.dump(n, w, currentRecursionLevel + 1, maxRecursionLevels);
}
}
w.endArray();
} else {
w.object();
props = node.getProperties();
while (props.hasNext()) {
prop = props.nextProperty();
if (prop.getName().matches("jcr:.+") || prop.getName().matches("cq:.+")) continue;
this.writeProperty(w, prop);
}
if (this.recursionLevelActive(currentRecursionLevel, maxRecursionLevels)) {
children = node.getNodes();
while (children.hasNext()) {
n = children.nextNode();
this.dumpSingleNode(n, w, currentRecursionLevel, maxRecursionLevels);
}
}
w.endObject();
}
}
}