NodeNameList.java
2.19 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Node
* javax.jcr.RepositoryException
* javax.jcr.nodetype.NodeType
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.jcr.vault.fs.api;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.ListIterator;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NodeType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class NodeNameList {
private static final Logger log = LoggerFactory.getLogger(NodeNameList.class);
private final LinkedHashSet<String> names = new LinkedHashSet();
public void addName(String name) {
this.names.add(name);
}
public boolean contains(String name) {
return this.names.contains(name);
}
public LinkedHashSet<String> getNames() {
return this.names;
}
public boolean needsReorder(Node parent) throws RepositoryException {
return this.names.size() > 1 && parent.getPrimaryNodeType().hasOrderableChildNodes();
}
public boolean restoreOrder(Node parent) throws RepositoryException {
if (!parent.isCheckedOut()) {
log.warn("Unable to restore order of a checked-in node: " + parent.getPath());
return false;
}
int size = this.names.size();
String last = null;
ArrayList<String> list = new ArrayList<String>(this.names);
ListIterator<String> iter = list.listIterator(size);
while (iter.hasPrevious()) {
String prev = iter.previous();
if (!parent.hasNode(prev)) continue;
log.debug("ordering {} before {}", (Object)prev, (Object)last);
try {
parent.orderBefore(prev, last);
}
catch (Exception e) {
String path = parent.getPath() + "/" + prev;
log.warn("Ignoring unexpected error during reorder of {}: {}", (Object)path, (Object)e.toString());
}
last = prev;
}
return true;
}
}