Java Code Examples for javax.jcr.Node#getName()

The following examples show how to use javax.jcr.Node#getName() . 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: FolderArtifactHandler.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
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 2
Source File: JcrExporter.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
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 3
Source File: JcrMetadataRepository.java    From archiva with Apache License 2.0 6 votes vote down vote up
private static Optional<MailingList> getMailinglist(Node mailinglistNode) {
    try {
        String mailingListName = mailinglistNode.getName();
    MailingList mailinglist = new MailingList();
    mailinglist.setName(mailingListName);
    mailinglist.setMainArchiveUrl(getPropertyString(mailinglistNode, "archive"));
    String n = "otherArchives";
    if (mailinglistNode.hasProperty(n)) {
        mailinglist.setOtherArchives(Arrays.asList(getPropertyString(mailinglistNode, n).split(",")));
    } else {
        mailinglist.setOtherArchives(Collections.<String>emptyList());
    }
    mailinglist.setPostAddress(getPropertyString(mailinglistNode, "post"));
    mailinglist.setSubscribeAddress(getPropertyString(mailinglistNode, "subscribe"));
    mailinglist.setUnsubscribeAddress(getPropertyString(mailinglistNode, "unsubscribe"));
    return Optional.of(mailinglist);
    } catch (RepositoryException e) {
        return Optional.empty();
    }

}
 
Example 4
Source File: JcrMetadataRepository.java    From archiva with Apache License 2.0 6 votes vote down vote up
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 5
Source File: RepositoryServiceImpl.java    From urule with Apache License 2.0 5 votes vote down vote up
@Override
public List<RepositoryFile> getDirectories(String project) throws Exception {
	Node rootNode=getRootNode();
	NodeIterator nodeIterator = rootNode.getNodes();
	Node targetProjectNode = null;
	while (nodeIterator.hasNext()) {
		Node projectNode = nodeIterator.nextNode();
		if (!projectNode.hasProperty(FILE)) {
			continue;
		}
		String projectName = projectNode.getName();
		if (project != null && !project.equals(projectName)) {
			continue;
		}
		targetProjectNode = projectNode;
		break;
	}
	if (targetProjectNode == null) {
		throw new RuleException("Project [" + project + "] not exist.");
	}
	List<RepositoryFile> fileList = new ArrayList<RepositoryFile>();
	RepositoryFile root = new RepositoryFile();
	root.setName("根目录");
	String projectPath = targetProjectNode.getPath();
	root.setFullPath(projectPath);
	fileList.add(root);
	NodeIterator projectNodeIterator = targetProjectNode.getNodes();
	while (projectNodeIterator.hasNext()) {
		Node dirNode = projectNodeIterator.nextNode();
		if (!dirNode.hasProperty(DIR_TAG)) {
			continue;
		}
		RepositoryFile file = new RepositoryFile();
		file.setName(dirNode.getPath().substring(projectPath.length()));
		file.setFullPath(dirNode.getPath());
		fileList.add(file);
		buildDirectories(dirNode, fileList, projectPath);
	}
	return fileList;
}
 
Example 6
Source File: RepositoryServiceImpl.java    From urule with Apache License 2.0 5 votes vote down vote up
private void lockCheck(Node node,User user) throws Exception{
	if(lockManager.isLocked(node.getPath())){
		String lockOwner=lockManager.getLock(node.getPath()).getLockOwner();
		if(lockOwner.equals(user.getUsername())){
			return;
		}
		throw new NodeLockException("【"+node.getName()+"】已被"+lockOwner+"锁定!");
	}
}
 
Example 7
Source File: AbstractArtifactHandler.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ImportInfo accept(Session session, Aggregate file,
                         ArtifactSet artifacts)
        throws RepositoryException, IOException {
    Node node = file.getNode();
    String name = node.getName();
    return accept(file.getManager().getWorkspaceFilter(),
            name.length() == 0 ? node : node.getParent(),
            name, (ArtifactSetImpl) artifacts);
}
 
Example 8
Source File: ChildNodeStash.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
/**
 * Moves the stashed nodes back below the given parent path.
 * @param parent the new parent node
 * @param importInfo the import info to record the changes
 * @throws RepositoryException if an error occurrs
 */
