Java Code Examples for javax.jcr.Node#getNodes()

The following examples show how to use javax.jcr.Node#getNodes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StorageUpdate12.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
private void addRuntimeNameProperty() throws RepositoryException {
	
	String statement = 
			"/jcr:root" + ISO9075.encodePath(StorageConstants.REPORTS_ROOT) + 
			"//*[@className='ro.nextreports.server.domain.Report']" + 
			"//*[fn:name()='parametersValues']";
	  
	QueryResult queryResult = getTemplate().query(statement);

	NodeIterator nodes = queryResult.getNodes();
	
	LOG.info("RuntimeHistory : Found " + nodes.getSize() + " parameterValues nodes");
	while (nodes.hasNext()) {			
		Node node = nodes.nextNode();
		NodeIterator childrenIt = node.getNodes();
		while (childrenIt.hasNext()) {
			Node child = childrenIt.nextNode();				
			child.setProperty("runtimeName", child.getName());
		}
	}	
	getTemplate().save();		
}
 
Example 2
Source File: RepositoryServiceImpl.java    From urule with Apache License 2.0 6 votes vote down vote up
private void buildDirectories(Node node, List<RepositoryFile> fileList, String projectPath) throws Exception {
	NodeIterator nodeIterator = node.getNodes();
	while (nodeIterator.hasNext()) {
		Node dirNode = nodeIterator.nextNode();
		if (!dirNode.hasProperty(FILE)) {
			continue;
		}
		if (!dirNode.hasProperty(DIR_TAG)) {
			continue;
		}
		RepositoryFile file = new RepositoryFile();
		file.setName(dirNode.getPath().substring(projectPath.length()));
		file.setFullPath(dirNode.getPath());
		buildDirectories(dirNode, fileList, projectPath);
		fileList.add(file);
	}
}
 
Example 3
Source File: RepositoryServiceImpl.java    From urule with Apache License 2.0 6 votes vote down vote up
private void unlockAllChildNodes(Node node,User user,List<Node> nodeList,String rootPath) throws Exception{
	NodeIterator iter=node.getNodes();
	while(iter.hasNext()){
		Node nextNode=iter.nextNode();
		String absPath=nextNode.getPath();
		if(!lockManager.isLocked(absPath)){
			continue;
		}
		Lock lock=lockManager.getLock(absPath);
		String owner=lock.getLockOwner();
		if(!user.getUsername().equals(owner)){
			throw new NodeLockException("当前目录下有子目录被其它人锁定,您不能执行锁定"+rootPath+"目录");
		}
		nodeList.add(nextNode);
		unlockAllChildNodes(nextNode, user, nodeList, rootPath);
	}
}
 
Example 4
Source File: RepositoryServiceImpl.java    From urule with Apache License 2.0 6 votes vote down vote up
private void buildPath(List<String> list, Node parentNode) throws RepositoryException {
	NodeIterator nodeIterator=parentNode.getNodes();
	while(nodeIterator.hasNext()){
		Node node=nodeIterator.nextNode();
		String nodePath=node.getPath();
		if(nodePath.endsWith(FileType.Ruleset.toString())){
			list.add(nodePath);
		}else if(nodePath.endsWith(FileType.UL.toString())){
			list.add(nodePath);
		}else if(nodePath.endsWith(FileType.DecisionTable.toString())){
			list.add(nodePath);
		}else if(nodePath.endsWith(FileType.ScriptDecisionTable.toString())){
			list.add(nodePath);
		}else if(nodePath.endsWith(FileType.DecisionTree.toString())){
			list.add(nodePath);					
		}else if(nodePath.endsWith(FileType.RuleFlow.toString())){
			list.add(nodePath);					
		}
		buildPath(list,node);
	}
}
 
Example 5
Source File: JcrStorageDao.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
public int countEntityChildrenById(String id) throws NotFoundException {
	Node node = checkId(id);
	try {
		if (!node.hasNodes()) {
			return 0;
		}

		NodeIterator nodes = node.getNodes();
		// TODO it's OK ?
		return (int) nodes.getSize();
		/*
		 * int count = 0; while (nodes.hasNext()) { Node nextNode =
		 * nodes.nextNode(); if (isEntityNode(nextNode)) {; count++; } }
		 * 
		 * return count;
		 */
	} catch (RepositoryException e) {
		throw convertJcrAccessException(e);
	}
}
 
