javax.jcr.Node.getIdentifier()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(173)

本文整理了Java中javax.jcr.Node.getIdentifier()方法的一些代码示例,展示了Node.getIdentifier()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.getIdentifier()方法的具体详情如下:
包路径:javax.jcr.Node
类名称:Node
方法名:getIdentifier

Node.getIdentifier介绍

[英]Returns the identifier of this node. Applies to both referenceable and non-referenceable nodes.

A RepositoryException is thrown if an error occurs.
[中]返回此节点的标识符。适用于可引用和不可引用节点。
如果发生错误,将抛出RepositoryException

代码示例

代码示例来源:origin: info.magnolia/magnolia-core

  1. /**
  2. * Used for building exception messages where we want to avoid handling another exception inside a throws clause.
  3. */
  4. public static String getNodeIdentifierIfPossible(Node content) {
  5. try {
  6. return content.getIdentifier();
  7. } catch (RepositoryException e) {
  8. return "<not available>";
  9. }
  10. }

代码示例来源:origin: info.magnolia/magnolia-core

  1. @Override
  2. public int compare(Node node1, Node node2) {
  3. try {
  4. final String identifier1 = node1.getIdentifier();
  5. final String identifier2 = node2.getIdentifier();
  6. return identifier1.compareTo(identifier2);
  7. } catch (RepositoryException e) {
  8. throw new RuntimeException("Error getting identifier from jcr node.", e);
  9. }
  10. }

代码示例来源:origin: info.magnolia/magnolia-core

  1. String getSavePath(Node node) throws RepositoryException {
  2. String uuid = node.getIdentifier();
  3. return String.format("%s/%s/%s", StringUtils.substring(uuid, 0, 2), StringUtils.substring(uuid, 9, 11), StringUtils.substring(uuid, 14, 16));
  4. }
  5. }

代码示例来源:origin: info.magnolia/magnolia-core

  1. public LazyNodeWrapper(Node node) throws RepositoryException {
  2. this.workspace = node.getSession().getWorkspace().getName();
  3. this.nodeIdentifier = node.getIdentifier();
  4. this.node = node;
  5. }

代码示例来源:origin: info.magnolia/magnolia-core

  1. @Override
  2. public MgnlGroup doExec(Session session) throws RepositoryException {
  3. String parentPath = StringUtils.defaultString(path, "/");
  4. Node groupNode = session.getNode(parentPath).addNode(name, NodeTypes.Group.NAME);
  5. session.save();
  6. return new MgnlGroup(groupNode.getIdentifier(), groupNode.getName(), Collections.EMPTY_LIST, Collections.EMPTY_LIST);
  7. }

代码示例来源:origin: info.magnolia/magnolia-core

  1. @Override
  2. public void setWrappedNode(Node node) {
  3. try {
  4. this.workspace = node.getSession().getWorkspace().getName();
  5. this.nodeIdentifier = node.getIdentifier();
  6. this.node = node;
  7. } catch (RepositoryException e) {
  8. throw new RuntimeRepositoryException(e);
  9. }
  10. }

代码示例来源:origin: info.magnolia/magnolia-core

  1. public String getUUID() {
  2. if (StringUtils.isEmpty(this.uuid) && this.getJCRNode() != null) {
  3. try {
  4. this.uuid = this.getJCRNode().getIdentifier();
  5. } catch (RepositoryException e) {
  6. throw new RuntimeRepositoryException(e);
  7. }
  8. }
  9. return this.uuid;
  10. }

代码示例来源:origin: info.magnolia/magnolia-core

  1. private String getSavePath(Node node) throws RepositoryException {
  2. String uuid = node.getIdentifier();
  3. return String.format("%s/%s/%s", StringUtils.substring(uuid, 0, 2), StringUtils.substring(uuid, 9, 11), StringUtils.substring(uuid, 14, 16));
  4. }
  5. }

