use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class NodeOrderableChildNodesTest method prepareTest.
/**
* Sets up the test content needed for the test cases.
*/
private void prepareTest() throws RepositoryException {
// get root node
Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
// create testNode
parentNode = defaultRootNode.addNode(nodeName1, getProperty("nodetype2"));
// add child node
Node firstNode = parentNode.addNode(nodeName2, getProperty("nodetype3"));
// add a second child node
Node secondNode = parentNode.addNode(nodeName3, getProperty("nodetype3"));
// save the new nodes
superuser.save();
// get child node refs
NodeIterator it = parentNode.getNodes();
initialFirstNode = it.nextNode();
initialSecondNode = it.nextNode();
// first lets test if the nodes have been added in the right order
assertTrue("Child nodes are not added in proper order ", firstNode.isSame(initialFirstNode));
assertTrue("Child nodes are not added in proper order ", secondNode.isSame(initialSecondNode));
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class XPathDocOrderTest method docOrderTest.
//-----------------------------< internal >---------------------------------
/**
* Executes a statement, checks if the Result contains exactly one node with
* <code>path</code>.
*
* @param stmt to be executed
* @param path the path of the node in the query result.
*/
private void docOrderTest(Statement stmt, String path) throws RepositoryException, NotExecutableException {
if (!isSupported(Repository.QUERY_XPATH_DOC_ORDER)) {
throw new NotExecutableException("Repository does not support document order on result set.");
}
int count = 0;
// check precondition: at least 3 nodes
for (NodeIterator it = testRootNode.getNodes(); it.hasNext(); it.nextNode()) {
count++;
}
if (count < 3) {
throw new NotExecutableException("Workspace does not contain enough content under: " + testRoot + ". At least 3 nodes are required for this test.");
}
QueryResult result = execute(stmt);
checkResult(result, 1);
assertEquals("Wrong result node.", path, result.getNodes().nextNode().getPath());
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class XPathDocOrderTest method testDocOrderLastFunction.
/**
* Tests the <code>last()</code> function.
* <p>
* For configuration description see {@link XPathDocOrderTest}.
*/
public void testDocOrderLastFunction() throws Exception {
String xpath = xpathRoot + "/*[position()=last()]";
String resultPath = "";
for (NodeIterator nodes = testRootNode.getNodes(); nodes.hasNext(); ) {
resultPath = nodes.nextNode().getPath();
}
docOrderTest(new Statement(xpath, qsXPATH), resultPath);
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class XPathPosIndexTest method docOrderTest.
//-----------------------------< internal >---------------------------------
/**
* Executes a statement, checks if the Result contains exactly one node with
* <code>path</code>.
*
* @param stmt to be executed
* @param path the path of the node in the query result.
*/
private void docOrderTest(Statement stmt, String path) throws RepositoryException, NotExecutableException {
if (!isSupported(Repository.QUERY_XPATH_POS_INDEX)) {
throw new NotExecutableException("Repository does not support document order on result set.");
}
int count = 0;
// check precondition: at least 3 nodes
for (NodeIterator it = testRootNode.getNodes(); it.hasNext(); it.nextNode()) {
count++;
}
if (count < 3) {
throw new NotExecutableException("Workspace does not contain enough content under: " + testRoot + ". At least 3 nodes are required for this test.");
}
QueryResult result = execute(stmt);
checkResult(result, 1);
assertEquals("Wrong result node.", path, result.getNodes().nextNode().getPath());
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class NodeImpl method getWeakReferences.
/**
* {@inheritDoc}
*/
public PropertyIterator getWeakReferences(String name) throws RepositoryException {
if (name == null) {
return getWeakReferences();
}
// check state of this instance
sanityCheck();
// shortcut if node isn't referenceable
if (!isNodeType(NameConstants.MIX_REFERENCEABLE)) {
return PropertyIteratorAdapter.EMPTY;
}
try {
StringBuilder stmt = new StringBuilder();
stmt.append("//*[@").append(ISO9075.encode(name));
stmt.append(" = '").append(data.getId()).append("']");
Query q = getSession().getWorkspace().getQueryManager().createQuery(stmt.toString(), Query.XPATH);
QueryResult result = q.execute();
ArrayList<Property> l = new ArrayList<Property>();
for (NodeIterator nit = result.getNodes(); nit.hasNext(); ) {
Node n = nit.nextNode();
l.add(n.getProperty(name));
}
if (l.isEmpty()) {
return PropertyIteratorAdapter.EMPTY;
} else {
return new PropertyIteratorAdapter(l);
}
} catch (RepositoryException e) {
String msg = "Unable to retrieve WEAKREFERENCE properties that refer to " + id;
log.debug(msg);
throw new RepositoryException(msg, e);
}
}
Aggregations