Example 6
Source File: JcrPackageManagerImplTest.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
private String getNextPath(String path) throws RepositoryException {
    Node currentNode = admin.getNode(path);
    if (currentNode.hasNodes()) {
        NodeIterator nodes = currentNode.getNodes();
        while (nodes.hasNext()) {
            Node node = nodes.nextNode();
            if ("jcr:system".equals(node.getName())) {
                continue;
            }
            String nodePath = node.getPath();
            if (visitedPaths.contains(nodePath)) {
                continue;
            } else {
                visitedPaths.add(nodePath);
            }
            return nodePath;
        }
        return getParentPath(path);
    } else {
        return getParentPath(path);
    }
}
 
Example 7
Source File: RepositoryCFile.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
public ConsoleFile[] listFiles() throws IOException {
    try {
        if (item.isNode()) {
            Node node = (Node) item;
            ArrayList<RepositoryCFile> ret = new ArrayList<RepositoryCFile>();
            PropertyIterator piter = node.getProperties();
            while (piter.hasNext()) {
                ret.add(new RepositoryCFile(piter.nextProperty()));
            }
            NodeIterator niter = node.getNodes();
            while (niter.hasNext()) {
                ret.add(new RepositoryCFile(niter.nextNode()));
            }
            return ret.toArray(new RepositoryCFile[ret.size()]);
        } else {
            return ConsoleFile.EMPTY_ARRAY;
        }
    } catch (RepositoryException e) {
        throw new IOException(e.toString());
    }
}
 
Example 8
Source File: JcrStorageDao.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
public Entity[] getEntityChildren(String path) throws NotFoundException {
	checkPath(path);

	Node node = getNode(path);
	try {
		if (!node.hasNodes()) {
			return new Entity[0];
		}

		List<Entity> entities = new ArrayList<Entity>();
		NodeIterator nodes = node.getNodes();
		while (nodes.hasNext()) {
			Entity entity = getEntity(nodes.nextNode());
			if (entity != null) {
				entities.add(entity);
			}
		}

		return entities.toArray(new Entity[entities.size()]);
	} catch (RepositoryException e) {
		throw convertJcrAccessException(e);
	}
}
 
Example 9
Source File: JcrExporter.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
private void scan(Node dir) throws RepositoryException {
    NodeIterator iter = dir.getNodes();
    while (iter.hasNext()) {
        Node child = iter.nextNode();
        String name = child.getName();
        if (".svn".equals(name) || ".vlt".equals(name)) {
            continue;
        }
        if (child.isNodeType(JcrConstants.NT_FOLDER)) {
            exportInfo.update(ExportInfo.Type.RMDIR, child.getPath());
            scan(child);
        } else if (child.isNodeType(JcrConstants.NT_FILE)) {
            exportInfo.update(ExportInfo.Type.DELETE, child.getPath());
        }
    }
}
 
Example 10
Source File: JcrUtils.java    From jackalope with Apache License 2.0 5 votes vote down vote up
public static Iterable<Node> getChildNodes(final Node node) {
    return new Iterable<Node>() {
        @SuppressWarnings("unchecked")
        @Override
        public Iterator<Node> iterator() {
            try {
                return node.getNodes();
            }
            catch (RepositoryException re) {
                return new Iterator<Node>() {
                    @Override
                    public boolean hasNext() {
                        return false;
                    }


                    @Override
                    public Node next() {
                        return null;
                    }


                    @Override
                    public void remove() {
                    }
                };
            }
        }
    };
}
 