代码示例来源:origin: info.magnolia/magnolia-core

  1. private void prepareGroupData() throws Exception {
  2. String peopleGroup = "people";
  3. String employeesGroup = "employees";
  4. String developersGroup = "developers";
  5. // Create a group (developers) which has an assigned group (employees) which again has an assigned group (people)
  6. final Node developersNode = session.getRootNode().addNode(developersGroup, NodeTypes.Group.NAME);
  7. final Node employeesNode = session.getRootNode().addNode(employeesGroup, NodeTypes.Group.NAME);
  8. final Node peopleNode = session.getRootNode().addNode(peopleGroup, NodeTypes.Group.NAME);
  9. developersNode.addNode(RepositoryBackedSecurityManager.GROUPS_NODE_NAME, NodeTypes.ContentNode.NAME).setProperty("0", employeesNode.getIdentifier());
  10. employeesNode.addNode(RepositoryBackedSecurityManager.GROUPS_NODE_NAME, NodeTypes.ContentNode.NAME).setProperty("0", peopleNode.getIdentifier());
  11. session.save();
  12. }

代码示例来源:origin: pentaho/pentaho-platform

  1. public Object doInJcr( final Session session ) throws RepositoryException, IOException {
  2. PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants( session );
  3. Node node = session.getNodeByIdentifier( id.toString() );
  4. if ( !node.getParent().isSame( session.getRootNode() ) ) {
  5. return toAcl( session, pentahoJcrConstants, node.getParent().getIdentifier() );
  6. } else {
  7. return null;
  8. }
  9. }
  10. } );

代码示例来源:origin: info.magnolia.ui/magnolia-ui-admincentral

  1. @Override
  2. public Boolean answer(InvocationOnMock invocation) throws Throwable {
  3. Node foo = parentNode.addNode("foo", Page.NAME);
  4. Node bar = parentNode.addNode("bar", Page.NAME);
  5. expectedItemIds.add(new JcrNodeItemId(foo.getIdentifier(), WEBSITE));
  6. expectedItemIds.add(new JcrNodeItemId(bar.getIdentifier(), WEBSITE));
  7. return true;
  8. }
  9. }).when(commandsManager).executeCommand(eq(mockCommand), anyMapOf(String.class, Object.class));

代码示例来源:origin: info.magnolia/magnolia-core

  1. public Link(Node node) {
  2. try {
  3. setJCRNode(node);
  4. setWorkspace(node.getSession().getWorkspace().getName());
  5. if (node.isNodeType(JcrConstants.MIX_REFERENCEABLE)) {
  6. setUUID(node.getIdentifier());
  7. }
  8. } catch (RepositoryException e) {
  9. throw new RuntimeRepositoryException(e);
  10. }
  11. }

代码示例来源:origin: apache/jackrabbit-oak

  1. @Override
  2. protected void setUp() throws Exception {
  3. super.setUp();
  4. Node node = testRootNode.addNode(nodeName1);
  5. node.addMixin(mixReferenceable);
  6. Node sibling = testRootNode.addNode(nodeName2);
  7. uuid = node.getIdentifier();
  8. path = node.getPath();
  9. siblingPath = sibling.getPath();
  10. }

代码示例来源:origin: info.magnolia/magnolia-core

  1. private void createUserAndAddToGroup(String userName, String groupName, String basePath) throws Exception {
  2. // "manually" create a user and assign it to a group => /admin/<userName>/groups/0=<group-uuid>
  3. Session groupsSession = MgnlContext.getJCRSession(RepositoryConstants.USER_GROUPS);
  4. String groupUuid = groupsSession.getNode("/" + groupName).getIdentifier();
  5. //
  6. Session usersSession = MgnlContext.getJCRSession(RepositoryConstants.USERS);
  7. Node parentNode = NodeUtil.createPath(session.getRootNode(), basePath, NodeTypes.Folder.NAME);
  8. Node newUserNode = parentNode.addNode(userName, NodeTypes.User.NAME);
  9. Node groupsNode = newUserNode.addNode("groups", NodeTypes.ContentNode.NAME);
  10. groupsNode.setProperty("0", groupUuid);
  11. usersSession.save();
  12. }