public void recoverChildren(Node parent, ImportInfo importInfo) throws RepositoryException {
    // move the old child nodes back
    if (tmpNode != null) {
        NodeIterator iter = tmpNode.getNodes();
        boolean hasErrors = false;
        while (iter.hasNext()) {
            Node child = iter.nextNode();
            String newPath = parent.getPath() + "/" + child.getName();
            try {
                if (session.nodeExists(newPath)) {
                    log.debug("Skipping restore from temporary location {} as node already exists at {}", child.getPath(), newPath);
                } else {
                    session.move(child.getPath(), newPath);
                }
            } catch (RepositoryException e) {
                log.warn("Unable to move child back to new location at {} due to: {}. Node will remain in temporary location: {}",
                        new Object[]{newPath, e.getMessage(), child.getPath()});
                if (importInfo != null) {
                    importInfo.onError(newPath, e);
                    hasErrors = true;
                }
            }
        }
        if (!hasErrors) {
            tmpNode.remove();
        }
    }
}
 
Example 9
Source File: JcrMetadataRepository.java    From archiva with Apache License 2.0 5 votes vote down vote up
private void recurse(List<String> facets, String prefix, Node node)
        throws RepositoryException {
    for (Node n : JcrUtils.getChildNodes(node)) {
        String name = prefix + "/" + n.getName();
        if (n.hasNodes()) {
            recurse(facets, name, n);
        } else {
            // strip leading / first
            facets.add(name.substring(1));
        }
    }
}
 
Example 10
Source File: JcrMetadataRepository.java    From archiva with Apache License 2.0 5 votes vote down vote up
private static Optional<License> getLicense(Node licenseNode) {
    try {
        String licenseName = licenseNode.getName();
        String licenseUrl = getPropertyString(licenseNode, "url");
        License license = new License();
        license.setName(licenseName);
        license.setUrl(licenseUrl);
        return Optional.of(license);
    } catch (RepositoryException e) {
        return Optional.empty();
    }
}
 
Example 11
Source File: JcrMetadataRepository.java    From archiva with Apache License 2.0 5 votes vote down vote up
private void retrieveFacetProperties(FacetedMetadata metadata, Node node) throws RepositoryException {
    for (Node n : JcrUtils.getChildNodes(node)) {
        if (n.isNodeType(FACET_NODE_TYPE)) {
            String name = n.getName();
            MetadataFacetFactory factory = metadataService.getFactory(name);
            if (factory == null) {
                log.error("Attempted to load unknown project version metadata facet: {}", name);
            } else {
                MetadataFacet facet = createFacetFromNode(factory, n);
                metadata.addFacet(facet);
            }
        }
    }
}
 
Example 12
Source File: StorageUpdate11.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
private void convertReports() throws RepositoryException {
	
	String statement = 
			"/jcr:root" + ISO9075.encodePath(StorageConstants.REPORTS_ROOT) + 
			"//*[@className='ro.nextreports.server.domain.Report' and @type='Next']" + 
			"//*[fn:name()='jcr:content' and @jcr:mimeType='text/xml']";
	  
	QueryResult queryResult = getTemplate().query(statement);

	NodeIterator nodes = queryResult.getNodes();
	LOG.info("Converter 5.1 : Found " + nodes.getSize() + " report nodes");
	while (nodes.hasNext()) {
		
		Node node = nodes.nextNode();
		
		Node reportNode = node.getParent().getParent().getParent().getParent();
		String reportName = reportNode.getName();
		String reportPath = reportNode.getPath();	
		LOG.info(" * Start convert '" + reportPath + "'");						
											
		Property prop = node.getProperty("jcr:data");			
       	String xml = null;
           try {                  	
           	xml = new Converter_5_2().convertFromInputStream(prop.getBinary().getStream(), true);            	            	
           	if (xml != null) {
               	ValueFactory valueFactory = node.getSession().getValueFactory(); 
               	Binary binaryValue = valueFactory.createBinary(new ByteArrayInputStream(xml.getBytes("UTF-8")));
               	node.setProperty ("jcr:data", binaryValue);                	
               	LOG.info("\t -> OK");
               } else {
               	LOG.error("\t -> FAILED : null xml");
               }
           	            	            	
           } catch (Throwable t) {                    	            	            
           	LOG.error("\t-> FAILED : " + t.getMessage(), t);            	
           } 					
           
	}
}
 