Example 11
Source File: WebdavProviderTestCase.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/** Recursively outputs the contents of the given node. */
private static void dump(final Node node) throws RepositoryException {
    // First output the node path
    message(node.getPath());
    // Skip the virtual (and large!) jcr:system subtree
    if (node.getName().equals("jcr:system")) {
        return;
    }

    if (node.getName().equals("jcr:content")) {
        return;
    }

    // Then output the properties
    final PropertyIterator properties = node.getProperties();
    while (properties.hasNext()) {
        final Property property = properties.nextProperty();
        if (property.getDefinition().isMultiple()) {
            // A multi-valued property, print all values
            final Value[] values = property.getValues();
            for (final Value value : values) {
                message(property.getPath() + " = " + value.getString());
            }
        } else {
            // A single-valued property
            message(property.getPath() + " = " + property.getString());
        }
    }

    // Finally output all the child nodes recursively
    final NodeIterator nodes = node.getNodes();
    while (nodes.hasNext()) {
        dump(nodes.nextNode());
    }
}
 
Example 12
Source File: JcrPackageManagerImpl.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
/**
 * internally adds the packages below {@code root} to the given list
 * recursively.
 *
 * @param root root node
 * @param packages list for the packages
 * @param filter optional filter to filter out packages
 * @param built if {@code true} only packages with size > 0 are returned
 * @param shallow if {@code true} don't recurs
 * @throws RepositoryException if an error occurs
 */
private void listPackages(Node root, List<JcrPackage> packages,
                          WorkspaceFilter filter, boolean built, boolean shallow)
        throws RepositoryException {
    if (root != null) {
        for (NodeIterator iter = root.getNodes(); iter.hasNext();) {
            Node child = iter.nextNode();
            if (".snapshot".equals(child.getName())) {
                continue;
            }
            JcrPackageImpl pack = new JcrPackageImpl(registry, child);
            if (pack.isValid()) {
                // skip packages with illegal names
                JcrPackageDefinition jDef = pack.getDefinition();
                if (jDef != null && !jDef.getId().isValid()) {
                    continue;
                }
                if (filter == null || filter.contains(child.getPath())) {
                    if (!built || pack.getSize() > 0) {
                        packages.add(pack);
                    }
                }
            } else if (child.hasNodes() && !shallow){
                listPackages(child, packages, filter, built, false);
            }
        }
    }
}
 
Example 13
Source File: JcrSysViewTransformer.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
private void addPaths(List<String> paths, Node node) throws RepositoryException {
    paths.add(node.getPath());
    NodeIterator iter = node.getNodes();
    while (iter.hasNext()) {
        addPaths(paths, iter.nextNode());
    }
}
 
Example 14
Source File: BaseRepositoryService.java    From urule with Apache License 2.0 5 votes vote down vote up
@Override
public List<RepositoryFile> loadProjects(String companyId) throws Exception{
	List<RepositoryFile> projects=new ArrayList<RepositoryFile>();
	Node rootNode=getRootNode();
	NodeIterator nodeIterator = rootNode.getNodes();
	while (nodeIterator.hasNext()) {
		Node projectNode = nodeIterator.nextNode();
		if (!projectNode.hasProperty(FILE)) {
			continue;
		}
		if(StringUtils.isNotEmpty(companyId)){
			if(projectNode.hasProperty(COMPANY_ID)){
				String id=projectNode.getProperty(COMPANY_ID).getString();
				if(!companyId.equals(id)){
					continue;
				}
			}
		}
		if(projectNode.getName().indexOf(RESOURCE_SECURITY_CONFIG_FILE)>-1){
			continue;
		}
		RepositoryFile projectFile = new RepositoryFile();
		projectFile.setType(Type.project);
		projectFile.setName(projectNode.getName());
		projectFile.setFullPath("/" + projectNode.getName());
		projects.add(projectFile);
	}
	return projects;
}
 
Example 15
Source File: Purge.java    From APM with Apache License 2.0 5 votes vote down vote up
private NodeIterator getPermissions(Context context)
    throws ActionExecutionException, RepositoryException {
  JackrabbitSession session = context.getSession();
  String path = PERMISSION_STORE_PATH + context.getCurrentAuthorizable().getID();
  NodeIterator result = null;
  if (session.nodeExists(path)) {
    Node node = session.getNode(path);
    result = node.getNodes();
  }
  return result;
}
 
Example 16
Source File: CheckPermissions.java    From APM with Apache License 2.0 5 votes vote down vote up
private List<String> crawl(final Node node) throws RepositoryException {
  List<String> paths = new ArrayList<>();
  paths.add(node.getPath());
  for (NodeIterator iter = node.getNodes(); iter.hasNext(); ) {
    paths.addAll(crawl(iter.nextNode()));
  }
  return paths;
}
 
