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

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

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

Node.orderBefore介绍

[英]If this node supports child node ordering, this method inserts the child node at srcChildRelPath into the child node list at the position immediately the child node at destChildRelPath.

To place the node srcChildRelPath at the end of the list, a destChildRelPath of null is used.

Note that (apart from the case where destChildRelPath is null) both of these arguments must be relative paths of depth one, in other words they are the names of the child nodes, possibly suffixed with an index.

If srcChildRelPath and destChildRelPath are the same, then no change is made.

This is session-write method, meaning that a change made by this method is dispatched on save

A ConstraintViolationException will be thrown either immediately, on dispatch (save whether within or without transactions) or on persist (save without transactions, commit within a transaction), if this operation would violate a node type or implementation-specific constraint. Implementations may differ on when this validation is performed.

A VersionException will be thrown either immediately, on dispatch (save whether within or without transactions) or on persist (save without transactions, commit within a transaction), if this node is read-only due to it or a node above it being checked-in Implementations may differ on when this validation is performed.

A LockException will be thrown either immediately (by this method), or on save, if a lock prevents the re-ordering. Implementations may differ on when this validation is performed.
[中]如果此节点支持子节点排序,则此方法会将srcChildRelPath处的子节点插入子节点列表中destChildRelPath处的子节点旁边的位置。
要将节点srcChildRelPath放在列表的末尾,需要使用destChildRelPathnull
请注意(除了destChildRelPathnull的情况之外),这两个参数都必须是深度为1的相对路径,换句话说,它们是子节点的名称,可能带有索引后缀。
如果srcChildRelPathdestChildRelPath是相同的,则不会进行任何更改。
这是会话写入方法,意味着此方法所做的更改将在save上调度
如果此操作违反了节点类型或特定于实现的约束,则ConstraintViolationException将立即在分派时(无论是否在事务中保存)或在持久化时(不在事务中保存,在事务中提交)抛出。执行此验证的时间可能会有所不同。
VersionException将立即抛出,无论是在分派时(保存是否包含事务)还是在持久化时(保存而不包含事务,在事务中提交),如果此节点由于其原因是只读的,或者它上面的节点正在被检入,则在执行此验证时,实现可能会有所不同。
如果锁阻止重新订购,将立即(通过此方法)或在save上抛出LockException。执行此验证的时间可能会有所不同。

代码示例

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

  1. /**
  2. * @inheritDoc
  3. */
  4. public void orderBefore(String srcChildRelPath, String destChildRelPath)
  5. throws UnsupportedRepositoryOperationException, VersionException, ConstraintViolationException,
  6. ItemNotFoundException, LockException, RepositoryException {
  7. node.orderBefore(srcChildRelPath, destChildRelPath);
  8. }

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

  1. /**
  2. * Orders the node last among its siblings.
  3. */
  4. public static void orderLast(Node node) throws RepositoryException {
  5. node.getParent().orderBefore(node.getName(), null);
  6. }

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

  1. /**
  2. * Convenience - delegate to {@link Node#orderBefore(String, String)}.
  3. */
  4. public static void orderBefore(Node node, String siblingName) throws RepositoryException {
  5. node.getParent().orderBefore(node.getName(), siblingName);
  6. }

