当前位置: 首页>>代码示例>>Java>>正文


Java JcrUtils类代码示例

本文整理汇总了Java中org.apache.jackrabbit.commons.JcrUtils的典型用法代码示例。如果您正苦于以下问题:Java JcrUtils类的具体用法?Java JcrUtils怎么用?Java JcrUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JcrUtils类属于org.apache.jackrabbit.commons包,在下文中一共展示了JcrUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPageByVersion

import org.apache.jackrabbit.commons.JcrUtils; //导入依赖的package包/类
@Override
public Page getPageByVersion(final String path, final String versionName) {
    return jcrTemplate.execute(session -> {
        Node rootNode = session.getRootNode();
        Node node = JcrUtils.getNodeIfExists(rootNode, path);
        if (node != null) {
            VersionManager vm = session.getWorkspace().getVersionManager();
            VersionHistory history = vm.getVersionHistory("/" + path);
            Version version = history.getVersion(versionName);
            if (version != null) {
                Node frozenNode = version.getFrozenNode();
                return convertNodeToPage(frozenNode);
            } else {
                return null;
            }
        } else {
            return null;
        }
    });
}
 
开发者ID:MyCollab,项目名称:mycollab,代码行数:21,代码来源:PageServiceImpl.java

示例2: recurse

import org.apache.jackrabbit.commons.JcrUtils; //导入依赖的package包/类
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 ) );
        }
    }
}
 
开发者ID:ruikom,项目名称:apache-archiva,代码行数:18,代码来源:JcrMetadataRepository.java

示例3: addMetadataFacet

import org.apache.jackrabbit.commons.JcrUtils; //导入依赖的package包/类
@Override
public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet )
    throws MetadataRepositoryException
{
    try
    {
        Node repo = getOrAddRepositoryNode( repositoryId );
        Node facets = JcrUtils.getOrAddNode( repo, "facets" );

        String id = metadataFacet.getFacetId();
        Node facetNode = JcrUtils.getOrAddNode( facets, id );

        Node node = getOrAddNodeByPath( facetNode, metadataFacet.getName() );

        for ( Map.Entry<String, String> entry : metadataFacet.toProperties().entrySet() )
        {
            node.setProperty( entry.getKey(), entry.getValue() );
        }
    }
    catch ( RepositoryException e )
    {
        throw new MetadataRepositoryException( e.getMessage(), e );
    }
}
 
开发者ID:ruikom,项目名称:apache-archiva,代码行数:25,代码来源:JcrMetadataRepository.java

示例4: removeProjectVersion

import org.apache.jackrabbit.commons.JcrUtils; //导入依赖的package包/类
@Override
public void removeProjectVersion( String repoId, String namespace, String projectId, String projectVersion )
    throws MetadataRepositoryException
{
    try
    {

        String path = getProjectPath( repoId, namespace, projectId );
        Node root = getJcrSession().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 );
    }
}
 
开发者ID:ruikom,项目名称:apache-archiva,代码行数:27,代码来源:JcrMetadataRepository.java

示例5: getPage

import org.apache.jackrabbit.commons.JcrUtils; //导入依赖的package包/类
@Override
public Page getPage(final String path, final String requestedUser) {
    return jcrTemplate.execute(session -> {
        Node rootNode = session.getRootNode();
        Node node = JcrUtils.getNodeIfExists(rootNode, path);
        if (node != null) {
            if (isNodePage(node)) {
                if (isAccessible(node, requestedUser)) {
                    return convertNodeToPage(node);
                } else {
                    return null;
                }
            }
        }

        return null;
    });
}
 
开发者ID:MyCollab,项目名称:mycollab,代码行数:19,代码来源:PageServiceImpl.java

示例6: getPageVersions

import org.apache.jackrabbit.commons.JcrUtils; //导入依赖的package包/类
@Override
public List<PageVersion> getPageVersions(final String path) {
    return jcrTemplate.execute(session -> {
        Node rootNode = session.getRootNode();
        Node node = JcrUtils.getNodeIfExists(rootNode, path);
        if (node != null) {
            VersionManager vm = session.getWorkspace().getVersionManager();
            VersionHistory history = vm.getVersionHistory("/" + path);
            List<PageVersion> versions = new ArrayList<>();
            for (VersionIterator it = history.getAllVersions(); it.hasNext(); ) {
                Version version = (Version) it.next();
                if (!"jcr:rootVersion".equals(version.getName())) {
                    versions.add(convertNodeToPageVersion(version));
                }
            }
            return versions;
        } else {
            return null;
        }
    });
}
 
