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


Java Session类代码示例

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


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

示例1: hasNodePropertyValue

import javax.jcr.Session; //导入依赖的package包/类
/**
 * Checks if specified node property has specified value
 *
 * @param session       Jcr session.
 * @param nodePath      Absolute path to node.
 * @param propertyName  Property name.
 * @param propertyValue Property value.
 * @return True if node property has specified value.
 */
public static ExpectedCondition<Boolean> hasNodePropertyValue(final Session session,
    final String nodePath, final String propertyName, final String propertyValue) {
  LOG.debug("Checking if node '{}' has property '{}' with value '{}'", nodePath, propertyName,
      propertyValue);
  return input -> {
    Boolean result = null;
    try {
      session.refresh(true);
      result = session.getNode(nodePath).getProperty(propertyName).getValue().getString()
          .equals(propertyValue);
    } catch (RepositoryException e) {
      LOG.error(JCR_ERROR, e);
    }
    return result;
  };
}
 
开发者ID:Cognifide,项目名称:bobcat,代码行数:26,代码来源:JcrExpectedConditions.java

示例2: queryJcrContent

import javax.jcr.Session; //导入依赖的package包/类
String queryJcrContent(Session session) throws RepositoryException {

    // get query manager
    QueryManager queryManager = session.getWorkspace().getQueryManager();

    // query for all nodes with tag "JCR"
    Query query = queryManager.createQuery("/jcr:root/content/adaptto//*[tags='JCR']", Query.XPATH);

    // iterate over results
    QueryResult result = query.execute();
    NodeIterator nodes = result.getNodes();
    StringBuilder output = new StringBuilder();
    while (nodes.hasNext()) {
      Node node = nodes.nextNode();
      output.append("path=" + node.getPath() + "\n");
    }

    return output.toString();
  }
 
开发者ID:adaptto,项目名称:2015-sling-rookie-session,代码行数:20,代码来源:JcrQuerySample.java

示例3: testReadNode

import javax.jcr.Session; //导入依赖的package包/类
/** Create a node via Sling's http interface and verify that admin can
 *  read it via davex remote access.
 */
