DurboUtil.java
7.22 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.durbo.DurboInput
* com.day.durbo.DurboInput$Property
* javax.jcr.Node
* javax.jcr.NodeIterator
* javax.jcr.RepositoryException
* javax.jcr.nodetype.NodeType
* org.apache.jackrabbit.util.ISO9075
* org.apache.jackrabbit.util.Text
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.replication.impl.content.durbo;
import com.day.durbo.DurboInput;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NodeType;
import org.apache.jackrabbit.util.ISO9075;
import org.apache.jackrabbit.util.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class DurboUtil {
private static final Logger log = LoggerFactory.getLogger(DurboUtil.class);
public static final String REP_POLICY_NODE_TYPE = "rep:Policy";
public static final String REP_POLICY_NODE = "rep:policy";
public static final String CQ_ANNOTATIONS_NODE = "cq:annotations";
public static final String REP_USER_NODE_TYPE = "rep:User";
public static final String REP_SYSTEM_USER_NODE_TYPE = "rep:SystemUser";
public static final String REP_AUTHORIZABLE_ID_PROPERTY = "rep:authorizableId";
public static final String REP_PRINCIPAL_NAME_PROPERTY = "rep:principalName";
public static final String JCR_UUID_PROPERTY = "jcr:uuid";
public static final String USER_TOKENS_NODE = ".tokens";
public static final String REP_GROUP_NODE_TYPE = "rep:Group";
public static final String ORDER_SIBLINGS_PROPERTY = "orderSiblings";
public static final String ORDER_CHILDREN_PROPERTY = "orderChildren";
public static final String START_PATH_PROPERTY = "startPath";
public static final String PARENT_NODE_TYPES_PROPERTY = "parentNodeTypes";
public static final String PARENT_NODE_PROPERTIES = "parentNodeProperties";
public static final String MIME_TYPE = "application/cq5-replication-durbo";
public static final Set<String> IGNORED_PROPERTIES;
public static final Set<String> IGNORED_SYSVIEW_PROPERTIES;
public static final Set<String> IGNORED_NODES;
public static final Set<String> IGNORED_MIXIN_TYPES;
public static String getValue(Map<String, DurboInput.Property> props, String key, String defaultValue) {
if (props.containsKey(key)) {
return props.get(key).getString();
}
return defaultValue;
}
public static String putNodeNames(Node node) throws RepositoryException {
if (node.getPrimaryNodeType().hasOrderableChildNodes()) {
StringBuilder listBuffer = new StringBuilder();
NodeIterator iter = node.getNodes();
while (iter.hasNext()) {
String name = iter.nextNode().getName();
if (name.startsWith("jcr:")) continue;
listBuffer.append(ISO9075.encode((String)name)).append(',');
}
return listBuffer.toString();
}
return "";
}
public static String[] getNodeNames(Map<String, DurboInput.Property> props, String key) {
String rawValue = DurboUtil.getValue(props, key, null);
if (rawValue != null) {
String[] values = rawValue.split(",");
for (int i = 0; i < values.length; ++i) {
values[i] = ISO9075.decode((String)values[i]);
}
return values;
}
return new String[0];
}
public static boolean setChildNodeOrder(Node parent, String nameList) throws RepositoryException {
return nameList != null && DurboUtil.setChildNodeOrder(parent, Text.explode((String)nameList, (int)44));
}
public static boolean setChildNodeOrder(Node parent, String[] names) throws RepositoryException {
if (names.length > 1 && parent.getPrimaryNodeType().hasOrderableChildNodes()) {
if (!parent.isCheckedOut()) {
log.warn("Unable to restore order of a checked-in node: " + parent.getPath());
return false;
}
String last = null;
List<String> list = Arrays.asList(names);
ListIterator<String> iter = list.listIterator(list.size());
while (iter.hasPrevious()) {
String prev = iter.previous();
if (!parent.hasNode(prev)) continue;
log.debug("ordering {} before {}", (Object)prev, (Object)last);
parent.orderBefore(prev, last);
last = prev;
}
return true;
}
return false;
}
public static boolean isAuthorizableNodeType(String ntName, int targetType) {
switch (targetType) {
case 2: {
return "rep:Group".equals(ntName);
}
case 1: {
return "rep:User".equals(ntName) || "rep:SystemUser".equals(ntName);
}
case 3: {
return "rep:Group".equals(ntName) || "rep:User".equals(ntName) || "rep:SystemUser".equals(ntName);
}
}
throw new IllegalArgumentException("Invalid authorizable type " + targetType);
}
public static String urlEncodeMap(Map<String, String> map) {
StringBuffer sb = new StringBuffer();
for (Map.Entry<String, String> entry : map.entrySet()) {
sb.append(Text.escape((String)entry.getKey()));
sb.append("=");
sb.append(Text.escape((String)entry.getValue()));
sb.append("&");
}
return sb.toString();
}
public static Map<String, String> urlDecodeMap(String s) {
String[] tokens;
HashMap<String, String> map = new HashMap<String, String>();
for (String token : tokens = s.split("&")) {
String[] parts = token.split("=");
if (parts.length != 2) continue;
map.put(Text.unescape((String)parts[0]), Text.unescape((String)parts[1]));
}
return map;
}
static {
Set iProps = new HashSet<String>();
iProps.add((String)"jcr:frozenMixinTypes");
iProps.add((String)"jcr:frozenPrimaryType");
iProps.add((String)"jcr:frozenUuid");
iProps.add((String)"jcr:versionHistory");
iProps.add((String)"jcr:baseVersion");
iProps.add((String)"jcr:predecessors");
iProps.add((String)"jcr:successors");
iProps.add((String)"jcr:isCheckedOut");
iProps.add((String)"cq:distribute");
IGNORED_SYSVIEW_PROPERTIES = Collections.unmodifiableSet(iProps);
iProps = new HashSet<String>(IGNORED_SYSVIEW_PROPERTIES);
iProps.add("jcr:primaryType");
iProps.add("jcr:mixinTypes");
iProps.add("jcr:uuid");
IGNORED_PROPERTIES = Collections.unmodifiableSet(iProps);
HashSet<String> iNodes = new HashSet<String>();
iNodes.add("cq:annotations");
IGNORED_NODES = Collections.unmodifiableSet(iNodes);
HashSet<String> iMix = new HashSet<String>();
iMix.add("rep:AccessControllable");
IGNORED_MIXIN_TYPES = Collections.unmodifiableSet(iMix);
}
}