开发者ID:MyCollab,项目名称:mycollab,代码行数:22,代码来源:PageServiceImpl.java

示例7: restorePage

import org.apache.jackrabbit.commons.JcrUtils; //导入依赖的package包/类
@Override
public Page restorePage(final String path, final String versionName) {
    return jcrTemplate.execute(session -> {
        Node rootNode = session.getRootNode();
        Node node = JcrUtils.getNodeIfExists(rootNode, path);
        if (node != null) {
            VersionManager vm = session.getWorkspace().getVersionManager();
            try {
                vm.restore("/" + path, versionName, true);
                node = JcrUtils.getNodeIfExists(rootNode, path);
                return convertNodeToPage(node);
            } catch (Exception e) {
                LOG.error("Error when restore document {} to version {}", path, versionName, e);
            }
        }
        return null;
    });

}
 
开发者ID:MyCollab,项目名称:mycollab,代码行数:20,代码来源:PageServiceImpl.java

示例8: createEmptyCache

import org.apache.jackrabbit.commons.JcrUtils; //导入依赖的package包/类
private Node createEmptyCache(HtmlLibrary library, String root, Session session)  {
	Node node = null;
	// this.lock.writeLock().lock();
	try {
		Node swap = JcrUtils.getOrCreateByPath(root, 
				JcrResourceConstants.NT_SLING_FOLDER, 
				JcrResourceConstants.NT_SLING_FOLDER, 
				session, true);
		node = swap.addNode(getLibraryName(library), JcrConstants.NT_FILE);
		swap = node.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
		swap.setProperty(JcrConstants.JCR_LASTMODIFIED, 0L);
		swap.setProperty(JcrConstants.JCR_MIMETYPE, library.getType().contentType);
		swap.setProperty(JcrConstants.JCR_DATA, 
				session.getValueFactory().createBinary(new ByteArrayInputStream(new byte[0])));
		session.save();
		// this.lock.writeLock().unlock();
	} catch(RepositoryException re) {
		log.debug(re.getMessage());
	}
	return node;
}
 
开发者ID:steeleforge,项目名称:aemin,代码行数:22,代码来源:HtmlLibraryManagerDelegateImpl.java

示例9: setUp

import org.apache.jackrabbit.commons.JcrUtils; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    predicateParams = new HashMap<String, String>();

    session = MockJcr.newSession();

    node = JcrUtils.getOrCreateByPath("/content/asset.pdf", JcrConstants.NT_UNSTRUCTURED, session);

    JcrUtils.getOrCreateByPath("/content/asset.pdf/jcr:content/renditions/rendition-1", JcrConstants.NT_UNSTRUCTURED, session);
    JcrUtils.getOrCreateByPath("/content/asset.pdf/jcr:content/renditions/rendition-2", JcrConstants.NT_UNSTRUCTURED, session);
    JcrUtils.getOrCreateByPath("/content/asset.pdf/jcr:content/renditions/rendition-3", JcrConstants.NT_UNSTRUCTURED, session);
    JcrUtils.getOrCreateByPath("/content/asset.pdf/jcr:content/renditions/rendition-4", JcrConstants.NT_UNSTRUCTURED, session);
    JcrUtils.getOrCreateByPath("/content/asset.pdf/jcr:content/renditions/rendition-5", JcrConstants.NT_UNSTRUCTURED, session);

    when(row.getNode()).thenReturn(node);
    when(predicate.getParameters()).thenReturn(predicateParams);
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:18,代码来源:NodeExistsPredicateEvaluatorTest.java

示例10: testImportToFolderHavingFileWhichIsOlder

