use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class SysViewContentHandler method startElement.
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
try {
if (qName.equals(svNode)) {
//attribute sv:name
String nodeName = attributes.getValue(svName);
if (noRecurse) {
if (!testRootDone) {
nodeElemStack.push(currentNodeElem);
testRootDone = true;
// correct root name?
if (currentNodeElem.node.getDepth() == 0) {
checkCondition("Exported Root node has not the required " + "element name 'jcr:root'.", nodeName.equals(jcrRoot));
}
// nothing else to do here
} else // rootNode yet done
{
// only the testRootNode should be exported.
checkCondition("Child Node Element of testRoot Node " + "element found although noRecursive is true.", !testRootDone);
}
} else {
if (!testRootDone) {
nodeElemStack.push(currentNodeElem);
testRootDone = true;
// correct root name?
if (currentNodeElem.node.getDepth() == 0) {
checkCondition("Exported Root node has not the required " + "element name 'jcr:root'.", nodeName.equals(jcrRoot));
}
// nothing else to do here
} else // Collect the exported data in a NodeElemData object.
// every occurrence of an opened sv:node element
// creates such an object which will be put on the nodeElemStack.
// As this element will be popped from the stack when the node element
// is closed, the latest element on the stack represents the parent
// node element of the current node element.
{
parentNodeElem = (NodeElemData) nodeElemStack.pop();
// get the node(s) with the found nodeName
NodeIterator nodeIter = parentNodeElem.node.getNodes(nodeName);
// create a new nodeElemData for this new node elem in process
currentNodeElem = new NodeElemData();
currentNodeElem.name = nodeName;
long size = getSize(nodeIter);
if (size >= 1) {
// position the node elem is found in the exported tree.
if (parentNodeElem.childNodeElemNames.containsKey(nodeName)) {
ChildNodeElem child = (ChildNodeElem) parentNodeElem.childNodeElemNames.get(nodeName);
child.number++;
currentNodeElem.index = child.number;
// get the node
String relPath = currentNodeElem.name + "[" + child.number + "]";
currentNodeElem.node = parentNodeElem.node.getNode(relPath);
currentNodeElem.path = currentNodeElem.node.getPath();
parentNodeElem.childNodeElemNames.put(nodeName, child);
} else {
ChildNodeElem child = new ChildNodeElem();
child.name = nodeName;
child.number = 1;
currentNodeElem.index = child.number;
// get the node
String relPath = currentNodeElem.name + "[" + child.number + "]";
currentNodeElem.node = parentNodeElem.node.getNode(relPath);
currentNodeElem.path = currentNodeElem.node.getPath();
parentNodeElem.childNodeElemNames.put(nodeName, child);
}
} else {
// no node found, this is an error.
checkCondition("No child node of node " + parentNodeElem.path + " found with name: " + nodeName, false);
}
// push the parent data and the current node element data on the stack
nodeElemStack.push(parentNodeElem);
nodeElemStack.push(currentNodeElem);
}
}
} else // Collect the value(s) found in an ArrayList.
if (qName.equals(svProperty)) {
currentPropElem = new PropElemData();
currentPropElem.name = attributes.getValue(svName);
currentPropElem.typeName = attributes.getValue(svType);
currentPropElem.type = PropertyType.valueFromName(currentPropElem.typeName);
currentPropElem.values = new ArrayList<String>();
} else if (qName.equals(svValue)) {
// init
currentValue = new StringBuffer();
} else {
// invalid element name is used
checkCondition("Invalid element name " + qName + " in SysView export found", false);
}
} catch (PathNotFoundException pne) {
checkCondition("Item not found during exportSysViewTest: " + pne.toString(), false);
} catch (RepositoryException re) {
// what here?
}
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class ReadWhileSaveTest method testReadWhileSave.
public void testReadWhileSave() throws RepositoryException, IOException {
Thread t = runExpensiveSave();
long numReads = 0;
while (t.isAlive()) {
Session s = getHelper().getSuperuserSession();
try {
for (NodeIterator it = s.getRootNode().getNodes(); it.hasNext(); ) {
it.nextNode();
}
numReads++;
} finally {
s.logout();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// ignore
}
}
log.println("numReads: " + numReads);
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class MoveTest method doTestMove.
private void doTestMove(boolean save) throws RepositoryException {
Session session = testRootNode.getSession();
for (NodeIterator it = testRootNode.getNodes(); it.hasNext(); ) {
it.nextNode().remove();
session.save();
}
Node node1 = testRootNode.addNode(nodeName1);
Node node2 = node1.addNode(nodeName2);
session.save();
String from = node2.getPath();
String to = node1.getParent().getPath() + "/" + nodeName2;
session.move(from, to);
try {
if (save) {
node2.save();
} else {
node2.refresh(false);
}
fail("Refresh and Save should not work for moved nodes");
} catch (RepositoryException e) {
// expected
}
session.save();
NodeIterator it = node2.getParent().getNodes(nodeName2);
assertTrue(it.hasNext());
it.nextNode();
assertFalse(it.hasNext());
node2.getParent().getPath();
// for (it = testRootNode.getNodes(); it.hasNext();) {
// System.out.println(it.nextNode().getPath());
// }
String now = node2.getPath();
assertEquals(testRootNode.getPath() + "/" + nodeName2, now);
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class MoveTest method doTestMoveWithGetPath.
private void doTestMoveWithGetPath(boolean index) throws RepositoryException {
Session session = testRootNode.getSession();
for (NodeIterator it = testRootNode.getNodes(); it.hasNext(); ) {
it.nextNode().remove();
session.save();
}
String testPath = testRootNode.getPath();
Node a = testRootNode.addNode("a");
Node b = a.addNode("b");
session.save();
session.move(testPath + "/a/b", testPath + "/a");
if (index) {
b.getPath();
}
session.move(testPath + "/a", testPath + "/a");
assertEquals(testPath + "/a[2]", a.getPath());
assertEquals(testPath + "/a", b.getPath());
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class MultiWorkspaceShareableNodeTest method initNodesW2.
protected void initNodesW2() throws RepositoryException {
// testroot
if (superuserW2.getRootNode().hasNode(testPath)) {
testRootNodeW2 = superuserW2.getRootNode().getNode(testPath);
// clean test root
for (NodeIterator it = testRootNodeW2.getNodes(); it.hasNext(); ) {
it.nextNode().remove();
}
testRootNodeW2.save();
} else {
testRootNodeW2 = superuserW2.getRootNode().addNode(testPath, testNodeType);
superuserW2.save();
}
}
Aggregations