Example 17
Source File: Webdav4ProviderTestCase.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/** Recursively outputs the contents of the given node. */
private static void dump(final Node node) throws RepositoryException {
    // First output the node path
    message(node.getPath());
    // Skip the virtual (and large!) jcr:system subtree
    if (node.getName().equals("jcr:system")) {
        return;
    }

    if (node.getName().equals("jcr:content")) {
        return;
    }

    // Then output the properties
    final PropertyIterator properties = node.getProperties();
    while (properties.hasNext()) {
        final Property property = properties.nextProperty();
        if (property.getDefinition().isMultiple()) {
            // A multi-valued property, print all values
            final Value[] values = property.getValues();
            for (final Value value : values) {
                message(property.getPath() + " = " + value.getString());
            }
        } else {
            // A single-valued property
            message(property.getPath() + " = " + property.getString());
        }
    }

    // Finally output all the child nodes recursively
    final NodeIterator nodes = node.getNodes();
    while (nodes.hasNext()) {
        dump(nodes.nextNode());
    }
}
 
Example 18
Source File: DocViewSAXImporter.java    From jackrabbit-filevault with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    log.trace("<- element {}", qName);
    try {
        // currentNode's import is finished, check if any child nodes
        // need to be removed
        NodeNameList childNames = stack.getChildNames();
        Node node = stack.getNode();
        int numChildren = 0;
        if (node == null) {
            DocViewAdapter adapter = stack.getAdapter();
            if (adapter != null) {
                adapter.endNode();
            }
            // close transformer if last in stack
            if (stack.adapter != null) {
                List<String> createdPaths = stack.adapter.close();
                for (String createdPath : createdPaths) {
                    importInfo.onCreated(createdPath);
                }
                stack.adapter = null;
                log.trace("Sysview transformation complete.");
            }
        } else {
            NodeIterator iter = node.getNodes();
            while (iter.hasNext()) {
                numChildren++;
                Node child = iter.nextNode();
                String path = child.getPath();
                String label = Text.getName(path);
                AccessControlHandling acHandling = getAcHandling(child.getName());
                if (!childNames.contains(label)
                        && !hints.contains(path)
                        && isIncluded(child, child.getDepth() - rootDepth)) {
                    // if the child is in the filter, it belongs to
                    // this aggregate and needs to be removed
                    if (aclManagement.isACLNode(child)) {
                        if (acHandling == AccessControlHandling.OVERWRITE
                                || acHandling == AccessControlHandling.CLEAR) {
                            importInfo.onDeleted(path);
                            aclManagement.clearACL(node);
                        }
                    } else {
                        if (wspFilter.getImportMode(path) == ImportMode.REPLACE) {
                            importInfo.onDeleted(path);
                            // check if child is not protected
                            if (child.getDefinition().isProtected()) {
                                log.debug("Refuse to delete protected child node: {}", path);
                            } else if (child.getDefinition().isMandatory()) {
                                log.debug("Refuse to delete mandatory child node: {}", path);
                            } else {
                                child.remove();
                            }
                        }
                    }
                } else if (acHandling == AccessControlHandling.CLEAR
                        && aclManagement.isACLNode(child)
                        && isIncluded(child, child.getDepth() - rootDepth)) {
                    importInfo.onDeleted(path);
                    aclManagement.clearACL(node);
                }
            }
            if (isIncluded(node, node.getDepth() - rootDepth)) {
                // ensure order
                stack.restoreOrder();
            }
        }
        stack = stack.pop();
        if (node != null && (numChildren == 0 && !childNames.isEmpty() || stack.isRoot())) {
            importInfo.addNameList(node.getPath(), childNames);
        }
    } catch (RepositoryException e) {
        throw new SAXException(e);
    }
}
 
Example 19
Source File: AggregateImpl.java    From jackrabbit-filevault with Apache License 2.0 4 votes vote down vote up
/**
 * Walks the tree.
 *
 * @param aggregateWalkListener the listener
 * @param relPath rel path of node
 * @param node the current node
 * @param depth the depth of the node
 * @throws RepositoryException if an error occurs.
 */
