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

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

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

Node.getName介绍

暂无

代码示例

代码示例来源:origin: org.apache.sling/org.apache.sling.jcr.resource

  1. private String getPath(final Node node) throws RepositoryException {
  2. final String path;
  3. if (parentPath == null) {
  4. path = node.getPath();
  5. } else {
  6. path = "/".equals(parentPath) ? '/' + node.getName() : parentPath + '/' + node.getName();
  7. }
  8. return path;
  9. }
  10. }

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

  1. private Node getFirstChild(Node parentNode, Collection<String> childNames) throws RepositoryException {
  2. NodeIterator nodes = parentNode.getNodes();
  3. while (nodes.hasNext()) {
  4. Node child = nodes.nextNode();
  5. if (childNames.contains(child.getName())) {
  6. return child;
  7. }
  8. }
  9. return null;
  10. }

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

  1. /**
  2. * Tests if the name of the created node is correct.
  3. */
  4. public void testName() throws RepositoryException {
  5. Node n1 = testRootNode.addNode(nodeName1, testNodeType);
  6. testRootNode.getSession().save();
  7. assertEquals("Wrong node name.", n1.getName(), nodeName1);
  8. }

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

  1. /**
  2. * A ConstraintViolationException is thrown if the operation would violate a
  3. * node-type or other implementation-specific constraint.
  4. */
  5. public void testMoveNodesConstraintViolationException() throws RepositoryException {
  6. // if parent node is nt:base then no sub nodes can be created
  7. String nodetype = testNodeTypeNoChildren == null ? ntBase : testNodeTypeNoChildren;
  8. Node subNodesNotAllowedNode = testRootNode.addNode(nodeName3, nodetype);
  9. testRootNode.getSession().save();
  10. try {
  11. String dstAbsPath = subNodesNotAllowedNode.getPath() + "/" + node2.getName();
  12. workspace.move(node2.getPath(), dstAbsPath);
  13. fail("Moving a node below a node which can not have any sub nodes should throw a ConstraintViolationException.");
  14. } catch (ConstraintViolationException e) {
  15. // successful
  16. }
  17. }

代码示例来源:origin: org.onehippo.cms7/hippo-repository-engine

  1. private void moveToHistory(final Node node) {
  2. try {
  3. // the updater node was modified externally by the executor
  4. session.refresh(false);
  5. final String srcPath = node.getPath();
  6. final Node history = session.getNode(UPDATE_HISTORY_PATH);
  7. String name = node.getName();
  8. int count = 2;
  9. while (history.hasNode(name)) {
  10. name = node.getName() + "-" + count++;
  11. }
  12. final String destPath = UPDATE_HISTORY_PATH + "/" + name;
  13. session.move(srcPath, destPath);
  14. session.save();
  15. } catch (RepositoryException e) {
  16. log.error("Failed to remove updater from queue", e);
  17. }
  18. }

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

  1. @Test
  2. public void findPrincipalNodes() throws Exception {
  3. // GIVEN
  4. final String otherTestUser = "Dagobert";
  5. final Node folder = root.addNode("folder", NodeTypes.Folder.NAME);
  6. folder.addNode(otherTestUser, NodeTypes.User.NAME);
  7. session.save();
  8. // WHEN
  9. final NodeIterator iterator = securityManager.findPrincipalNodes(root, NodeTypes.User.NAME);
  10. // THEN
  11. final List<String> users = new ArrayList<>();
  12. while (iterator.hasNext()) {
  13. users.add(iterator.nextNode().getName());
  14. }
  15. assertThat(users, hasItem(TEST_USER_NAME));
  16. assertThat(users, hasItem(otherTestUser));
  17. }

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

  1. /**
  2. * OAK-612
  3. */
  4. @Test
  5. public void testAddNode() throws Exception {
  6. new TestContentLoader().loadTestContent(getAdminSession());
  7. Session session = getAdminSession();
  8. Node test = session.getRootNode().addNode("test", "test:orderableFolder");
  9. assertTrue(test.getPrimaryNodeType().hasOrderableChildNodes());
  10. test.addNode("a");
  11. test.addNode("b");
  12. session.save();
  13. NodeIterator it = test.getNodes();
  14. assertEquals("a", it.nextNode().getName());
  15. assertEquals("b", it.nextNode().getName());
  16. }

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

  1. public void testNameLength() throws RepositoryException {
  2. node.setProperty(propertyName1, vf.createValue(node.getName(), PropertyType.NAME));
  3. superuser.save();
  4. checkOperators(propertyName1, node.getProperty(propertyName1).getLength());
  5. }

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

  1. /**
  2. * Orders the node first among its siblings.
  3. */
  4. public static void orderFirst(Node node) throws RepositoryException {
  5. Node parent = node.getParent();
  6. NodeIterator siblings = parent.getNodes();
  7. Node firstSibling = siblings.nextNode();
  8. if (!firstSibling.isSame(node)) {
  9. parent.orderBefore(node.getName(), firstSibling.getName());
  10. }
  11. }

代码示例来源:origin: org.onehippo.cms7.hst.client-modules/hst-page-composer

  1. private void moveContainerItems(final Node from, final Node to) throws RepositoryException {
  2. Session session = from.getSession();
  3. for (Node fromChild : new NodeIterable(from.getNodes())) {
  4. String newName = fromChild.getName();
  5. int counter = 0;
  6. while (to.hasNode(newName)) {
  7. newName = fromChild.getName() + ++counter;
  8. }
  9. session.move(fromChild.getPath(), to.getPath() + "/" + newName);
  10. }
  11. }