import org.apache.jackrabbit.commons.JcrUtils; //导入依赖的package包/类
@Test
public void testImportToFolderHavingFileWhichIsOlder() throws Exception {
    Calendar earliest = Calendar.getInstance();
    earliest.setTimeInMillis(0L);
    Node file = JcrUtils.putFile(folder, testFile.getName(), "x-text/test", new ByteArrayInputStream("".getBytes()),
            earliest);

    session.save();
    
    Resource resource = mock(Resource.class);
    when(resource.adaptTo(Node.class)).thenReturn(folder);
    importer.importData("file", testFile.getAbsolutePath(), resource);

    assertFalse(session.hasPendingChanges());
    assertTrue(folder.hasNode(testFile.getName()));
    assertEquals("text/plain", JcrUtils.getStringProperty(file, "jcr:content/jcr:mimeType", ""));
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:18,代码来源:FileImporterTest.java

示例11: testImportToFolderHavingFileWhichIsNewer

import org.apache.jackrabbit.commons.JcrUtils; //导入依赖的package包/类
@Test
public void testImportToFolderHavingFileWhichIsNewer() throws Exception {
    Calendar latest = Calendar.getInstance();
    latest.add(Calendar.DATE, 2);
    Node file = JcrUtils.putFile(folder, testFile.getName(), "x-text/test", new ByteArrayInputStream("".getBytes()),
            latest);

    session.save();
    
    Resource resource = mock(Resource.class);
    when(resource.adaptTo(Node.class)).thenReturn(folder);
    importer.importData("file", testFile.getAbsolutePath(), resource);

    assertFalse(session.hasPendingChanges());
    assertTrue(folder.hasNode(testFile.getName()));

    // this verifies the the file wasn't imported
    assertEquals("x-text/test", JcrUtils.getStringProperty(file, "jcr:content/jcr:mimeType", ""));
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:20,代码来源:FileImporterTest.java

示例12: testImportToFile

import org.apache.jackrabbit.commons.JcrUtils; //导入依赖的package包/类
@Test
public void testImportToFile() throws Exception {
    Calendar earliest = Calendar.getInstance();
    earliest.setTimeInMillis(0L);
    Node file = JcrUtils.putFile(folder, "test.txt", "x-text/test", new ByteArrayInputStream("".getBytes()),
            earliest);

    session.save();

    Resource resource = mock(Resource.class);
    when(resource.adaptTo(Node.class)).thenReturn(file);
    importer.importData("file", testFile.getAbsolutePath(), resource);

    assertFalse(session.hasPendingChanges());
    assertFalse(folder.hasNode(testFile.getName()));
    assertEquals("text/plain", JcrUtils.getStringProperty(file, "jcr:content/jcr:mimeType", ""));
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:18,代码来源:FileImporterTest.java

示例13: testImportToFileWhichIsNewer

import org.apache.jackrabbit.commons.JcrUtils; //导入依赖的package包/类
@Test
public void testImportToFileWhichIsNewer() throws Exception {
    Calendar latest = Calendar.getInstance();
    latest.add(Calendar.DATE, 2);
    Node file = JcrUtils
            .putFile(folder, "test.txt", "x-text/test", new ByteArrayInputStream("".getBytes()), latest);

    session.save();

    Resource resource = mock(Resource.class);
    when(resource.adaptTo(Node.class)).thenReturn(file);
    importer.importData("file", testFile.getAbsolutePath(), resource);

    assertFalse(session.hasPendingChanges());
    assertFalse(folder.hasNode(testFile.getName()));

    // this verifies the the file wasn't imported
    assertEquals("x-text/test", JcrUtils.getStringProperty(file, "jcr:content/jcr:mimeType", ""));
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:20,代码来源:FileImporterTest.java

示例14: lastModified

import org.apache.jackrabbit.commons.JcrUtils; //导入依赖的package包/类
@Override
public long lastModified() {
    try {
        return JcrUtils.getLastModified(resource.adaptTo(Node.class)).getTimeInMillis();
    } catch (RepositoryException ew) {
        return Calendar.getInstance().getTimeInMillis();
    }
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:9,代码来源:HTMLResourceBasedTemplateLoader.java

示例15: removeProject

import org.apache.jackrabbit.commons.JcrUtils; //导入依赖的package包/类
@Override
public void removeProject( String repositoryId, String namespace, String projectId )
    throws MetadataRepositoryException
{
    try
    {
        Node root = getJcrSession().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( PROJECT_NODE_TYPE ) && projectId.equals( node.getName() ) )
                {
                    node.remove();
                }
            }

        }
    }
    catch ( RepositoryException e )
    {
        throw new MetadataRepositoryException( e.getMessage(), e );
    }

}
 
开发者ID:ruikom,项目名称:apache-archiva,代码行数:30,代码来源:JcrMetadataRepository.java


注:本文中的org.apache.jackrabbit.commons.JcrUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。