use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class ExportFileSystem method addFolder.
/**
* Exports a nt:folder and all its children to the file system
* @param node
* the <code>Node</code>
* @param file
* <code>File</code>
* @throws CommandException
* if the <code>File</code> can't be created
* @throws RepositoryException
* if the current working <code>Repository</code> throws an
* <code>Exception</code>
* @throws IOException
* if an IOException occurs
*/
private void addFolder(Node node, File file) throws CommandException, RepositoryException, IOException {
boolean created = file.mkdir();
if (!created) {
throw new CommandException("exception.folder.not.created", new String[] { file.getPath() });
}
NodeIterator iter = node.getNodes();
while (iter.hasNext()) {
Node child = iter.nextNode();
// File
if (child.isNodeType("nt:file")) {
File childFile = new File(file, child.getName());
createFile(child, childFile);
} else if (child.isNodeType("nt:folder")) {
File childFolder = new File(file, child.getName());
addFolder(child, childFolder);
}
}
}
use of javax.jcr.NodeIterator in project jackrabbit-oak by apache.
the class OrderedIndexQueryBaseTest method runTest.
@Override
protected void runTest() throws Exception {
QueryManager qm = session.getWorkspace().getQueryManager();
Query q = qm.createQuery(getQuery(), Query.JCR_SQL2);
QueryResult r = q.execute();
NodeIterator nodes = r.getNodes();
int counter = 0;
while (nodes.hasNext() && counter++ < FETCH_NODES) {
nodes.next();
}
}
use of javax.jcr.NodeIterator in project jackrabbit-oak by apache.
the class DescendantSearchTest method runTest.
@Override
public void runTest() throws Exception {
QueryManager manager = session.getWorkspace().getQueryManager();
for (int i = 0; i < NODE_COUNT; i++) {
Query query = createQuery(manager, i);
NodeIterator iterator = query.execute().getNodes();
while (iterator.hasNext()) {
Node node = iterator.nextNode();
if (node.getProperty("testcount").getLong() != i) {
throw new Exception("Invalid test result: " + node.getPath());
}
}
}
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class WorkspaceImpl method createWorkspace.
//--------------------------------------------------< new JSR 283 methods >
/**
* {@inheritDoc}
*/
public void createWorkspace(String name, String srcWorkspace) throws AccessDeniedException, RepositoryException {
// check state of this instance
sanityCheck();
context.getAccessManager().checkRepositoryPermission(Permission.WORKSPACE_MNGMT);
WorkspaceManager manager = context.getRepositoryContext().getWorkspaceManager();
manager.createWorkspace(name);
SessionImpl tmpSession = null;
try {
// create a temporary session on new workspace for current subject
tmpSession = manager.createSession(session.getSubject(), name);
WorkspaceImpl newWsp = (WorkspaceImpl) tmpSession.getWorkspace();
// Workspace#clone(String, String, String, boolean) doesn't
// allow to clone to "/"...
//newWsp.clone(srcWorkspace, "/", "/", false);
Node root = getSession().getRootNode();
for (NodeIterator it = root.getNodes(); it.hasNext(); ) {
Node child = it.nextNode();
// skip nodes that already exist in newly created workspace
if (!tmpSession.nodeExists(child.getPath())) {
newWsp.clone(srcWorkspace, child.getPath(), child.getPath(), false);
}
}
} finally {
if (tmpSession != null) {
// we don't need the temporary session anymore, logout
tmpSession.logout();
}
}
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class ItemStateHierarchyManagerDeadlockTest method retrieveNodesUnderInvRootNode.
public void retrieveNodesUnderInvRootNode() {
System.out.println("Start retrieveNodesUnderInvRootNode ");
Session session = null;
try {
session = login();
// start from the bottom of the tree and move up
Node inventoryRoot = getInvRootNode(session);
NodeIterator nodes = inventoryRoot.getNodes();
while (nodes.hasNext()) {
Node node = nodes.nextNode();
// System.out.println(" Node: " + node.getName());
PropertyIterator properties = node.getProperties();
while (properties.hasNext()) {
Property prop = properties.nextProperty();
// System.out.println(" Prop: " + prop.getName() + " - " + prop.getString());
}
}
session.save();
System.out.println("End retrieveNodesUnderInvRootNode");
} catch (Exception e) {
System.err.println("Exception in retrieveNodesUnderInvRootNode:" + e.getMessage());
} finally {
if (session != null)
session.logout();
}
}
Aggregations