代码示例来源:origin: org.onehippo.cms7/hippo-repository-engine

  1. private void markMissingInitializeItems(final Session session, final Set<String> itemNames) throws RepositoryException {
  2. final Node initializeFolder = session.getNode(INIT_FOLDER_PATH);
  3. for (Node item : new NodeIterable(initializeFolder.getNodes())) {
  4. if (!itemNames.contains(item.getName()) && !item.getName().equals(HIPPO_LOCK)) {
  5. log.info("Marking missing initialize item {}", item.getName());
  6. InitializeItem.markMissing(item);
  7. }
  8. }
  9. session.save();
  10. }

代码示例来源:origin: ModeShape/modeshape

  1. @Override
  2. public void afterEach() throws Exception {
  3. NodeIterator nodeIterator = session.getRootNode().getNodes();
  4. while (nodeIterator.hasNext()) {
  5. Node node = nodeIterator.nextNode();
  6. if (!JcrLexicon.SYSTEM.getString().equals(node.getName())) {
  7. node.remove();
  8. }
  9. }
  10. session.save();
  11. super.afterEach();
  12. }

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

  1. private Node getLastChild(Node parent, Collection<String> childNames) throws RepositoryException {
  2. Node lastMatch = null;
  3. NodeIterator nodes = parent.getNodes();
  4. while (nodes.hasNext()) {
  5. Node child = nodes.nextNode();
  6. if (childNames.contains(child.getName())) {
  7. lastMatch = child;
  8. }
  9. }
  10. return lastMatch;
  11. }

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

  1. /**
  2. * A ConstraintViolationException is thrown if the operation would violate a
  3. * node-type or other implementation-specific constraint.
  4. */
  5. public void testCopyNodesConstraintViolationException() throws RepositoryException {
  6. // if parent node is nt:base then no sub nodes can be created
  7. String nodetype = testNodeTypeNoChildren == null ? ntBase : testNodeTypeNoChildren;
  8. Node subNodesNotAllowedNode = testRootNode.addNode(nodeName3, nodetype);
  9. testRootNode.getSession().save();
  10. try {
  11. String dstAbsPath = subNodesNotAllowedNode.getPath() + "/" + node2.getName();
  12. workspace.copy(node2.getPath(), dstAbsPath);
  13. fail("Copying a node below a node which can not have any sub nodes should throw a ConstraintViolationException.");
  14. } catch (ConstraintViolationException e) {
  15. // successful
  16. }
  17. }

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

  1. /**
  2. * Test if the removeExisting-flag removes an existing node in case of uuid conflict.
  3. */
  4. public void testWorkspaceRestoreWithRemoveExistingJcr2() throws NotExecutableException, RepositoryException {
  5. // create version for parentNode of childNode
  6. superuser.getWorkspace().clone(workspaceName, wVersionableChildNode.getPath(), wVersionableChildNode.getPath(), false);
  7. Version parentV = versionableNode.getSession().getWorkspace().getVersionManager().checkin(versionableNode.getPath());
  8. // move child node in order to produce the uuid conflict
  9. String newChildPath = wVersionableNode2.getPath() + "/" + wVersionableChildNode.getName();
  10. wSuperuser.move(wVersionableChildNode.getPath(), newChildPath);
  11. wSuperuser.save();
  12. // restore the parent with removeExisting == true >> moved child node
  13. // must be removed.
  14. wSuperuser.getWorkspace().getVersionManager().restore(new Version[]{parentV}, true);
  15. if (wSuperuser.itemExists(newChildPath)) {
  16. fail("Workspace.restore(Version[], boolean) with the boolean flag set to true, must remove the existing node in case of Uuid conflict.");
  17. }
  18. }

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

  1. /**
  2. * Take action on a sibling node.<br>
  3. * In this case, simply display in the install screen the sibling node name and path.
  4. */
  5. protected void handleNode(Node node, InstallContext installContext) throws RepositoryException {
  6. installContext.warn("Found same name sibling of '" + node.getName() + "' at '" + node.getPath() + "'");
  7. }

代码示例来源: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. @Test
  2. public void findPrincipalNodesIgnoresNodesUnderDifferentRoot() throws Exception {
  3. // GIVEN
  4. final String otherTestUser = "Dagobert";
  5. final Node folder = root.addNode("folder", NodeTypes.Folder.NAME);
  6. folder.addNode(otherTestUser, NodeTypes.User.NAME);
  7. session.save();
  8. // WHEN
  9. final NodeIterator iterator = securityManager.findPrincipalNodes(folder, NodeTypes.User.NAME);
  10. // THEN
  11. final List<String> users = new ArrayList<>();
  12. while (iterator.hasNext()) {
  13. users.add(iterator.nextNode().getName());
  14. }
  15. assertThat(users, not(hasItem(TEST_USER_NAME)));
  16. assertThat(users, hasItem(otherTestUser));
  17. }

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

  1. @SuppressWarnings("deprecation")
  2. public void testRestoreRemoved() throws RepositoryException {
  3. Node parent = versionableNode.getParent();
  4. String oldName = versionableNode.getName();
  5. Version v1 = versionableNode.checkin();
  6. versionableNode.remove();
  7. versionableNode = null;
  8. parent.getSession().save();
  9. parent.restore(v1, oldName, true);
  10. versionableNode = parent.getNode(oldName);
  11. String value = versionableNode.getProperty(propertyName1).getString();
  12. assertEquals("Restoring a node must set the correct property.", propertyValue2, value);
  13. }

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

  1. private void assertNodeOrder(Node node, String[] names) throws RepositoryException {
  2. NodeIterator nodes = node.getNodes();
  3. for (String name : names) {
  4. Node childNode = nodes.nextNode();
  5. if (!childNode.getName().equals(name)) {
  6. fail("Expected [" + name + "] was [" + childNode.getName() + "]");
  7. }
  8. }
  9. }
  10. }

相关文章