Path.java
1.97 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.jackrabbit.oak.api.PropertyState
* org.apache.jackrabbit.oak.api.Tree
*/
package com.adobe.aemfd.formsfoundation.oak.restrictions.impl;
import com.adobe.aemfd.formsfoundation.oak.restrictions.impl.Value;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Tree;
public class Path {
private final Tree tree;
private final PropertyState propertyState;
private final String path;
private Tree root;
public Path(Tree tree, PropertyState propertyState, String pathStr) {
this.tree = tree;
this.propertyState = propertyState;
this.path = pathStr;
}
private Tree getRoot() {
if (this.root != null) {
return this.root;
}
this.root = this.tree;
while (!this.root.isRoot()) {
this.root = this.root.getParent();
}
return this.root;
}
public Value evaluate() {
String[] pathTokens = this.path.split("/");
Tree currentTree = this.tree;
for (int i = 0; i < pathTokens.length; ++i) {
String token = pathTokens[i];
if (token.length() == 0) {
currentTree = this.getRoot();
continue;
}
if ("..".equals(token)) {
currentTree = currentTree.getParent();
continue;
}
if (".".equals(token)) continue;
if (i == pathTokens.length - 1) {
if (currentTree == this.tree && this.propertyState != null && this.propertyState.getName().equals(token)) {
return Value.fromPropertyState(this.propertyState);
}
PropertyState propertyState = currentTree.getProperty(token);
return Value.fromPropertyState(propertyState);
}
currentTree = currentTree.getChild(token);
}
return null;
}
}