Java Code Examples for javax.jcr.Node#remove()
The following examples show how to use
javax.jcr.Node#remove() .
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: 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 2
Source File: VltUtils.java From publick-sling-blog with Apache License 2.0 | 6 votes |
public static void deletePackage(JcrPackage jcrPackage) { if (jcrPackage == null) { return; } Node node = jcrPackage.getNode(); jcrPackage.close(); try { if (node != null) { node.remove(); } } catch (RepositoryException e) { // do nothing } }
Example 3
Source File: GenericAggregator.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} * * Throws an exception if this aggregator allows children but * {@code recursive} is {@code false}. */ public ImportInfo remove(Node node, boolean recursive, boolean trySave) throws RepositoryException { if (fullCoverage && !recursive) { // todo: allow smarter removal throw new RepositoryException("Unable to remove content since aggregation has children and recursive is not set."); } ImportInfo info = new ImportInfoImpl(); info.onDeleted(node.getPath()); Node parent = node.getParent(); if (getAclManagement().isACLNode(node)) { getAclManagement().clearACL(parent); } else { node.remove(); } if (trySave) { parent.getSession().save(); } return info; }
Example 4
Source File: FolderArtifactHandler.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
private Node modifyPrimaryType(Node node, ImportInfoImpl info) throws RepositoryException { String name = node.getName(); Node parent = node.getParent(); // check versionable ensureCheckedOut(node, info); ChildNodeStash recovery = new ChildNodeStash(node.getSession()); recovery.stashChildren(node); node.remove(); // now create the new node Node newNode = parent.addNode(name, nodeType); info.onReplaced(newNode.getPath()); // move the children back recovery.recoverChildren(newNode, info); return newNode; }
Example 5
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 6 votes |
@Override public void removeProjectVersion(RepositorySession session, String repoId, String namespace, String projectId, String projectVersion) throws MetadataRepositoryException { final Session jcrSession = getSession(session); try { String path = getProjectPath(repoId, namespace, projectId); Node root = jcrSession.getRootNode(); Node nodeAtPath = root.getNode(path); for (Node node : JcrUtils.getChildNodes(nodeAtPath)) { if (node.isNodeType(PROJECT_VERSION_NODE_TYPE) && StringUtils.equals(projectVersion, node.getName())) { node.remove(); } } } catch (RepositoryException e) { throw new MetadataRepositoryException(e.getMessage(), e); } }
Example 6
Source File: JcrExporter.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public void close() throws IOException, RepositoryException { if (autoDeleteFiles) { for (ExportInfo.Entry e: exportInfo.getEntries().values()) { if (e.type == ExportInfo.Type.DELETE) { String relPath = PathUtil.getRelativePath(localParent.getPath(), e.path); try { Node node = localParent.getNode(relPath); node.remove(); track("D", relPath); } catch (RepositoryException e1) { track(e1, relPath); } } } } localParent.getSession().save(); }
Example 7
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 6 votes |
@Override public void removeProject(RepositorySession session, String repositoryId, String namespace, String projectId) throws MetadataRepositoryException { final Session jcrSession = getSession(session); try { Node root = jcrSession.getRootNode(); String namespacePath = getNamespacePath(repositoryId, namespace); if (root.hasNode(namespacePath)) { Iterator<Node> nodeIterator = JcrUtils.getChildNodes(root.getNode(namespacePath)).iterator(); while (nodeIterator.hasNext()) { Node node = nodeIterator.next(); if (node.isNodeType(org.apache.archiva.metadata.repository.jcr.JcrConstants.PROJECT_MIXIN_TYPE) && projectId.equals(node.getName())) { node.remove(); } } } } catch (RepositoryException e) { throw new MetadataRepositoryException(e.getMessage(), e); } }
Example 8
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 6 votes |
@Override public void removeNamespace(RepositorySession session, String repositoryId, String projectId) throws MetadataRepositoryException { final Session jcrSession = getSession(session); try { Node root = jcrSession.getRootNode(); String path = getNamespacePath(repositoryId, projectId); if (root.hasNode(path)) { Node node = root.getNode(path); if (node.isNodeType(NAMESPACE_MIXIN_TYPE)) { node.remove(); } } } catch (RepositoryException e) { throw new MetadataRepositoryException(e.getMessage(), e); } }
Example 9
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 6 votes |
@Override public void removeMetadataFacet(RepositorySession session, String repositoryId, String facetId, String name) throws MetadataRepositoryException { final Session jcrSession = getSession(session); try { Node root = jcrSession.getRootNode(); String path = getFacetPath(repositoryId, facetId, name); if (root.hasNode(path)) { Node node = root.getNode(path); do { // also remove empty container nodes Node parent = node.getParent(); node.remove(); node = parent; } while (!node.hasNodes()); } } catch (RepositoryException e) { throw new MetadataRepositoryException(e.getMessage(), e); } }
Example 10
Source File: RepositoryServiceImpl.java From urule with Apache License 2.0 | 5 votes |
public void deleteFile(String path,User user) throws Exception{ if(!permissionService.fileHasWritePermission(path)){ throw new NoPermissionException(); } repositoryInteceptor.deleteFile(path); path = processPath(path); Node rootNode=getRootNode(); if (!rootNode.hasNode(path)) { throw new RuleException("File [" + path + "] not exist."); } String[] subpaths = path.split("/"); Node fileNode = rootNode; for (String subpath : subpaths) { if (StringUtils.isEmpty(subpath)) { continue; } String subDirs[] = subpath.split("\\."); for (String dir : subDirs) { if (StringUtils.isEmpty(dir)) { continue; } if (!fileNode.hasNode(dir)) { continue; } fileNode = fileNode.getNode(dir); lockCheck(fileNode,user); if (!fileNode.isCheckedOut()) { versionManager.checkout(fileNode.getPath()); } } } fileNode = rootNode.getNode(path); lockCheck(fileNode,user); if (!fileNode.isCheckedOut()) { versionManager.checkout(fileNode.getPath()); } fileNode.remove(); session.save(); }
Example 11
Source File: JcrStorageDao.java From nextreports-server with Apache License 2.0 | 5 votes |
public void removeEntityById(String id) throws NotFoundException { try { Node node = checkId(id); node.remove(); } catch (RepositoryException e) { throw convertJcrAccessException(e); } getTemplate().save(); entitiesCache.remove(id); }
Example 12
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 5 votes |
@Override public void removeFacetFromArtifact(RepositorySession session, String repositoryId, String namespace, String project, String projectVersion, MetadataFacet metadataFacet) throws MetadataRepositoryException { final Session jcrSession = getSession(session); try { Node root = jcrSession.getRootNode(); String path = getProjectVersionPath(repositoryId, namespace, project, projectVersion); if (root.hasNode(path)) { Node node = root.getNode(path); for (Node n : JcrUtils.getChildNodes(node)) { if (n.isNodeType(ARTIFACT_NODE_TYPE)) { ArtifactMetadata artifactMetadata = getArtifactFromNode(repositoryId, n); log.debug("artifactMetadata: {}", artifactMetadata); MetadataFacet metadataFacetToRemove = artifactMetadata.getFacet(metadataFacet.getFacetId()); if (metadataFacetToRemove != null && metadataFacet.equals(metadataFacetToRemove)) { n.remove(); } } } } } catch (RepositoryException e) { throw new MetadataRepositoryException(e.getMessage(), e); } }
Example 13
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 5 votes |
@Override public void removeArtifact(RepositorySession session, String repositoryId, String namespace, String projectId, String projectVersion, String id) throws MetadataRepositoryException { final Session jcrSession = getSession(session); try { Node root = jcrSession.getRootNode(); String path = getArtifactPath(repositoryId, namespace, projectId, projectVersion, id); if (root.hasNode(path)) { root.getNode(path).remove(); } // remove version path = getProjectPath(repositoryId, namespace, projectId); Node nodeAtPath = root.getNode(path); for (Node node : JcrUtils.getChildNodes(nodeAtPath)) { if (node.isNodeType(PROJECT_VERSION_NODE_TYPE) // && StringUtils.equals(node.getName(), projectVersion)) { node.remove(); } } } catch (RepositoryException e) { throw new MetadataRepositoryException(e.getMessage(), e); } }
Example 14
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 5 votes |
@Override public void removeTimestampedArtifact(RepositorySession session, ArtifactMetadata artifactMetadata, String baseVersion) throws MetadataRepositoryException { final Session jcrSession = getSession(session); String repositoryId = artifactMetadata.getRepositoryId(); try { Node root = jcrSession.getRootNode(); String path = getProjectVersionPath(repositoryId, artifactMetadata.getNamespace(), artifactMetadata.getProject(), baseVersion); if (root.hasNode(path)) { Node node = root.getNode(path); for (Node n : JcrUtils.getChildNodes(node)) { if (n.isNodeType(ARTIFACT_NODE_TYPE)) { if (n.hasProperty("version")) { String version = n.getProperty("version").getString(); if (StringUtils.equals(version, artifactMetadata.getVersion())) { n.remove(); } } } } } } catch (RepositoryException e) { throw new MetadataRepositoryException(e.getMessage(), e); } }
Example 15
Source File: FileAggregator.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public ImportInfo remove(Node node, boolean recursive, boolean trySave) throws RepositoryException { ImportInfo info = new ImportInfoImpl(); info.onDeleted(node.getPath()); Session s = node.getSession(); node.remove(); if (trySave) { s.save(); } return info; }
Example 16
Source File: NodeTypeAggregator.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public ImportInfo remove(Node node, boolean recursive, boolean trySave) throws RepositoryException { ImportInfo info = new ImportInfoImpl(); info.onDeleted(node.getPath()); Session s = node.getSession(); node.remove(); if (trySave) { s.save(); } return info; }
Example 17
Source File: MockedResourceResolver.java From sling-samples with Apache License 2.0 | 5 votes |
public void delete(Resource resource) throws PersistenceException { if (resources.contains(resource)) { resources.remove(resource); Node node = resource.adaptTo(Node.class); try { node.remove(); } catch (RepositoryException e) { throw new PersistenceException("RepositoryException: "+e, e); } } else { throw new UnsupportedOperationException("Not implemented"); } }
Example 18
Source File: CatalogDataResourceProviderManagerImplTest.java From commerce-cif-connector with Apache License 2.0 | 5 votes |
@After public void afterTest() throws Exception { manager.deactivate(componentContext); final String absPath = "/var/commerce/products"; if (session.nodeExists(absPath)) { Node root = session.getNode(absPath); root.remove(); session.save(); } }
Example 19
Source File: JcrPackageImpl.java From jackrabbit-filevault with Apache License 2.0 | 4 votes |
/** * Internally creates the snapshot * @param opts exports options when building the snapshot * @param replace if {@code true} existing snapshot will be replaced * @param acHandling user acHandling to use when snapshot is installed, i.e. package is uninstalled * @return the package of the snapshot or {@code null} * @throws RepositoryException if an error occurrs. * @throws PackageException if an error occurrs. * @throws IOException if an error occurrs. */ @Nullable private JcrPackage snapshot(@NotNull ExportOptions opts, boolean replace, @Nullable AccessControlHandling acHandling) throws RepositoryException, PackageException, IOException { if (node == null) { return null; } PackageId id = getSnapshotId(); Node packNode = getSnapshotNode(); if (packNode != null) { if (!replace) { log.debug("Refusing to recreate snapshot {}, already exists.", id); return null; } else { packNode.remove(); node.getSession().save(); } } JcrPackageDefinitionImpl myDef = (JcrPackageDefinitionImpl) getDefinition(); WorkspaceFilter filter = myDef.getMetaInf().getFilter(); if (filter == null || filter.getFilterSets().isEmpty()) { log.info("Refusing to create snapshot {} due to empty filters", id); return null; } for (PathFilterSet set: filter.getFilterSets()) { if (("".equals(set.getRoot()) || "/".equals(set.getRoot())) && set.getEntries().isEmpty()) { log.info("Refusing to create snapshot {} due to / only filter", id); return null; } } log.debug("Creating snapshot for {}.", id); JcrPackageManagerImpl packMgr = new JcrPackageManagerImpl(mgr); String path = mgr.getInstallationPath(id); String parentPath = Text.getRelativeParent(path, 1); Node folder = packMgr.mkdir(parentPath, true); JcrPackage snap = mgr.createNew(folder, id, null, true); JcrPackageDefinitionImpl snapDef = (JcrPackageDefinitionImpl) snap.getDefinition(); snapDef.setId(id, false); snapDef.setFilter(filter, false); snapDef.set(JcrPackageDefinition.PN_DESCRIPTION, "Snapshot of package " + myDef.getId().toString(), false); if (acHandling == null) { snapDef.set(JcrPackageDefinition.PN_AC_HANDLING, myDef.get(JcrPackageDefinition.PN_AC_HANDLING), false); } else { snapDef.set(JcrPackageDefinition.PN_AC_HANDLING, acHandling.name(), false); } if (opts.getListener() != null) { opts.getListener().onMessage(ProgressTrackerListener.Mode.TEXT, "Creating snapshot for package " + myDef.getId(), ""); } packMgr.assemble(snap.getNode(), snapDef, opts.getListener()); log.debug("Creating snapshot for {} completed.", id); mgr.dispatch(PackageEvent.Type.SNAPSHOT, id, null); return snap; }
Example 20
Source File: DocViewSAXImporter.java From jackrabbit-filevault with Apache License 2.0 | 4 votes |
/** * {@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); } }