javax.jcr.NodeIterator Java Examples
The following examples show how to use
javax.jcr.NodeIterator.
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: BlogServiceImpl.java From publick-sling-blog with Apache License 2.0 | 7 votes |
/** * Get blog posts with pagination * * @param offset The starting point of blog posts to return. * @param limit The number of blog posts to return. * @return The blog posts. */ public NodeIterator getPosts(Long offset, Long limit) { NodeIterator nodes = null; if (session != null) { try { QueryManager queryManager = session.getWorkspace().getQueryManager(); Query query = queryManager.createQuery(BLOG_QUERY, Query.JCR_SQL2); if (offset != null) { query.setOffset(offset); } if (limit != null) { query.setLimit(limit); } QueryResult result = query.execute(); nodes = result.getNodes(); } catch (RepositoryException e) { LOGGER.error("Could not search repository", e); } } return nodes; }
Example #2
Source File: RepositoryCFile.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
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 #3
Source File: StorageUpdate10.java From nextreports-server with Apache License 2.0 | 6 votes |
private void modifyDashboardState() throws RepositoryException { LOG.info("Modify dashboard state - add columnCount property"); String path = StorageConstants.DASHBOARDS_ROOT; String className = "ro.nextreports.server.domain.DashboardState"; String statement = "/jcr:root" + ISO9075.encodePath(path) + "//*[@className='" + className + "']"; QueryResult queryResult = getTemplate().query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("Found " + nodes.getSize() + " dashboard state nodes"); while (nodes.hasNext()) { Node node = nodes.nextNode(); node.setProperty("columnCount", 2); } getTemplate().save(); }
Example #4
Source File: StorageUpdate12.java From nextreports-server with Apache License 2.0 | 6 votes |
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 #5
Source File: StorageUpdate15.java From nextreports-server with Apache License 2.0 | 6 votes |
private void updateTemplateNodes() throws RepositoryException { // add shortcutType node to all report templates nodes String statement = "/jcr:root" + ISO9075.encodePath(StorageConstants.REPORTS_ROOT) + "//*[@className='ro.nextreports.server.domain.Report']/templates"; QueryResult queryResult = getTemplate().query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("Add shortcutType node to all report templates nodes : Found " + nodes.getSize() + " report nodes"); while (nodes.hasNext()) { Node node = nodes.nextNode(); NodeIterator templatesForReport = node.getNodes(); while (templatesForReport.hasNext()) { Node template = templatesForReport.nextNode(); Node shortcutTypeNode = template.addNode("shortcutType"); shortcutTypeNode.setProperty("type", 0); shortcutTypeNode.setProperty("timeType", 0); shortcutTypeNode.setProperty("timeUnits", 0); } } getTemplate().save(); }
Example #6
Source File: JcrPackageRegistry.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
/** * internally adds the packages below {@code root} to the given list * recursively. * * @param root root node * @param packages list for the packages * @throws RepositoryException if an error occurs */ private void listPackages(Node root, Set<PackageId> packages) throws RepositoryException { for (NodeIterator iter = root.getNodes(); iter.hasNext();) { Node child = iter.nextNode(); if (".snapshot".equals(child.getName())) { continue; } try (JcrPackageImpl pack = new JcrPackageImpl(this, child)) { if (pack.isValid()) { // skip packages with illegal names JcrPackageDefinition jDef = pack.getDefinition(); if (jDef == null || !jDef.getId().isValid()) { continue; } packages.add(jDef.getId()); } else if (child.hasNodes()) { listPackages(child, packages); } } } }
Example #7
Source File: Purge.java From APM with Apache License 2.0 | 6 votes |
private void purge(final Context context, final ActionResult actionResult) throws RepositoryException, ActionExecutionException { NodeIterator iterator = getPermissions(context); String normalizedPath = normalizePath(path); while (iterator != null && iterator.hasNext()) { Node node = iterator.nextNode(); if (node.hasProperty(PermissionConstants.REP_ACCESS_CONTROLLED_PATH)) { String parentPath = node.getProperty(PermissionConstants.REP_ACCESS_CONTROLLED_PATH) .getString(); String normalizedParentPath = normalizePath(parentPath); boolean isUsersPermission = parentPath.startsWith(context.getCurrentAuthorizable().getPath()); if (StringUtils.startsWith(normalizedParentPath, normalizedPath) && !isUsersPermission) { RemoveAll removeAll = new RemoveAll(parentPath); ActionResult removeAllResult = removeAll.execute(context); if (Status.ERROR.equals(removeAllResult.getStatus())) { copyErrorMessages(removeAllResult, actionResult); } } } } }
Example #8
Source File: JcrStorageDao.java From nextreports-server with Apache License 2.0 | 6 votes |
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 #9
Source File: TestBase.java From sling-whiteboard with Apache License 2.0 | 6 votes |
static void visitRecursively(Node n, Predicate<String> pathFilter, Set<String> allPathsFound) throws RepositoryException { if(!"/".equals(n.getPath()) && !pathFilter.test(n.getPath())) { return; } log.debug("visit({})", n.getPath()); if(allPathsFound != null) { allPathsFound.add(n.getPath()); } final NodeIterator it = n.getNodes(); while(it.hasNext()) { final Node next = it.nextNode(); visitRecursively(next, pathFilter, allPathsFound); } }
Example #10
Source File: JcrExporter.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
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 #11
Source File: StorageUpdate6.java From nextreports-server with Apache License 2.0 | 6 votes |
private void addAnalystUserProfile() throws RepositoryException { LOG.info("User profile analyst"); String path = StorageConstants.USERS_ROOT ; String className = "ro.nextreports.server.domain.User"; String statement = "/jcr:root" + ISO9075.encodePath(path) + "//*[@className='" + className + "']"; QueryResult queryResult = getTemplate().query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("Found " + nodes.getSize() + " nodes"); while (nodes.hasNext()) { Node node = nodes.nextNode(); node.setProperty("profile", "analyst"); } getTemplate().save(); }
Example #12
Source File: JcrPackageManagerImplTest.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
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 #13
Source File: DefaultObjectWrapper.java From sling-whiteboard with Apache License 2.0 | 6 votes |
public NodeIterator wrap(SessionWrapper s, final NodeIterator iter) { return new NodeIteratorAdapter(new Iterator<Node>() { @Override public boolean hasNext() { return iter.hasNext(); } @Override public Node next() { return wrap(s, iter.nextNode()); } @Override public void remove() { iter.remove(); } }); }
Example #14
Source File: JcrStorageDao.java From nextreports-server with Apache License 2.0 | 6 votes |
public void clearUserWidgetData(String widgetId) { try { String className = "ro.nextreports.server.domain.UserWidgetParameters"; String xpath = "/jcr:root" + ISO9075.encodePath(StorageConstants.USERS_DATA_ROOT) + "//*[@className='" + className + "']"; NodeIterator nodes = getTemplate().query(xpath).getNodes(); while (nodes.hasNext()) { Node node = nodes.nextNode(); if (node.getName().equals(widgetId)) { node.remove(); } } getTemplate().save(); } catch (RepositoryException e) { throw convertJcrAccessException(e); } }
Example #15
Source File: JcrStorageDao.java From nextreports-server with Apache License 2.0 | 6 votes |
private Entity[] getEntities(QueryResult queryResult) { try { NodeIterator nodes = queryResult.getNodes(); List<Entity> entities = new ArrayList<Entity>(); 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 #16
Source File: StorageUpdate8.java From nextreports-server with Apache License 2.0 | 6 votes |
private void updateInternalSettings() throws RepositoryException { // find all internalSettings nodes from DASHBOARDS and change chartId property in entityId String statement = "/jcr:root" + ISO9075.encodePath(StorageConstants.DASHBOARDS_ROOT) + "//*[fn:name()='internalSettings']"; QueryResult queryResult = getTemplate().query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("Found " + nodes.getSize() + " internalSettings nodes"); while (nodes.hasNext()) { Node node = nodes.nextNode(); try { Property prop = node.getProperty("chartId"); node.setProperty("entityId", prop.getValue()); prop.remove(); } catch (PathNotFoundException ex) { // if property not found we have nothing to do } } }
Example #17
Source File: StorageUpdate3.java From nextreports-server with Apache License 2.0 | 6 votes |
private void renameChartWidgetClassName() throws RepositoryException { LOG.info("Rename chart widget class name"); String path = StorageConstants.DASHBOARDS_ROOT; String className = "ro.nextreports.server.web.chart.ChartWidget"; String newClassName = "ro.nextreports.server.web.dashboard.chart.ChartWidget"; String statement = "/jcr:root" + ISO9075.encodePath(path) + "//*[@widgetClassName='" + className + "']"; QueryResult queryResult = getTemplate().query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("Found " + nodes.getSize() + " nodes"); while (nodes.hasNext()) { Node node = nodes.nextNode(); node.setProperty("widgetClassName", newClassName); } getTemplate().save(); }
Example #18
Source File: RepositoryRefactor.java From urule with Apache License 2.0 | 6 votes |
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 #19
Source File: RepositoryServiceImpl.java From urule with Apache License 2.0 | 6 votes |
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 #20
Source File: RepositoryServiceImpl.java From urule with Apache License 2.0 | 6 votes |
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 #21
Source File: DefaultWorkspaceFilter.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
private void dumpCoverage(javax.jcr.Node node, ProgressTracker tracker, boolean skipJcrContent) throws RepositoryException { String path = node.getPath(); if (skipJcrContent && "jcr:content".equals(Text.getName(path))) { return; } boolean contained; if ((contained = contains(path)) || isAncestor(path)) { if (contained) { tracker.track("A", path); } NodeIterator iter = node.getNodes(); while (iter.hasNext()) { dumpCoverage(iter.nextNode(), tracker, skipJcrContent); } } }
Example #22
Source File: RepositoryServiceImpl.java From urule with Apache License 2.0 | 6 votes |
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 #23
Source File: JcrStorageDao.java From nextreports-server with Apache License 2.0 | 6 votes |
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 #24
Source File: PageServiceImpl.java From mycollab with GNU Affero General Public License v3.0 | 5 votes |
@Override public List<Page> getPages(final String path, final String requestedUser) { return jcrTemplate.execute(session -> { Node rootNode = session.getRootNode(); Node node = JcrUtils.getNodeIfExists(rootNode, path); if (node != null) { if (isNodeFolder(node)) { List<Page> pages = new ArrayList<>(); NodeIterator childNodes = node.getNodes(); while (childNodes.hasNext()) { Node childNode = childNodes.nextNode(); if (isNodePage(childNode)) { if (isAccessible(childNode, requestedUser)) { Page page = convertNodeToPage(childNode); pages.add(page); } } } return pages; } else { throw new ContentException(String.format("Do not support any node type except mycollab:folder. The current node has type: %s and its path is %s", node.getPrimaryNodeType().getName(), path)); } } return new ArrayList<Page>(); }); }
Example #25
Source File: JcrWorkspaceFilter.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
public static void saveLegacyFilter(WorkspaceFilter filter, Node defNode, boolean save) throws RepositoryException { // delete all nodes first for (NodeIterator iter = defNode.getNodes(); iter.hasNext();) { iter.nextNode().remove(); } int nr = 0; for (PathFilterSet set: filter.getFilterSets()) { Node setNode = defNode.addNode("f" + nr); setNode.setProperty(JcrPackageDefinitionImpl.PN_ROOT, set.getRoot()); int eNr = 0; for (ItemFilterSet.Entry e: set.getEntries()) { // expect path filter if (!(e.getFilter() instanceof DefaultPathFilter)) { throw new IllegalArgumentException("Can only handle default path filters."); } Node eNode = setNode.addNode("f" + eNr); eNode.setProperty(JcrPackageDefinitionImpl.PN_TYPE, e.isInclude() ? "include" : "exclude"); eNode.setProperty(JcrPackageDefinitionImpl.PN_PATTERN, ((DefaultPathFilter) e.getFilter()).getPattern()); eNr++; } nr++; } if (save) { defNode.getSession().save(); } }
Example #26
Source File: WebdavProviderTestCase.java From commons-vfs with Apache License 2.0 | 5 votes |
/** 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 #27
Source File: TestPackageInstall.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * installs a package that contains a node with childnode ordering and full-coverage sub nodes. * see JCRVLT-24 */ @Test public void testChildNodeOrder() throws IOException, RepositoryException, PackageException { JcrPackage pack = packMgr.upload(getStream("/test-packages/test_childnodeorder.zip"), false); assertNotNull(pack); pack.install(getDefaultOptions()); assertNodeExists("/tmp/ordertest/test/rail/items/modes/items"); NodeIterator iter = admin.getNode("/tmp/ordertest/test/rail/items/modes/items").getNodes(); StringBuilder names = new StringBuilder(); while (iter.hasNext()) { names.append(iter.nextNode().getName()).append(","); } assertEquals("child order", "a,d,b,c,", names.toString()); }
Example #28
Source File: RepositoryCopier.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private void trackTree(Node node, boolean isNew) throws RepositoryException { NodeIterator iter = node.getNodes(); while (iter.hasNext()) { Node child = iter.nextNode(); if (isNew) { track(child.getPath(), "%06d A", ++totalNodes); } else { track(child.getPath(), "%06d U", ++totalNodes); } trackTree(child, isNew); } }
Example #29
Source File: JcrSysViewTransformer.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
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 #30
Source File: JcrStorageDao.java From nextreports-server with Apache License 2.0 | 5 votes |
public Entity[] getBaseEntityChildren(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()) { Node child = nodes.nextNode(); if (child.getName().endsWith("_history")) { continue; } Entity entity = getEntity(child); if (entity != null) { entities.add(entity); } } return entities.toArray(new Entity[entities.size()]); } catch (RepositoryException e) { throw convertJcrAccessException(e); } }