public void testReadNode() throws Exception {
    final String path = "/DavExNodeTest_1_" + System.currentTimeMillis();
    final String url = HTTP_BASE_URL + path;

    // add some properties to the node
    final Map<String, String> props = new HashMap<String, String>();
    props.put("name1", "value1");
    props.put("name2", "value2");

    testClient.createNode(url, props);

    // Oak does not support login without credentials, so to
    // verify that davex access works we do need valid repository credentials.
    final Credentials creds = new SimpleCredentials("admin", "admin".toCharArray());
    Session session = repository.login(creds);

    try {
        final Node node = session.getNode(path);
        assertNotNull(node);
        assertEquals("value1", node.getProperty("name1").getString());
        assertEquals("value2", node.getProperty("name2").getString());
    } finally {
        session.logout();
    }
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:29,代码来源:DavExIntegrationTest.java

示例4: runScript

import javax.jcr.Session; //导入依赖的package包/类
protected void runScript(ResourceResolver resourceResolver, Session session, OnDeployScript script) {
    String statusNodePath = "/var/on-deploy-scripts-status/" + script.getClass().getName();
    Node statusNode = getOrCreateStatusTrackingNode(session, statusNodePath);
    String status = getScriptStatus(resourceResolver, statusNode, statusNodePath);
    if (status == null || status.equals("fail")) {
        trackScriptStart(session, statusNode, statusNodePath);
        try {
            script.execute(resourceResolver, queryBuilder);
            logger.info("On-deploy script completed successfully: {}", statusNodePath);
            trackScriptEnd(session, statusNode, statusNodePath, "success");
        } catch (Exception e) {
            logger.error("On-deploy script failed: {}", statusNodePath, e);
            trackScriptEnd(session, statusNode, statusNodePath, "fail");
        }
    } else if (!status.equals("success")) {
        logger.warn("Skipping on-deploy script as it may already be in progress: {} - status: {}", statusNodePath, status);
    } else {
        logger.debug("Skipping on-deploy script, as it is already complete: {}", statusNodePath);
    }
}
 
开发者ID:HS2-SOLUTIONS,项目名称:hs2-aem-commons,代码行数:21,代码来源:OnDeployExecutorImpl.java

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: setUp

import javax.jcr.Session; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
    super.setUp();

    Session session = openSession();
    Node node = session.getRootNode().addNode("home").addNode("test");
    node.setProperty("content.approved", APPROVED);
    node.setProperty("my.contents.property", CONTENT);
    
    
    ValueFactory valFact = session.getValueFactory();
    Value[] vals = new Value[] {valFact.createValue("value-1"), valFact.createValue("value-2")};
    node.setProperty("my.multi.valued", vals);
    
    identifier = node.getIdentifier();

    session.save();
    session.logout();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:JcrGetNodeByIdTest.java

示例12: execute

import javax.jcr.Session; //导入依赖的package包/类
@Override
public void execute(final InstallContext installContext) throws TaskExecutionException {
    try {
        final Session session = MgnlContext.getJCRSession(NewsRepositoryConstants.COLLABORATION);

        final Node rootNode = session.getRootNode();
        final int numberOfMovedNodes = processNewsItems(installContext, rootNode, 0);

        if (numberOfMovedNodes > 0) {
            installContext.info("Nested news items were found and have been un-nested.");
            installContext.info("Note: If present, duplicate news items now have a name that ends with '-duplicate'.");
            installContext.info("Please check all news items and re-publish if needed.");
        }
    } catch (RepositoryException e) {
        throw new TaskExecutionException("Error while un-nesting event nodes", e);
    }
}
 
开发者ID:tricode,项目名称:magnolia-news,代码行数:18,代码来源:FindAndMoveNestedNewsTask.java

示例13: six

import javax.jcr.Session; //导入依赖的package包/类
public void six() {
	Session session = null; // Noncompliant
	String plotTwist = "twist";
	plotTwist = "anotherTwist";
	plotTwist = getMeAnotherTwist();
	plotTwist = StringUtils.capitalize(plotTwist);
	try {
		session = repository.loginService(null, null);
	} catch (RepositoryException e) {
		e.printStackTrace();
	} finally {
		if (session != null && session.isLive()) {
			//	session.logout();
			plotTwist.toString();
		}
	}
}
 
开发者ID:Cognifide,项目名称:AEM-Rules-for-SonarQube,代码行数:18,代码来源:SessionLogoutSix.java

示例14: reprocessNotification

import javax.jcr.Session; //导入依赖的package包/类
public void reprocessNotification(CardNotification cardNotification, String type) throws Exception {
	ObjectContentManager ocm = ocmFactory.getOcm();
	try {

		final Session session = ocm.getSession();			
		final String source = cardNotification.getPath();
		final String destination = String.format(URI.NOTIFICATIONS_TYPE_ID_URI, type, cardNotification.getId());
		
		session.move(source, destination);
		ocm.save();
		this.jmsTemplate.convertAndSend(cardNotification);
		
		LOG.info("Successfully Moved Notification id:'" + 
				cardNotification.getId() + "' type:'" + 
				type + "' for reprocessing.");
		
	} finally {
		ocm.logout();
	}
}
 
开发者ID:cheetah100,项目名称:gravity,代码行数:21,代码来源:NotificationController.java

示例15: testExpandMultivalue

import javax.jcr.Session; //导入依赖的package包/类
/**
 * jsonfn.from(content).expand("baz", "category").print()
 *
 * ==> { "foo" : "hahaha", "baz" : {"identifier" : "1234-123456-1234", "name" : "cat1"}, b: 1234, "bar" : "meh", ... }
 */
@Test
public void testExpandMultivalue() throws Exception {
    // GIVEN
    Node node = session.getNode("/home/section2/article/mgnl:apex");
    Session catSession = catNode.getSession();
    catSession.getWorkspace().copy(catNode.getPath(), "/othercat");
    catSession.save();
    Node catNode2 = catSession.getNode("/othercat");
    node.setProperty("baz", new String[] { catNode.getIdentifier(), catNode2.getIdentifier() });
    node.save();
    // WHEN
    String json = JsonTemplatingFunctions.from(node).expand("baz", "category").add("@id").print();
    // THEN
    assertThat(json, startsWith("{"));
    // [{ == array of props ;)
    assertThat(json, containsString("\"baz\" : [ {"));
    assertThat(json, containsString("" + catNode.getIdentifier()));
    assertThat(json, containsString("" + catNode2.getIdentifier()));
    assertThat(json, endsWith("}"));
}
 
开发者ID:rah003,项目名称:neat-jsonfn,代码行数:26,代码来源:JsonBuilderTest.java


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