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


Java Session.getNodeByIdentifier方法代码示例

本文整理汇总了Java中javax.jcr.Session.getNodeByIdentifier方法的典型用法代码示例。如果您正苦于以下问题:Java Session.getNodeByIdentifier方法的具体用法?Java Session.getNodeByIdentifier怎么用?Java Session.getNodeByIdentifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.jcr.Session的用法示例。


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

示例1: testJcrProducer

import javax.jcr.Session; //导入方法依赖的package包/类
@Test
public void testJcrProducer() throws Exception {
    Exchange exchange = createExchangeWithBody("<hello>world!</hello>");
    exchange.getIn().setHeader(JcrConstants.JCR_NODE_NAME, "node");
    exchange.getIn().setHeader("my.contents.property", exchange.getIn().getBody());
    Exchange out = template.send("direct:a", exchange);
    assertNotNull(out);
    String uuid = out.getOut().getBody(String.class);
    Session session = openSession();
    try {
        Node node = session.getNodeByIdentifier(uuid);
        assertNotNull(node);
        assertEquals("/home/test/node", node.getPath());
        assertEquals("<hello>world!</hello>", node.getProperty("my.contents.property").getString());
    } finally {
        if (session != null && session.isLive()) {
            session.logout();
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:JcrProducerTest.java

示例2: testNodeTypeIsSpecified

import javax.jcr.Session; //导入方法依赖的package包/类
@Test
public void testNodeTypeIsSpecified() throws Exception {
    Exchange exchange = createExchangeWithBody("Test");
    exchange.getIn().removeHeader("testClass"); //there is no definition of such property in nt:resource
    exchange.getIn().setHeader(JcrConstants.JCR_NODE_NAME, "typedNode");
    exchange.getIn().setHeader(JcrConstants.JCR_NODE_TYPE, "nt:folder");
    Exchange out = template.send("direct:a", exchange);
    assertNotNull(out);
    String uuid = out.getOut().getBody(String.class);
    Session session = openSession();
    try {
        Node node = session.getNodeByIdentifier(uuid);
        assertNotNull(node);
        assertEquals("/home/test/typedNode", node.getPath());
        assertEquals("nt:folder", node.getPrimaryNodeType().getName());
    } finally {
        if (session != null && session.isLive()) {
            session.logout();
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:JcrProducerTest.java

示例3: testCreateNodeWithAuthentication

import javax.jcr.Session; //导入方法依赖的package包/类
@Test
public void testCreateNodeWithAuthentication() throws Exception {
    Exchange exchange = createExchangeWithBody("<message>hello!</message>");
    Exchange out = template.send("direct:a", exchange);
    assertNotNull(out);
    String uuid = out.getOut().getBody(String.class);
    assertNotNull("Out body was null; expected JCR node UUID", uuid);
    Session session = getRepository().login(
            new SimpleCredentials("admin", "admin".toCharArray()));
    try {
        Node node = session.getNodeByIdentifier(uuid);
        assertNotNull(node);
        assertEquals(BASE_REPO_PATH + "/node", node.getPath());
    } finally {
        if (session != null && session.isLive()) {
            session.logout();
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:JcrAuthLoginTest.java

示例4: testJcrNodePathCreation

import javax.jcr.Session; //导入方法依赖的package包/类
@Test
public void testJcrNodePathCreation() throws Exception {
    Exchange exchange = createExchangeWithBody("<body/>");
    Exchange out = template.send("direct:a", exchange);
    assertNotNull(out);
    String uuid = out.getOut().getBody(String.class);
    assertNotNull("Out body was null; expected JCR node UUID", uuid);
    Session session = openSession();
    try {
        Node node = session.getNodeByIdentifier(uuid);
        assertNotNull(node);
        assertEquals("/home/test/node/with/path", node.getPath());
    } finally {
        if (session != null && session.isLive()) {
            session.logout();
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:JcrNodePathCreationTest.java

示例5: testJcrNodePathCreationMultiValued

import javax.jcr.Session; //导入方法依赖的package包/类
@Test
public void testJcrNodePathCreationMultiValued() throws Exception {
    Exchange exchange = createExchangeWithBody(multiValued);
    Exchange out = template.send("direct:a", exchange);
    assertNotNull(out);
    String uuid = out.getOut().getBody(String.class);
    assertNotNull("Out body was null; expected JCR node UUID", uuid);
    Session session = openSession();
    try {
        Node node = session.getNodeByIdentifier(uuid);
        assertNotNull(node);
        assertEquals("/home/test/node/with/path", node.getPath());
        assertTrue(node.getProperty("my.contents.property").isMultiple());
        assertArrayEquals(multiValued, node.getProperty("my.contents.property").getValues());
    } finally {
        if (session != null && session.isLive()) {
            session.logout();
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:JcrNodePathCreationTest.java

示例6: testJcrProducer

import javax.jcr.Session; //导入方法依赖的package包/类
@Test
public void testJcrProducer() throws Exception {
    Exchange exchange = createExchangeWithBody("<hello>world!</hello>");
    Exchange out = template.send("direct:a", exchange);
    assertNotNull(out);
    String uuid = out.getOut().getBody(String.class);
    Session session = openSession(CUSTOM_WORKSPACE_NAME);
    try {
        Node node = session.getNodeByIdentifier(uuid);
        Workspace workspace = session.getWorkspace();
        assertEquals(CUSTOM_WORKSPACE_NAME, workspace.getName());
        assertNotNull(node);
        assertEquals("/home/test/node", node.getPath());
        assertEquals("<hello>world!</hello>", node.getProperty("my.contents.property").getString());
    } finally {
        if (session != null && session.isLive()) {
            session.logout();
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:JcrProducerDifferentWorkspaceTest.java

示例7: deleteComment

import javax.jcr.Session; //导入方法依赖的package包/类
/**
 * Delete comment by setting it's display property to false.
 *
 * @param request The current request to get session and Resource Resolver
 * @param id The comment UUID
 * @return true if the operation was successful
 */
public boolean deleteComment(final SlingHttpServletRequest request, final String id) {
    boolean result = false;

    try {
        Session session = request.getResourceResolver().adaptTo(Session.class); 
        Node node = session.getNodeByIdentifier(id);

        if (node != null) {
            JcrResourceUtil.setProperty(node, PublickConstants.COMMENT_PROPERTY_DISPLAY, false);
            session.save();
            result = true;
        }
    } catch (RepositoryException e) {
        LOGGER.error("Could not delete comment from JCR", e);
    }

    return result;
}
 
开发者ID:nateyolles,项目名称:publick-sling-blog,代码行数:26,代码来源:CommentServiceImpl.java

示例8: editComment

import javax.jcr.Session; //导入方法依赖的package包/类
/**
 * Edit comment and mark it as author edited.
 *
 * @param request The current request to get session and Resource Resolver
 * @param id The comment UUID
 * @param text The comment text
 * @return true if the operation was successful
 */
public boolean editComment(final SlingHttpServletRequest request, final String id, String text) {
    boolean result = false;

    try {
        Session session = request.getResourceResolver().adaptTo(Session.class);
        Node node = session.getNodeByIdentifier(id);

        if (node != null) {
            JcrResourceUtil.setProperty(node, PublickConstants.COMMENT_PROPERTY_COMMENT, text);
            JcrResourceUtil.setProperty(node, PublickConstants.COMMENT_PROPERTY_EDITED, true);
            session.save();
            result = true;
        }
    } catch (RepositoryException e) {
        LOGGER.error("Could not update comment from JCR", e);
    }

    return result;
}
 
开发者ID:nateyolles,项目名称:publick-sling-blog,代码行数:28,代码来源:CommentServiceImpl.java

示例9: markAsSpam

import javax.jcr.Session; //导入方法依赖的package包/类
/**
 * Mark comment as spam, submit it to Akismet and delete it by setting
 * it's display property to false.
 *
 * @param request The current request to get session and Resource Resolver
 * @param id The comment UUID
 * @return true if the operation was successful
 */
public boolean markAsSpam(final SlingHttpServletRequest request, final String id) {
    boolean result = false;

    try {
        final ResourceResolver resolver = request.getResourceResolver();
        final Session session = resolver.adaptTo(Session.class);
        final Node node = session.getNodeByIdentifier(id);

        if (node != null) {
            final Resource resource = resolver.getResource(node.getPath());
            result = akismetService.submitSpam(resource);
        }
    } catch (RepositoryException e) {
        LOGGER.error("Could not submit spam.", e);
    }

    return result;
}
 
开发者ID:nateyolles,项目名称:publick-sling-blog,代码行数:27,代码来源:CommentServiceImpl.java

示例10: markAsHam

import javax.jcr.Session; //导入方法依赖的package包/类
/**
 * Mark comment as ham, submit it to Akismet and mark it valid it by setting
 * it's display property to true.
 *
 * @param request The current request to get session and Resource Resolver
 * @param id The comment UUID
 * @return true if the operation was successful
 */
public boolean markAsHam(final SlingHttpServletRequest request, final String id) {
    boolean result = false;

    try {
        final ResourceResolver resolver = request.getResourceResolver();
        final Session session = resolver.adaptTo(Session.class);
        final Node node = session.getNodeByIdentifier(id);

        if (node != null) {
            final Resource resource = resolver.getResource(node.getPath());
            result = akismetService.submitHam(resource);
        }
    } catch (RepositoryException e) {
        LOGGER.error("Could not submit ham.", e);
    }

    return result;
}
 
开发者ID:nateyolles,项目名称:publick-sling-blog,代码行数:27,代码来源:CommentServiceImpl.java

示例11: getResourceNodePath

import javax.jcr.Session; //导入方法依赖的package包/类
/**
 * Get resource node path by session and uuid
 *
 * @param session The session used to get resource node path
 * @param resourceNodeUUID The uuid used to get resource node path
 * @param renderContext A renderContext object
 * @param resource A resource object
 * @return resourceNodePath
 * @throws RepositoryException
 */
public static String getResourceNodePath(final Session session,
                                         final String resourceNodeUUID,
                                         final RenderContext renderContext,
                                         final Resource resource)
        throws RepositoryException {
    String resourcePath = "";
    if (StringUtils.isNotEmpty(resourceNodeUUID)) {

        Node n = session.getNodeByIdentifier(resourceNodeUUID);
        try {
            URLGenerator urlGenerator = new URLGenerator(renderContext, resource);
            String base = urlGenerator.getBase();
            String nodeType = n.getPrimaryNodeType().getName();
            if(nodeType.equals(JAHIA_JNT_PAGE)) {
                resourcePath = base + n.getPath() + HTML_EXT;
            } else {
                resourcePath = ( (JCRNodeWrapper) n).getUrl();
            }

        } catch (Exception e){
            log.error("Error casting Node: " + n + " to JCRNodeWrapper, using path only", e);
            resourcePath = n.getPath();
        }
    }

    return resourcePath;
}
 
开发者ID:DantaFramework,项目名称:JahiaDF,代码行数:38,代码来源:ResourceUtils.java

示例12: testCreateNodeAndSubNode

import javax.jcr.Session; //导入方法依赖的package包/类
@Test
public void testCreateNodeAndSubNode() throws Exception {
    Session session = openSession();

    try {
        // create node
        Exchange exchange1 = ExchangeBuilder.anExchange(context)
            .withHeader(JcrConstants.JCR_NODE_NAME, "node")
            .build();
        Exchange out1 = template.send("direct:a", exchange1);
        assertNotNull(out1);
        String uuidNode = out1.getOut().getBody(String.class);

        Node node = session.getNodeByIdentifier(uuidNode);
        assertNotNull(node);
        assertEquals("/home/test/node", node.getPath());
        
        // create sub node
        Exchange exchange2 = ExchangeBuilder.anExchange(context)
            .withHeader(JcrConstants.JCR_NODE_NAME, "node/subnode")
            .build();
        Exchange out2 = template.send("direct:a", exchange2);
        assertNotNull(out2);
        String uuidSubNode = out2.getOut().getBody(String.class);
        
        Node subNode = session.getNodeByIdentifier(uuidSubNode);
        assertNotNull(subNode);
        assertEquals("/home/test/node/subnode", subNode.getPath());
        assertNotNull(subNode.getParent());
        assertEquals("/home/test/node", subNode.getParent().getPath());
    } finally {
        if (session != null && session.isLive()) {
            session.logout();
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:37,代码来源:JcrProducerSubNodeTest.java

示例13: expandSingle

import javax.jcr.Session; //导入方法依赖的package包/类
private Object expandSingle(String expandable, String workspace, String expandableProperty, String targetName) {
    if (expandable == null) {
        return null;
    }
    Node expandedNode;
    try {
        if (targetName.equals("jcr:uuid")) {
            Session session = MgnlContext.getJCRSession(workspace);
            if (expandable.startsWith("jcr:")) {
                expandable = StringUtils.removeStart(expandable, "jcr:");
            }
            if (expandable.startsWith("/")) {
                expandedNode = session.getNode(expandable);
            } else {
                expandedNode = session.getNodeByIdentifier(expandable);
            }
            if (config.allowDeleted || isNotDeleted(expandedNode)) {
                return mapToECMap(expandedNode, expandableProperty, config);
            } else {
                return null;
            }
        } else {
            String statement = "select * from [nt:base] where contains(" + escapeForQuery(targetName) + ",'" + escapeForQuery(expandable) + "')";
            NodeIterator results = QueryUtil.search(workspace, statement);

            return asNodeStream(results)
                    .filter(node -> config.allowDeleted || isNotDeleted(node))
                    .map(expanded -> mapToECMap(expanded, expandableProperty, config))
                    .collect(Collectors.toList());
        }
    } catch (RepositoryException e) {
        log.debug(e.getMessage(), e);
        return null;
    }
}
 
开发者ID:rah003,项目名称:neat-jsonfn,代码行数:36,代码来源:JsonBuilder.java


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