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


Java Session.getNode方法代码示例

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


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

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

示例2: readJcrContent

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

    // get node directly
    Node day1 = session.getNode("/content/adaptto/2013/day1");

    // get first child node
    Node firstTalk = day1.getNodes().nextNode();

    // read property values
    String title = firstTalk.getProperty("jcr:title").getString();
    long duration = firstTalk.getProperty("durationMin").getLong();

    // read multi-valued property
    Value[] tagValues = firstTalk.getProperty("tags").getValues();
    String[] tags = new String[tagValues.length];
    for (int i=0; i<tagValues.length; i++) {
      tags[i] = tagValues[i].getString();
    }

    return "First talk: " + title + " (" + duration + " min)\n"
        + "Tags: " + Arrays.toString(tags) + "\n"
        + "Path: " + firstTalk.getPath();
  }
 
开发者ID:adaptto,项目名称:2015-sling-rookie-session,代码行数:24,代码来源:JcrReadSample.java

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

示例4: testPrintDoubleQuoted2

import javax.jcr.Session; //导入方法依赖的package包/类
/**
 * jsonfn.from(content).add(".*").inline().print()
 *
 * ==> { "foo" : "that\\'s it", ... }
 */
@Test
public void testPrintDoubleQuoted2() throws Exception {
    // GIVEN
    Session session = MgnlContext.getInstance().getJCRSession("website");
    Node node = session.getNode("/home/section2/article/mgnl:apex");
    node.setProperty("description",
            "<p><span style=\"line-height:1.6em\">l&auml;ngsten produzierten Profikameras &uuml;berhaupt.</span></p><p><span style=\"line-height:1.6em\">Mit der F3 !</span></p>");
    // WHEN
    String json = JsonTemplatingFunctions.from(node).add("description").inline().print();
    // THEN
    assertThat(json, startsWith("{"));
    assertThat(json, containsString(
            "\"description\":\"<p><span style=\\\"line-height:1.6em\\\">l&auml;ngsten produzierten Profikameras &uuml;berhaupt.</span></p><p><span style=\\\"line-height:1.6em\\\">Mit der F3 !</span></p>\""));
    assertThat(json, endsWith("}"));
}
 
开发者ID:rah003,项目名称:neat-jsonfn,代码行数:21,代码来源:JsonBuilderTest.java

示例5: testSubNodePropertyListingWithExclusionOfParent

import javax.jcr.Session; //导入方法依赖的package包/类
/**
 * Lists specified properties only for sub nodes but not for the parent nodes. Issue #21.
 *
 */
@Test
public void testSubNodePropertyListingWithExclusionOfParent() throws Exception {
    Session session = MgnlContext.getInstance().getJCRSession("website");
    // GIVEN

    Node node = session.getNode("/home/section2/article/mgnl:apex/alias");
    node.addNode("tab0","mgnl:content");
    node.addNode("tab1","mgnl:content");
    node.addNode("tab2","mgnl:content");
    session.save();
    // WHEN
    String json = JsonTemplatingFunctions.from(session.getNode("/home/section2/article/mgnl:apex/alias"))
            .down(1).add( "tab(.+)['@id']").inline().print();
    // THEN
    assertThat(json, startsWith("{"));
    assertThat(json, containsString("\"tab1\":{\"@id\""));
    assertThat(json, not(containsString("},\"@id\":")));
    assertThat(json, containsString("},\"tab2\":{\"@id\":"));
    assertThat(json, endsWith("}"));
}
 
开发者ID:rah003,项目名称:neat-jsonfn,代码行数:25,代码来源:JsonBuilderTest.java

示例6: testSubNodeWithSamePropertyAsOneOfAncestors

import javax.jcr.Session; //导入方法依赖的package包/类
/**
 * Lists specified properties only for parent nodes but not for the subnodes. Issue #16.
 *
 */
