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

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

本文整理了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

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

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

@Override
public int compare(Node node1, Node node2) {
  try {
    final String identifier1 = node1.getIdentifier();
    final String identifier2 = node2.getIdentifier();
    return identifier1.compareTo(identifier2);
  } catch (RepositoryException e) {
    throw new RuntimeException("Error getting identifier from jcr node.", e);
  }
}

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

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

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

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

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

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

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

@Override
public void setWrappedNode(Node node) {
  try {
    this.workspace = node.getSession().getWorkspace().getName();
    this.nodeIdentifier = node.getIdentifier();
    this.node = node;
  } catch (RepositoryException e) {
    throw new RuntimeRepositoryException(e);
  }
}

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

public String getUUID() {
  if (StringUtils.isEmpty(this.uuid) && this.getJCRNode() != null) {
    try {
      this.uuid = this.getJCRNode().getIdentifier();
    } catch (RepositoryException e) {
      throw new RuntimeRepositoryException(e);
    }
  }
  return this.uuid;
}

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

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

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

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

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

public Object doInJcr( final Session session ) throws RepositoryException, IOException {
  PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants( session );
  Node node = session.getNodeByIdentifier( id.toString() );
  if ( !node.getParent().isSame( session.getRootNode() ) ) {
   return toAcl( session, pentahoJcrConstants, node.getParent().getIdentifier() );
  } else {
   return null;
  }
 }
} );

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

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

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

public Link(Node node) {
  try {
    setJCRNode(node);
    setWorkspace(node.getSession().getWorkspace().getName());
    if (node.isNodeType(JcrConstants.MIX_REFERENCEABLE)) {
      setUUID(node.getIdentifier());
    }
  } catch (RepositoryException e) {
    throw new RuntimeRepositoryException(e);
  }
}

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

@Override
protected void setUp() throws Exception {
  super.setUp();
  Node node = testRootNode.addNode(nodeName1);
  node.addMixin(mixReferenceable);
  Node sibling = testRootNode.addNode(nodeName2);
  uuid = node.getIdentifier();
  path = node.getPath();
  siblingPath = sibling.getPath();
}

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

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

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

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

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

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

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

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

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

public void testRemoveUUID() throws Exception {
  superuser.save();
  superuser.importXML(siblingPath, getImportStream(), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING);
  superuser.save();
  // original node must have been removed
  assertFalse(testRootNode.hasNode(nodeName1));
  Node sibling = superuser.getNode(siblingPath);
  assertTrue(sibling.hasNode(nodeName1));
  Node imported = sibling.getNode(nodeName1);
  assertTrue(imported.isNodeType(mixReferenceable));
  assertEquals(uuid, imported.getIdentifier());
}

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

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

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

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

相关文章

微信公众号

最新文章

更多