private void walk(AggregateWalkListener aggregateWalkListener, String relPath, Node node, int depth)
        throws RepositoryException {
    if (node != null) {
        boolean included = includes(relPath);
        aggregateWalkListener.onNodeBegin(node, included, depth);
        PropertyIterator piter = node.getProperties();
        while (piter.hasNext()) {
            Property prop = piter.nextProperty();
            if (includes(relPath + "/" + prop.getName())) {
                aggregateWalkListener.onProperty(prop, depth + 1);
            }
        }
        aggregateWalkListener.onChildren(node, depth);

        // copy nodes to list
        NodeIterator niter = node.getNodes();
        long size = niter.getSize();
        List<Node> nodes = new ArrayList<Node>(size > 0 ? (int) size : 16);
        while (niter.hasNext()) {
            nodes.add(niter.nextNode());
        }

        // if node is not orderable, sort them alphabetically
        boolean hasOrderableChildNodes = node.getPrimaryNodeType().hasOrderableChildNodes();
        if (!hasOrderableChildNodes) {
            Collections.sort(nodes, NodeNameComparator.INSTANCE);
        }
        for (Node child: nodes) {
            String p = relPath + "/" + Text.getName(child.getPath());
            if (includes(p)) {
                walk(aggregateWalkListener, p, child, depth + 1);
            } else {
                // only inform if node is orderable
                if (hasOrderableChildNodes) {
                    aggregateWalkListener.onNodeIgnored(child, depth+1);
                }
            }
        }
        aggregateWalkListener.onNodeEnd(node, included, depth);
    }
}
 
Example 20
Source File: StorageUpdate24.java    From nextreports-server with Apache License 2.0 4 votes vote down vote up
private void createOrUpdateCleanHistorySettings() throws RepositoryException, IOException {
	LOG.info("Update Clean History Settings Node");
	Node rootNode = getTemplate().getRootNode();
	Node settingsNode = rootNode.getNode(StorageConstants.NEXT_SERVER_FOLDER_NAME + StorageConstants.PATH_SEPARATOR
			+ StorageConstants.SETTINGS_FOLDER_NAME);

	NodeIterator ni = settingsNode.getNodes(StorageConstants.CLEAN_HISTORY);
	Settings s = new Settings();
	CleanHistorySettings ch = s.getCleanHistory();
	boolean found = false;
	boolean foundSettings = false;
	while (ni.hasNext()) {
		Node nn = ni.nextNode();
		// this is the node itself
		PropertyIterator ni2 = nn.getProperties();
		foundSettings = true;
		while (ni2.hasNext()) {
			Property nn2 = ni2.nextProperty();
			if (StorageConstants.DAYS_TO_DELETE.equals(nn2.getName())) {
				found = true;
				LOG.info("Found Clean History Settings Node DAYS_TO_DELETE skipping ...");
				break;
			}
		}
		if (!found) {
			nn.setProperty(StorageConstants.DAYS_TO_DELETE, ch.getDaysToDelete());
			getTemplate().save();
			LOG.info("Did not Found Clean History Settings Node DAYS_TO_DELETE adding default ...");
			break;
		}
	}

	if (!foundSettings) {
		LOG.info("Did not find Clean History Settings Node at all, adding default one");
		Node cleanHistoryNode = settingsNode.addNode(StorageConstants.CLEAN_HISTORY);
		cleanHistoryNode.addMixin("mix:referenceable");
		cleanHistoryNode.setProperty("className", CleanHistorySettings.class.getName());

		cleanHistoryNode.setProperty(StorageConstants.DAYS_TO_KEEP, ch.getDaysToKeep());
		cleanHistoryNode.setProperty(StorageConstants.CRON_EXPRESSION, ch.getCronExpression());
		cleanHistoryNode.setProperty(StorageConstants.DAYS_TO_DELETE, ch.getDaysToDelete());
		cleanHistoryNode.setProperty(StorageConstants.SHRINK_DATA_FOLDER, true);
		getTemplate().save();
	}

	
}