Example 13
Source File: RepositoryServiceImpl.java    From urule with Apache License 2.0 4 votes vote down vote up
@Override
public Repository loadRepository(String project,User user,boolean classify,FileType[] types,String searchFileName) throws Exception{
	String companyId=user.getCompanyId();
	createSecurityConfigFile(user);
	if(project!=null && project.startsWith("/")){
		project=project.substring(1,project.length());
	}
	Repository repo=new Repository();
	List<String> projectNames=new ArrayList<String>();
	repo.setProjectNames(projectNames);
	RepositoryFile rootFile = new RepositoryFile();
	rootFile.setFullPath("/");
	rootFile.setName("项目列表");
	rootFile.setType(Type.root);
	Node rootNode=getRootNode();
	NodeIterator nodeIterator = rootNode.getNodes();
	while (nodeIterator.hasNext()) {
		Node projectNode = nodeIterator.nextNode();
		if (!projectNode.hasProperty(FILE)) {
			continue;
		}
		if(StringUtils.isNotEmpty(companyId)){
			if(projectNode.hasProperty(COMPANY_ID)){
				String id=projectNode.getProperty(COMPANY_ID).getString();
				if(!companyId.equals(id)){
					continue;
				}
			}
		}
		String projectName = projectNode.getName();
		if(projectName.indexOf(RESOURCE_SECURITY_CONFIG_FILE)>-1){
			continue;
		}
		if (StringUtils.isNotBlank(project) && !project.equals(projectName)) {
			continue;
		}
		if(!permissionService.projectHasPermission(projectNode.getPath())){
			continue;
		}
		if(StringUtils.isBlank(project)){
			projectNames.add(projectName);
		}
		RepositoryFile projectFile=buildProjectFile(projectNode,types,classify,searchFileName);
		rootFile.addChild(projectFile, false);
	}
	repo.setRootFile(rootFile);
	return repo;
}
 
Example 14
Source File: ConfirmedOrdersObserver.java    From sling-samples with Apache License 2.0 4 votes vote down vote up
/** Meant to be called often (every second maybe) by the Sling scheduler */
public void run() {
    if(changedPropertyPaths.isEmpty()) {
        return;
    }
    
    final List<String> paths = new ArrayList<String>();
    final List<String> toRetry = new ArrayList<String>();
    synchronized (changedPropertyPaths) {
        paths.addAll(changedPropertyPaths);
        changedPropertyPaths.clear();
    }
    
    try {
        while(!paths.isEmpty()) {
            final String path = paths.remove(0);
            if(session.itemExists(path)) {
                final Item it = session.getItem(path);
                if(!it.isNode()) {
                    final Property p = (Property)it;
                    final Node n = p.getParent();
                    if(!n.hasProperty(SlingbucksConstants.LAST_MODIFIED_PROPERTY_NAME)) {
                        log.debug("Node {} doesn't have property {}, ignored", n.getPath(), SlingbucksConstants.LAST_MODIFIED_PROPERTY_NAME);
                    } else {
                        Calendar lastMod = n.getProperty(SlingbucksConstants.LAST_MODIFIED_PROPERTY_NAME).getDate();
                        if(System.currentTimeMillis() - lastMod.getTime().getTime() < WAIT_AFTER_LAST_CHANGE_MSEC) {
                            log.debug("Node {} modified more recently than {} msec, ignored", n.getPath(), WAIT_AFTER_LAST_CHANGE_MSEC);
                            toRetry.add(path);
                        } else {
                            final String targetPath = SlingbucksConstants.CONFIRMED_ORDERS_PATH + "/" + n.getName();
                            session.getWorkspace().move(n.getPath(), targetPath);
                            log.info("Confirmed order node {} moved to {}", n.getPath(), targetPath);
                        }
                    }
                }
            }
        }
    } catch(Exception e){
        log.error("Exception in run()", e);
    } finally {
        // Re-add any paths that we didn't process
        synchronized (changedPropertyPaths) {
            changedPropertyPaths.addAll(paths);
            changedPropertyPaths.addAll(toRetry);
        }
    }
}
 
Example 15
Source File: TreeSync.java    From jackrabbit-filevault with Apache License 2.0 4 votes vote down vote up
private Entry(Node parentNode, File parentDir, Node node) throws RepositoryException {
    this.parentNode = parentNode;
    this.node = node;
    this.jcrName = node.getName();
    this.file = new File(parentDir, PlatformNameFormat.getPlatformName(jcrName));
}
 
Example 16
Source File: JcrMetadataRepository.java    From archiva with Apache License 2.0 4 votes vote down vote up
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;
}