@Test
public void testSubNodeWithSamePropertyAsOneOfAncestors() throws Exception {
    Session session = MgnlContext.getInstance().getJCRSession("website");
    // GIVEN

    Node node = session.getNode("/home/section2/article/mgnl:apex/alias");
    node.setProperty("abstract", "foo");
    Node child = node.addNode("linkInternal","mgnl:content");
    child.setProperty("abstract", "foo");
    session.save();
    // WHEN
    String json = JsonTemplatingFunctions.from(session.getNode("/home/section2/article/mgnl:apex/alias"))
            .down(3).add("alias['abstract']").exclude("linkInternal['abstract']").inline().print();
    // THEN
    assertThat(json, startsWith("{"));
    assertThat(json, containsString("{\"abstract\":\"foo\"}"));
    assertThat(json, endsWith("}"));
}
 
开发者ID:rah003,项目名称:neat-jsonfn,代码行数:23,代码来源:JsonBuilderTest.java

示例7: testSubNodeWithSystemPropertyNameAsOneOfAncestors

import javax.jcr.Session; //导入方法依赖的package包/类
/**
 * Lists specified properties only for parent nodes but not for the subnodes. Issue #16.
 *
 */
@Test
public void testSubNodeWithSystemPropertyNameAsOneOfAncestors() throws Exception {
    Session session = MgnlContext.getInstance().getJCRSession("website");
    // GIVEN

    Node node = session.getNode("/home/section2/article/mgnl:apex/alias");
    node.setProperty("abstract", "foo");
    Node child = node.addNode("linkInternal","mgnl:content");
    child.setProperty("abstract", "foo");
    session.save();
    // WHEN
    String json = JsonTemplatingFunctions.from(session.getNode("/home/section2/article/mgnl:apex/alias"))
            .down(3).add("alias['@id']").exclude("linkInternal['@id']").inline().print();
    // THEN
    assertThat(json, startsWith("{"));
    assertThat(json, containsString("{\"@id\":\""));
    assertEquals(json.split("id").length, 2);
    assertThat(json, endsWith("}"));
}
 
开发者ID:rah003,项目名称:neat-jsonfn,代码行数:24,代码来源:JsonBuilderTest.java

示例8: curePhase

import javax.jcr.Session; //导入方法依赖的package包/类
/**
 * The purpose of this method is to check for some conditions which may break Phases.
 * 
 * @param boardId
 * @param phaseId
 * @return
 * @throws Exception
 */
@PreAuthorize("hasPermission(#boardId, 'BOARD', 'ADMIN')")
@RequestMapping(value = "/{phaseId}/cure", method=RequestMethod.GET)
public @ResponseBody Boolean curePhase(@PathVariable String boardId, 
									  		@PathVariable String phaseId) throws Exception {
	
	Session session = ocmFactory.getOcm().getSession();

	try{
		Node node = session.getNode(String.format(URI.PHASES_URI, boardId, phaseId));
		Property property = node.getProperty("cards");
		// If there is a property we need to kill it.
		property.remove();
		session.save();
	} catch (PathNotFoundException e){
		// This is expected - there should be no property.
	} finally {
		session.logout();	
	}
	
	this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
	
	return true;
}
 
开发者ID:cheetah100,项目名称:gravity,代码行数:32,代码来源:PhaseController.java

示例9: getIdFromRepository

import javax.jcr.Session; //导入方法依赖的package包/类
/**
 * This method 
 * @param session
 * @param path
 * @return
 * @throws Exception
 */
public synchronized static Long getIdFromRepository( Session session, String path, String id) throws Exception {
	Long returnId = null;
	//LockManager lockManager = session.getWorkspace().getLockManager();
	try{
		//Lock lock = lockManager.lock(path, false, false, 30000l, "");
		//Node node = lock.getNode();
		Node node = session.getNode(path);
						
		try {
			Property property = node.getProperty(id);
			returnId = property.getLong();
		} catch (PathNotFoundException e) {
			returnId = 10001l;
		}
		
		node.setProperty(id, returnId+1);
		session.save();
				
	} finally { 
		//lockManager.unlock(path);
	}

	return returnId;
}
 
开发者ID:cheetah100,项目名称:gravity,代码行数:32,代码来源:IdentifierTools.java

示例10: ensurePresence

