if (!item.isNode()) {
return;
}
Node parent = item.getParent();
String next = null;
if (command.equals(SlingPostConstants.ORDER_FIRST)) {
next = parent.getNodes().nextNode().getName();
} else if (command.equals(SlingPostConstants.ORDER_LAST)) {
next = "";
} else if (command.startsWith(SlingPostConstants.ORDER_BEFORE)) {
next = command.substring(SlingPostConstants.ORDER_BEFORE.length());
} else if (command.startsWith(SlingPostConstants.ORDER_AFTER)) {
String name = command.substring(SlingPostConstants.ORDER_AFTER.length());
NodeIterator iter = parent.getNodes();
while (iter.hasNext()) {
Node n = iter.nextNode();
if (n.getName().equals(name)) {
if (iter.hasNext()) {
next = iter.nextNode().getName();
} else {
next = "";
}
}
}
} else {
// check for integer
try {
// 01234
// abcde move a -> 2 (above 3)
// bcade move a -> 1 (above 1)
// bacde
int newPos = Integer.parseInt(command);
next = "";
NodeIterator iter = parent.getNodes();
while (iter.hasNext() && newPos >= 0) {
Node n = iter.nextNode();
if (n.getName().equals(item.getName())) {
// if old node is found before index, need to
// inc index
newPos++;
}
if (newPos == 0) {
next = n.getName();
break;
}
newPos--;
}
} catch (NumberFormatException e) {