Java Code Examples for javax.jcr.Node#getParent()
The following examples show how to use
javax.jcr.Node#getParent() .
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: 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 2
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 3
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 4
Source File: JcrStorageDao.java From nextreports-server with Apache License 2.0 | 6 votes |
public void renameEntity(String path, String newName) throws NotFoundException, DuplicationException { checkPath(path); Node node = getNode(path); Node parent; try { parent = node.getParent(); } catch (RepositoryException e) { throw convertJcrAccessException(e); } testDuplication(parent, newName); Entity entity = getEntity(node); entity.setLastUpdatedDate(new Date()); entity.setLastUpdatedBy(ServerUtil.getUsername()); getJcrom().updateNode(node, entity); getTemplate().rename(node, newName); getTemplate().save(); entitiesCache.remove(entity.getId()); // clear all children from cache (path is modified!) clearChildrenCache(entity.getId()); }
Example 5
Source File: SyncHandler.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private SyncResult syncToDisk(Session session) throws RepositoryException, IOException { SyncResult res = new SyncResult(); for (String path: preparedJcrChanges) { boolean recursive = path.endsWith("/"); if (recursive) { path = path.substring(0, path.length() - 1); } if (!contains(path)) { log.debug("**** rejected. filter does not include {}", path); continue; } File file = getFileForJcrPath(path); log.debug("**** about sync jcr:/{} -> file://{}", path, file.getAbsolutePath()); Node node; Node parentNode; if (session.nodeExists(path)) { node = session.getNode(path); parentNode = node.getParent(); } else { node = null; String parentPath = Text.getRelativeParent(path, 1); parentNode = session.nodeExists(parentPath) ? session.getNode(parentPath) : null; } TreeSync tree = createTreeSync(SyncMode.JCR2FS); res.merge(tree.syncSingle(parentNode, node, file, recursive)); } return res; }
Example 6
Source File: SyncHandler.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private void syncToJcr(Session session, SyncResult res) throws RepositoryException, IOException { for (String filePath: pendingFsChanges.keySet()) { if (res.getByFsPath(filePath) != null) { log.debug("ignoring change triggered by previous JCR->FS update. {}", filePath); return; } File file = pendingFsChanges.get(filePath); String path = getJcrPathForFile(file); log.debug("**** about sync file:/{} -> jcr://{}", file.getAbsolutePath(), path); if (!contains(path)) { log.debug("**** rejected. filter does not include {}", path); continue; } Node node; Node parentNode; if (session.nodeExists(path)) { node = session.getNode(path); parentNode = node.getParent(); } else { node = null; String parentPath = Text.getRelativeParent(path, 1); parentNode = session.nodeExists(parentPath) ? session.getNode(parentPath) : null; } TreeSync tree = createTreeSync(SyncMode.FS2JCR); tree.setSyncMode(SyncMode.FS2JCR); res.merge(tree.syncSingle(parentNode, node, file, false)); } }
Example 7
Source File: JcrPackageManagerImplTest.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private String getParentPath(String path) throws RepositoryException { Node currentNode = admin.getNode(path); if (currentNode.getPath().equals(admin.getRootNode().getPath())) { return null; } else { Node parent = currentNode.getParent(); if (parent != null) { return parent.getPath(); } else { return null; } } }
Example 8
Source File: CommentsServiceImpl.java From sling-samples with Apache License 2.0 | 4 votes |
/** * @see org.apache.sling.sample.slingshot.comments.CommentsService#addComment(org.apache.sling.api.resource.Resource, org.apache.sling.sample.slingshot.comments.Comment) */ @Override public void addComment(final Resource resource, final Comment c) throws PersistenceException { final String commentsPath = this.getCommentsResourcePath(resource); final Map<String, Object> props = new HashMap<String, Object>(); props.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, RESOURCETYPE_COMMENTS); final Resource ratingsResource = ResourceUtil.getOrCreateResource(resource.getResourceResolver(), commentsPath, props, null, true); final Map<String, Object> properties = new HashMap<String, Object>(); properties.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, CommentsUtil.RESOURCETYPE_COMMENT); properties.put(CommentsUtil.PROPERTY_TITLE, c.getTitle()); properties.put(CommentsUtil.PROPERTY_TEXT, c.getText()); properties.put(CommentsUtil.PROPERTY_USER, c.getCreatedBy()); // we try it five times PersistenceException exception = null; Resource newResource = null; for(int i=0; i<5; i++) { try { exception = null; final String name = ResourceUtil.createUniqueChildName(ratingsResource, Util.filter(c.getTitle())); newResource = resource.getResourceResolver().create(ratingsResource, name, properties); resource.getResourceResolver().commit(); break; } catch ( final PersistenceException pe) { resource.getResourceResolver().revert(); resource.getResourceResolver().refresh(); exception = pe; } } if ( exception != null ) { throw exception; } // order node at the top (if jcr based) final Node newNode = newResource.adaptTo(Node.class); if ( newNode != null ) { try { final Node parent = newNode.getParent(); final Node firstNode = parent.getNodes().nextNode(); if ( !firstNode.getName().equals(newNode.getName()) ) { parent.orderBefore(newNode.getName(), firstNode.getName()); newNode.getSession().save(); } } catch ( final RepositoryException re) { logger.error("Unable to order comment to the top", re); } } }
Example 9
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 4 votes |
private ArtifactMetadata getArtifactFromNode(String repositoryId, Node artifactNode) throws RepositoryException { String id = artifactNode.getName(); ArtifactMetadata artifact = new ArtifactMetadata(); artifact.setId(id); artifact.setRepositoryId(repositoryId == null ? artifactNode.getAncestor(2).getName() : repositoryId); Node projectVersionNode = artifactNode.getParent(); Node projectNode = projectVersionNode.getParent(); Node namespaceNode = projectNode.getParent(); artifact.setNamespace(namespaceNode.getProperty("namespace").getString()); artifact.setProject(projectNode.getName()); artifact.setProjectVersion(projectVersionNode.getName()); artifact.setVersion(artifactNode.hasProperty("version") ? artifactNode.getProperty("version").getString() : projectVersionNode.getName()); if (artifactNode.hasProperty(JCR_LAST_MODIFIED)) { artifact.setFileLastModified(artifactNode.getProperty(JCR_LAST_MODIFIED).getDate().getTimeInMillis()); } if (artifactNode.hasProperty("whenGathered")) { Calendar cal = artifactNode.getProperty("whenGathered").getDate(); artifact.setWhenGathered(ZonedDateTime.ofInstant(cal.toInstant(), cal.getTimeZone().toZoneId())); } if (artifactNode.hasProperty("size")) { artifact.setSize(artifactNode.getProperty("size").getLong()); } Node cslistNode = getOrAddNodeByPath(artifactNode, "checksums"); NodeIterator csNodeIt = cslistNode.getNodes("*"); while (csNodeIt.hasNext()) { Node csNode = csNodeIt.nextNode(); if (csNode.isNodeType(CHECKSUM_NODE_TYPE)) { addChecksum(artifact, csNode); } } retrieveFacetProperties(artifact, artifactNode); return artifact; }