代码示例来源:origin: info.magnolia/magnolia-core

  1. @Test
  2. public void testGetNodeByIdentifierBadId() throws RepositoryException {
  3. // GIVEN
  4. Node addedNode = MgnlContext.getJCRSession(WEBSITE).getRootNode().addNode("1");
  5. // WHEN
  6. Node returnedNode = SessionUtil.getNodeByIdentifier(WEBSITE, addedNode.getIdentifier() + 1);
  7. // THEN
  8. assertEquals(null, returnedNode);
  9. }

代码示例来源:origin: info.magnolia/magnolia-core

  1. @Test
  2. public void versionNodesAreRenamed() throws Exception {
  3. // WHEN
  4. task.execute(installContext);
  5. // THEN
  6. assertThat(testNode.getPath(), is("/" + getSavePath(testNode) + "/" + testNode.getIdentifier()));
  7. }

代码示例来源:origin: info.magnolia/magnolia-core

  1. @Test
  2. public void testGetNodeByIdentifier() throws RepositoryException {
  3. // GIVEN
  4. Node addedNode = MgnlContext.getJCRSession(WEBSITE).getRootNode().addNode("1");
  5. // WHEN
  6. Node returnedNode = SessionUtil.getNodeByIdentifier(WEBSITE, addedNode.getIdentifier());
  7. // THEN
  8. assertEquals(addedNode, returnedNode);
  9. }

代码示例来源:origin: apache/jackrabbit-oak

  1. public void testRemoveUUID() throws Exception {
  2. superuser.save();
  3. superuser.importXML(siblingPath, getImportStream(), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING);
  4. superuser.save();
  5. // original node must have been removed
  6. assertFalse(testRootNode.hasNode(nodeName1));
  7. Node sibling = superuser.getNode(siblingPath);
  8. assertTrue(sibling.hasNode(nodeName1));
  9. Node imported = sibling.getNode(nodeName1);
  10. assertTrue(imported.isNodeType(mixReferenceable));
  11. assertEquals(uuid, imported.getIdentifier());
  12. }

代码示例来源:origin: info.magnolia/magnolia-core

  1. @Test
  2. public void testCreateSessionFromString() throws IOException, RepositoryException {
  3. String workspace = "workspace";
  4. String content = "/parent1/sub1.prop1=one";
  5. MockSession session = SessionTestUtil.createSession(workspace, content);
  6. assertEquals("one", session.getNode("/parent1/sub1").getProperty("prop1").getString());
  7. content = "/parent1/sub1.@uuid=1\n" + "/parent2/sub2.@uuid=2";
  8. session = SessionTestUtil.createSession("testWorkspace", content);
  9. assertEquals("1", session.getNode("/parent1/sub1").getIdentifier());
  10. assertEquals("2", session.getNode("/parent2/sub2").getIdentifier());
  11. }

代码示例来源:origin: info.magnolia/magnolia-core

  1. @Test
  2. public void copyToVersionWithNewStructure() throws Exception {
  3. // GIVEN
  4. Node testNode = websiteSession.getRootNode().addNode("test", NodeTypes.Page.NAME);
  5. // WHEN
  6. copyUtil.copyToVersion(testNode, new RuleBasedNodePredicate(new Rule()));
  7. // THEN
  8. Node versionNode = versionSession.getNodeByIdentifier(testNode.getIdentifier());
  9. assertThat(versionNode.getParent().getPath(), matchesRegex("/\\w{2}/\\w{2}/\\w{2}"));
  10. assertThat(versionSession.getRootNode(), hasNode(CopyUtil.getSavePath(versionNode) + "/" + testNode.getIdentifier()));
  11. }

相关文章