import javax.jcr.Session; //导入方法依赖的package包/类
public void ensurePresence(Session session, String initialPath, String... nodeNames) throws PathNotFoundException, RepositoryException {
	if (null != nodeNames) {
		final String childNodeName = nodeNames[0];
		final Node parentNode = session.getNode(initialPath);
		
		final Node childNode;
		if (parentNode.hasNode(childNodeName)) {
			childNode = parentNode.getNode(childNodeName);
		} else {
			childNode = parentNode.addNode(childNodeName);
			session.save();
		}
		if (nodeNames.length > 1) {
			ensurePresence(session, childNode.getPath(), Arrays.copyOfRange(nodeNames, 1, nodeNames.length));
		}
	}
}
 
开发者ID:cheetah100,项目名称:gravity,代码行数:18,代码来源:ListTools.java

示例11: getAllSubpaths

import javax.jcr.Session; //导入方法依赖的package包/类
private List<String> getAllSubpaths(Session session, final String path) throws RepositoryException, LoginException {
	List<String> subPaths = new ArrayList<>();
	Node node = session.getNode(path);
	subPaths.addAll(crawl(node));

	return subPaths;
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:8,代码来源:CheckPermissions.java

示例12: saveScript

import javax.jcr.Session; //导入方法依赖的package包/类
private Script saveScript(ResourceResolver resolver, final String fileName, final InputStream input,
		final boolean overwrite) {
	Script result = null;
	final Session session = resolver.adaptTo(Session.class);
	final ValueFactory valueFactory;
	try {
		valueFactory = session.getValueFactory();
		final Binary binary = valueFactory.createBinary(input);
		final Node saveNode = session.getNode(getSavePath());

		final Node fileNode, contentNode;
		if (overwrite && saveNode.hasNode(fileName)) {
			fileNode = saveNode.getNode(fileName);
			contentNode = fileNode.getNode(JcrConstants.JCR_CONTENT);
		} else {
			fileNode = saveNode.addNode(generateFileName(fileName, saveNode), JcrConstants.NT_FILE);
			contentNode = fileNode.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
		}

		contentNode.setProperty(JcrConstants.JCR_DATA, binary);
		contentNode.setProperty(JcrConstants.JCR_ENCODING, SCRIPT_ENCODING.name());
		JcrUtils.setLastModified(contentNode, Calendar.getInstance());
		session.save();
		result = scriptFinder.find(fileNode.getPath(), resolver);
	} catch (RepositoryException e) {
		LOG.error(e.getMessage(), e);
	}
	return result;
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:30,代码来源:ScriptStorageImpl.java

示例13: writeJcrContent

import javax.jcr.Session; //导入方法依赖的package包/类
void writeJcrContent(Session session) throws RepositoryException {

    // get node directly
    Node talk = session.getNode("/content/adaptto/2015/day1/rookie-session");

    // write property values
    talk.setProperty("jcr:title", "My Rookie Session");
    talk.setProperty("durationMin", talk.getProperty("durationMin").getLong() + 10);
    talk.setProperty("tags", new String[] { "Sling", "JCR", "Rookie" });

    // save changes to repository (implicit transaction)
    session.save();
  }
 
开发者ID:adaptto,项目名称:2015-sling-rookie-session,代码行数:14,代码来源:JcrWriteSample.java

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

示例15: testPrintDoubleQuoted

import javax.jcr.Session; //导入方法依赖的package包/类
/**
 * jsonfn.from(content).add(".*").inline().print()
 *
 * ==> { "foo" : "that\\'s it", ... }
 */
@Test
public void testPrintDoubleQuoted() throws Exception {
    // GIVEN
    Session session = MgnlContext.getInstance().getJCRSession("website");
    Node node = session.getNode("/home/section2/article/mgnl:apex");
    node.setProperty("escape", "that\"s it");
    // WHEN
    String json = JsonTemplatingFunctions.from(node).add("escape").inline().escapeBackslash().print();
    // THEN
    assertThat(json, startsWith("{"));
    assertThat(json, containsString("\"escape\":\"that\\\\\"s it\""));
    assertThat(json, endsWith("}"));
}
 
开发者ID:rah003,项目名称:neat-jsonfn,代码行数:19,代码来源:JsonBuilderTest.java


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