Java Code Examples for javax.jcr.Node#isNodeType()
The following examples show how to use
javax.jcr.Node#isNodeType() .
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: 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 2
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 3
Source File: FileAggregator.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public boolean includes(Node root, Node node, String path) throws RepositoryException { if (path == null) { path = node.getPath(); } int depth = PathUtil.getDepth(path) - root.getDepth(); boolean isFile = root.isNodeType(JcrConstants.NT_FILE); if (depth == 0) { // should not happen, but ok. return true; } else if (depth == 1) { // on root level, we only allow "jcr:content" if it's a file if (isFile && node.getName().equals(JcrConstants.JCR_CONTENT)) { return true; } } else { // no sub nodes. } // only respect content filter if not empty return !contentFilter.isEmpty() && contentFilter.contains(node, path, depth); }
Example 4
Source File: NtFileItemFilter.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} * * @return {@code true} if the item is a nt:file or nt:resource property */ public boolean matches(Item item, int depth) throws RepositoryException { if (item.isNode()) { // include nt:file node Node node = (Node) item; if (depth == 0) { return node.isNodeType(JcrConstants.NT_FILE); } else if (depth == 1) { // include jcr:content return item.getName().equals(JcrConstants.JCR_CONTENT); } else { return false; } } else { if (depth == 1) { return fileNames.contains(item.getName()); } else if (depth == 2 && item.getParent().getName().equals(JcrConstants.JCR_CONTENT)) { return resNames.contains(item.getName()); } else { return false; } } }
Example 5
Source File: FolderArtifactHandler.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private void ensureCheckedOut(Node node, ImportInfoImpl info) throws RepositoryException { boolean isCheckedOut = !node.isNodeType(JcrConstants.MIX_VERSIONABLE) || node.isCheckedOut(); if (!isCheckedOut) { info.registerToVersion(node.getPath()); try { node.checkout(); } catch (RepositoryException e) { info.log.warn("error while checkout node (ignored)", e); } } }
Example 6
Source File: PageServiceImpl.java From mycollab with GNU Affero General Public License v3.0 | 5 votes |
private static boolean isNodePage(Node node) { try { return node.isNodeType("wiki:page"); } catch (RepositoryException e) { return false; } }
Example 7
Source File: PageServiceImpl.java From mycollab with GNU Affero General Public License v3.0 | 5 votes |
private static boolean isNodeFolder(Node node) { try { return node.isNodeType("wiki:folder"); } catch (RepositoryException e) { return false; } }
Example 8
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 9
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 5 votes |
private Node getOrAddProjectNode(Session jcrSession, String repositoryId, String namespace, String projectId) throws RepositoryException { Node namespaceNode = getOrAddNamespaceNode(jcrSession, repositoryId, namespace); Node node = JcrUtils.getOrAddNode(namespaceNode, projectId, FOLDER_TYPE); if (!node.isNodeType(PROJECT_MIXIN_TYPE)) { node.addMixin(PROJECT_MIXIN_TYPE); } if (!node.hasProperty("id")) { node.setProperty("id", projectId); } return node; }
Example 10
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 11
Source File: AbstractJcrDao.java From nextreports-server with Apache License 2.0 | 5 votes |
protected boolean isVersionable(Node node) { try { return node.isNodeType("mix:versionable"); } catch (RepositoryException e) { throw convertJcrAccessException(e); } }
Example 12
Source File: FileArtifactHandler.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * Checks if the given node is a nt_resource like structure that was modified. this is to test if a single * file artifact needs to recreate existing content of a sub-typed jcr:content node. see JCRVLT-177 * * @param content the content node * @return {@code true} if modified * @throws RepositoryException if an error occurrs */ private boolean isModifiedNtResource(Node content) throws RepositoryException { if (content.getMixinNodeTypes().length > 0) { return true; } if (content.isNodeType(NodeType.NT_RESOURCE)) { return false; } // allow nt:unstructured with no child nodes return content.hasNodes(); }
Example 13
Source File: FileAggregator.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public boolean matches(Node node, String path) throws RepositoryException { if (node.isNodeType(JcrConstants.NT_FILE)) { return node.hasProperty(JcrConstants.JCR_CONTENT + "/" + JcrConstants.JCR_DATA); } else { return node.isNodeType(JcrConstants.NT_RESOURCE); } }
Example 14
Source File: TreeSync.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private Type getJcrType(Node node) throws RepositoryException { if (node == null) { return Type.MISSING; } else if (node.isNodeType(NodeType.NT_FILE)) { if (node.getMixinNodeTypes().length == 0) { // only ok, if pure nt:file Node content = node.getNode(Node.JCR_CONTENT); if (content.isNodeType(NodeType.NT_RESOURCE) && content.getMixinNodeTypes().length == 0) { return Type.FILE; } } return Type.UNSUPPORTED; } for (String nt: FULL_COVERAGE_NTS) { try { if (node.isNodeType(nt)) { return Type.FULL_COVERAGE; } } catch (RepositoryException e) { // ignore } } if (node.isNodeType(NodeType.NT_HIERARCHY_NODE)) { return Type.DIRECTORY; } else { return Type.UNSUPPORTED; } }
Example 15
Source File: RepositoryServiceImpl.java From urule with Apache License 2.0 | 5 votes |
@Override public void lockPath(String path,User user) throws Exception{ path = processPath(path); int pos=path.indexOf(":"); if(pos!=-1){ path=path.substring(0,pos); } Node rootNode=getRootNode(); if (!rootNode.hasNode(path)) { throw new RuleException("File [" + path + "] not exist."); } Node fileNode = rootNode.getNode(path); String topAbsPath=fileNode.getPath(); if(lockManager.isLocked(topAbsPath)){ String owner=lockManager.getLock(topAbsPath).getLockOwner(); throw new NodeLockException("【"+path+"】已被"+owner+"锁定,您不能进行再次锁定!"); } List<Node> nodeList=new ArrayList<Node>(); unlockAllChildNodes(fileNode, user, nodeList, path); for(Node node:nodeList){ if(!lockManager.isLocked(node.getPath())){ continue; } Lock lock=lockManager.getLock(node.getPath()); lockManager.unlock(lock.getNode().getPath()); } if(!fileNode.isNodeType(NodeType.MIX_LOCKABLE)){ if (!fileNode.isCheckedOut()) { versionManager.checkout(fileNode.getPath()); } fileNode.addMixin("mix:lockable"); session.save(); } lockManager.lock(topAbsPath, true, true, Long.MAX_VALUE, user.getUsername()); }
Example 16
Source File: FileArtifactHandler.java From jackrabbit-filevault with Apache License 2.0 | 4 votes |
private boolean importNtResource(ImportInfo info, Node content, Artifact artifact) throws RepositoryException, IOException { String path = content.getPath(); boolean modified = false; if (explodeXml && !content.isNodeType(JcrConstants.NT_RESOURCE)) { // explode xml InputStream in = artifact.getInputStream(); try { content.getSession().importXML(path, in, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); // can't really augment info here } finally { in.close(); } modified = true; } else { ValueFactory factory = content.getSession().getValueFactory(); Value value = factory.createValue(artifact.getInputStream()); if (!content.hasProperty(JcrConstants.JCR_DATA) || !value.equals(content.getProperty(JcrConstants.JCR_DATA).getValue())) { content.setProperty(JcrConstants.JCR_DATA, value); modified = true; } // always update last modified if binary was modified (bug #22969) if (!content.hasProperty(JcrConstants.JCR_LASTMODIFIED) || modified) { Calendar lastMod = Calendar.getInstance(); content.setProperty(JcrConstants.JCR_LASTMODIFIED, lastMod); modified = true; } if (!content.hasProperty(JcrConstants.JCR_MIMETYPE)) { String mimeType = artifact.getContentType(); if (mimeType == null) { mimeType = Text.getName(artifact.getRelativePath(), '.'); mimeType = MimeTypes.getMimeType(mimeType, MimeTypes.APPLICATION_OCTET_STREAM); } content.setProperty(JcrConstants.JCR_MIMETYPE, mimeType); modified = true; } if (content.isNew()) { // mark binary data as modified info.onCreated(path + "/" + JcrConstants.JCR_DATA); info.onNop(path); } else if (modified) { // mark binary data as modified info.onModified(path + "/" + JcrConstants.JCR_DATA); info.onModified(path); } } return modified; }
Example 17
Source File: DocViewSAXImporter.java From jackrabbit-filevault with Apache License 2.0 | 4 votes |
private VersioningState(StackElement stack, Node node) throws RepositoryException { this.stack = stack; this.node = node; isCheckedOut = node == null || !node.isNodeType(JcrConstants.MIX_VERSIONABLE) || node.isCheckedOut(); isParentCheckedOut = stack.isCheckedOut(); }
Example 18
Source File: DocViewSAXImporter.java From jackrabbit-filevault with Apache License 2.0 | 4 votes |
public StackElement(Node node, boolean isNew) throws RepositoryException { this.node = node; this.isNew = isNew; isCheckedOut = node == null || !node.isNodeType(JcrConstants.MIX_VERSIONABLE) || node.isCheckedOut(); }
Example 19
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; }
Example 20
Source File: JcrACLManagement.java From jackrabbit-filevault with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ public boolean isACLNode(Node node) throws RepositoryException { return node.isNodeType("rep:Policy"); }