代码示例来源: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: info.magnolia/magnolia-core

  1. /**
  2. * Orders the node down one step among its siblings. If the node is the only sibling or the last sibling this method
  3. * has no effect.
  4. */
  5. public static void orderNodeDown(Node node) throws RepositoryException {
  6. Node siblingAfter = getSiblingAfter(node);
  7. if (siblingAfter != null) {
  8. node.getParent().orderBefore(siblingAfter.getName(), node.getName());
  9. }
  10. }

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

  1. public static void moveNodeBefore(Node nodeToMove, Node target) throws RepositoryException {
  2. Node targetParent = target.getParent();
  3. moveNode(nodeToMove, targetParent);
  4. targetParent.orderBefore(nodeToMove.getName(), target.getName());
  5. }

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

  1. /**
  2. * Orders the node up one step among its siblings. If the node is the only sibling or the first sibling this method
  3. * has no effect.
  4. */
  5. public static void orderNodeUp(Node node) throws RepositoryException {
  6. Node siblingBefore = getSiblingBefore(node);
  7. if (siblingBefore != null) {
  8. node.getParent().orderBefore(node.getName(), siblingBefore.getName());
  9. }
  10. }

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

  1. public static void renameNode(Node node, String newName) throws RepositoryException {
  2. if (node.getName().equals(newName)) {
  3. return;
  4. }
  5. final Node parent = node.getParent();
  6. final String newPath = combinePathAndName(parent.getPath(), newName);
  7. final Node siblingAfter = NodeUtil.getSiblingAfter(node);
  8. node.getSession().move(node.getPath(), newPath);
  9. if (siblingAfter != null) {
  10. parent.orderBefore(newName, siblingAfter.getName());
  11. }
  12. }

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

  1. @Override
  2. protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException {
  3. final Node node = installContext.getJCRSession(repository).getNode(path);
  4. node.getParent().orderBefore(node.getName(), orderBeforeNodeName);
  5. }

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

  1. @Test
  2. public void orderSameNode() throws Exception {
  3. Session session = getAdminSession();
  4. Node n = session.getRootNode().addNode("test", "nt:unstructured");
  5. Node a = n.addNode("a");
  6. n.orderBefore("a", "a");
  7. }

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

  1. public void testReorderWithAdd() throws Exception {
  2. testRootNode.orderBefore("C", "A");
  3. session.getNode(testRoot).addNode("D");
  4. session.save();
  5. try {
  6. superuser.save();
  7. fail("must throw InvalidItemStateException");
  8. } catch (InvalidItemStateException e) {
  9. // expected
  10. }
  11. }

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

  1. @Override
  2. public void testRevertReorderToEnd() throws RepositoryException {
  3. testRootNode.orderBefore(getRelPath(child1), null);
  4. testOrder(testRootNode, new Node[] { child2, child3, child4, child1});
  5. // NEW child nodes -> must be removed upon refresh
  6. testRootNode.refresh(false);
  7. NodeIterator it = testRootNode.getNodes();
  8. if (it.hasNext()) {
  9. fail("Reverting creation and reordering of new children must remove the children again.");
  10. }
  11. }
  12. }

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

  1. @Override
  2. public void testRevertReorderToEnd() throws RepositoryException {
  3. testRootNode.orderBefore(getRelPath(child1), null);
  4. testOrder(testRootNode, new Node[] { child2, child3, child4, child1});
  5. // NEW child nodes -> must be removed upon refresh
  6. testRootNode.refresh(false);
  7. NodeIterator it = testRootNode.getNodes(nodeName2);
  8. if (it.hasNext()) {
  9. fail("Reverting creation and reordering of new SNSs must remove the children again.");
  10. }
  11. }
  12. }

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

  1. public void testReorderTwice() throws RepositoryException {
  2. testRootNode.orderBefore(getRelPath(child2), null);
  3. testRootNode.orderBefore(getRelPath(child4), getRelPath(child1));
  4. testOrder(testRootNode, new Node[] { child4, child1, child3, child2});
  5. testRootNode.save();
  6. testOrder(testRootNode, new Node[] { child4, child1, child3, child2});
  7. }

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

  1. @Override
  2. public void testRevertReorder() throws RepositoryException {
  3. testRootNode.orderBefore(getRelPath(child4), getRelPath(child2));
  4. testOrder(testRootNode, new Node[] { child1, child4, child2, child3});
  5. // NEW child nodes -> must be removed upon refresh
  6. testRootNode.refresh(false);
  7. NodeIterator it = testRootNode.getNodes();
  8. if (it.hasNext()) {
  9. fail("Reverting creation and reordering of new children must remove the children again.");
  10. }
  11. }

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

  1. public void testReorder3() throws RepositoryException {
  2. String pathBefore = child3.getPath();
  3. testRootNode.orderBefore(getRelPath(child3), getRelPath(child1));
  4. testRootNode.save();
  5. Item itemIndex3 = testRootNode.getSession().getItem(pathBefore);
  6. assertTrue(itemIndex3.isSame(child2));
  7. Item item3 = testRootNode.getSession().getItem(child3.getPath());
  8. assertTrue(item3.isSame(child3));
  9. }
  10. }

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

  1. public void testReorderToEnd() throws RepositoryException, ConstraintViolationException, UnsupportedRepositoryOperationException, VersionException {
  2. testRootNode.orderBefore(getRelPath(child2), null);
  3. testOrder(testRootNode, new Node[] { child1, child3, child4, child2});
  4. testRootNode.save();
  5. testOrder(testRootNode, new Node[] { child1, child3, child4, child2});
  6. }

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

  1. @Test
  2. public void testReorder3() throws Exception {
  3. Node n = testSession.getNode(path);
  4. // give 'add_child_nodes', 'nt-management' and 'remove_child_nodes' at
  5. // 'path' -> reorder must succeed
  6. allow(path, privilegesFromNames(new String[] {Privilege.JCR_ADD_CHILD_NODES,
  7. Privilege.JCR_REMOVE_CHILD_NODES, Privilege.JCR_NODE_TYPE_MANAGEMENT}));
  8. n.orderBefore(Text.getName(childNPath2), Text.getName(childNPath));
  9. testSession.save();
  10. }

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

  1. @Override
  2. public void testRevertReorder() throws RepositoryException {
  3. testRootNode.orderBefore(getRelPath(child4), getRelPath(child2));
  4. testOrder(testRootNode, new Node[] { child1, child4, child2, child3});
  5. testRootNode.refresh(false);
  6. testOrder(testRootNode, new Node[] { child1, child2 });
  7. }

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

  1. public void testReorder() throws RepositoryException {
  2. testRootNode.orderBefore(getRelPath(child1), getRelPath(child3));
  3. testOrder(testRootNode, new Node[] { child2, child1, child3, child4});
  4. testRootNode.save();
  5. testOrder(testRootNode, new Node[] { child2, child1, child3, child4});
  6. }

相关文章