Java Code Examples for javax.jcr.Session#getRootNode()
The following examples show how to use
javax.jcr.Session#getRootNode() .
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: DefaultWorkspaceFilter.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public void dumpCoverage(Session session, ProgressTrackerListener listener, boolean skipJcrContent) throws RepositoryException { ProgressTracker tracker = new ProgressTracker(listener); // get common ancestor Tree<PathFilterSet> tree = new Tree<PathFilterSet>(); for (PathFilterSet set: nodesFilterSets) { tree.put(set.getRoot(), set); } String rootPath = tree.getRootPath(); javax.jcr.Node rootNode; if (session.nodeExists(rootPath)) { rootNode = session.getNode(rootPath); } else if (session.nodeExists("/")) { log.warn("Common ancestor {} not found. Using root node", rootPath); rootNode = session.getRootNode(); rootPath = "/"; } else { throw new PathNotFoundException("Common ancestor " + rootPath+ " not found."); } log.debug("Starting coverage dump at {} (skipJcrContent={})", rootPath, skipJcrContent); dumpCoverage(rootNode, tracker, skipJcrContent); }
Example 2
Source File: ContentSessionFactory.java From mycollab with GNU Affero General Public License v3.0 | 6 votes |
@Override protected void registerNodeTypes() throws Exception { LOG.info("Register node types"); Session session = getSession(); final String[] jcrNamespaces = session.getWorkspace().getNamespaceRegistry().getPrefixes(); boolean createNamespace = true; for (String jcrNamespace : jcrNamespaces) { if (jcrNamespace.equals("mycollab")) { createNamespace = false; LOG.debug("Jackrabbit OCM namespace exists."); } } if (createNamespace) { session.getWorkspace().getNamespaceRegistry() .registerNamespace("mycollab", "http://www.esofthead.com/mycollab"); LOG.debug("Successfully created Mycollab content namespace."); } if (session.getRootNode() == null) { throw new ContentException("Jcr session setup not successful."); } NodeTypeManager manager = session.getWorkspace().getNodeTypeManager(); manager.registerNodeType(createMyCollabContentType(manager), true); manager.registerNodeType(createMyCollabFolderType(manager), true); session.logout(); }
Example 3
Source File: PageSessionFactory.java From mycollab with GNU Affero General Public License v3.0 | 6 votes |
@Override protected void registerNodeTypes() throws Exception { LOG.info("Register node types"); Session session = getSession(); final String[] jcrNamespaces = session.getWorkspace().getNamespaceRegistry().getPrefixes(); boolean createNamespace = true; for (String jcrNamespace : jcrNamespaces) { if (jcrNamespace.equals("wiki")) { createNamespace = false; LOG.debug("Jackrabbit OCM namespace exists."); } } if (createNamespace) { session.getWorkspace().getNamespaceRegistry().registerNamespace("wiki", "http://www.esofthead.com/wiki"); LOG.debug("Successfully created MyCollab content namespace."); } if (session.getRootNode() == null) { throw new ContentException("Jcr session setup not successful."); } NodeTypeManager manager = session.getWorkspace().getNodeTypeManager(); manager.registerNodeType(createWikiPageType(manager), true); manager.registerNodeType(createWikiFolderType(manager), true); session.logout(); }
Example 4
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 5
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 6
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 7
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 8
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 6 votes |
private Node findArtifactNode(Session jcrSession, String namespace, String projectId, String projectVersion, String id) throws RepositoryException { if (namespace==null || projectId==null||projectVersion==null||id==null) { return null; } Node root = jcrSession.getRootNode(); Node node = JcrUtils.getOrAddNode(root, "repositories"); for (Node n : JcrUtils.getChildNodes(node)) { String repositoryId = n.getName(); Node repo = getOrAddRepositoryContentNode(jcrSession, repositoryId); Node nsNode = JcrUtils.getNodeIfExists(repo, StringUtils.replaceChars(namespace, '.', '/')); if (nsNode!=null) { Node projNode = JcrUtils.getNodeIfExists(nsNode, projectId); if (projNode !=null ) { Node projVersionNode = JcrUtils.getNodeIfExists(projNode, projectVersion); if (projVersionNode != null) { return JcrUtils.getNodeIfExists(projVersionNode, id); } } } } return null; }
Example 9
Source File: TestFilteredPropertyExport.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * Setup the path /tmp/foo/bar with properties set at each level */ private void setupTmpFooBarWithProperties(Session session) throws RepositoryException { Node root = session.getRootNode(); Node tmp = setupProperties(root.addNode("tmp")); Node foo = setupProperties(tmp.addNode("foo")); setupProperties(foo.addNode("bar")); }
Example 10
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 5 votes |
@Override public void removeMetadataFacets(RepositorySession session, String repositoryId, String facetId) throws MetadataRepositoryException { final Session jcrSession = getSession(session); try { Node root = jcrSession.getRootNode(); String path = getFacetPath(repositoryId, facetId); if (root.hasNode(path)) { root.getNode(path).remove(); } } catch (RepositoryException e) { throw new MetadataRepositoryException(e.getMessage(), e); } }
Example 11
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 5 votes |
@Override public void removeRepository(RepositorySession session, String repositoryId) throws MetadataRepositoryException { final Session jcrSession = getSession(session); try { Node root = jcrSession.getRootNode(); String path = getRepositoryPath(repositoryId); if (root.hasNode(path)) { root.getNode(path).remove(); } } catch (RepositoryException e) { throw new MetadataRepositoryException(e.getMessage(), e); } }
Example 12
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 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 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 15
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 5 votes |
private Node getOrAddRepositoryNode(Session jcrSession, String repositoryId) throws RepositoryException { log.debug("getOrAddRepositoryNode " + repositoryId); Node root = jcrSession.getRootNode(); Node node = JcrUtils.getOrAddNode(root, "repositories"); log.debug("Repositories " + node); node = JcrUtils.getOrAddNode(node, repositoryId, REPOSITORY_NODE_TYPE); if (!node.hasProperty("id")) { node.setProperty("id", repositoryId); } return node; }