本文整理了Java中javax.jcr.Node.orderBefore()
方法的一些代码示例,展示了Node.orderBefore()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.orderBefore()
方法的具体详情如下:
包路径:javax.jcr.Node
类名称: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
放在列表的末尾,需要使用destChildRelPath
的null
。
请注意(除了destChildRelPath
是null
的情况之外),这两个参数都必须是深度为1的相对路径,换句话说,它们是子节点的名称,可能带有索引后缀。
如果srcChildRelPath
和destChildRelPath
是相同的,则不会进行任何更改。
这是会话写入方法,意味着此方法所做的更改将在save
上调度
如果此操作违反了节点类型或特定于实现的约束,则ConstraintViolationException
将立即在分派时(无论是否在事务中保存)或在持久化时(不在事务中保存,在事务中提交)抛出。执行此验证的时间可能会有所不同。VersionException
将立即抛出,无论是在分派时(保存是否包含事务)还是在持久化时(保存而不包含事务,在事务中提交),如果此节点由于其原因是只读的,或者它上面的节点正在被检入,则在执行此验证时,实现可能会有所不同。
如果锁阻止重新订购,将立即(通过此方法)或在save
上抛出LockException
。执行此验证的时间可能会有所不同。
代码示例来源:origin: org.onehippo.cms7/hippo-repository-connector
/**
* @inheritDoc
*/
public void orderBefore(String srcChildRelPath, String destChildRelPath)
throws UnsupportedRepositoryOperationException, VersionException, ConstraintViolationException,
ItemNotFoundException, LockException, RepositoryException {
node.orderBefore(srcChildRelPath, destChildRelPath);
}
代码示例来源:origin: info.magnolia/magnolia-core
/**
* Orders the node last among its siblings.
*/
public static void orderLast(Node node) throws RepositoryException {
node.getParent().orderBefore(node.getName(), null);
}
代码示例来源:origin: info.magnolia/magnolia-core
/**
* Convenience - delegate to {@link Node#orderBefore(String, String)}.
*/
public static void orderBefore(Node node, String siblingName) throws RepositoryException {
node.getParent().orderBefore(node.getName(), siblingName);
}
代码示例来源:origin: info.magnolia/magnolia-core
/**
* Orders the node first among its siblings.
*/
public static void orderFirst(Node node) throws RepositoryException {
Node parent = node.getParent();
NodeIterator siblings = parent.getNodes();
Node firstSibling = siblings.nextNode();
if (!firstSibling.isSame(node)) {
parent.orderBefore(node.getName(), firstSibling.getName());
}
}
代码示例来源:origin: info.magnolia/magnolia-core
/**
* Orders the node down one step among its siblings. If the node is the only sibling or the last sibling this method
* has no effect.
*/
public static void orderNodeDown(Node node) throws RepositoryException {
Node siblingAfter = getSiblingAfter(node);
if (siblingAfter != null) {
node.getParent().orderBefore(siblingAfter.getName(), node.getName());
}
}
代码示例来源:origin: info.magnolia/magnolia-core
public static void moveNodeBefore(Node nodeToMove, Node target) throws RepositoryException {
Node targetParent = target.getParent();
moveNode(nodeToMove, targetParent);
targetParent.orderBefore(nodeToMove.getName(), target.getName());
}
代码示例来源:origin: info.magnolia/magnolia-core
/**
* Orders the node up one step among its siblings. If the node is the only sibling or the first sibling this method
* has no effect.
*/
public static void orderNodeUp(Node node) throws RepositoryException {
Node siblingBefore = getSiblingBefore(node);
if (siblingBefore != null) {
node.getParent().orderBefore(node.getName(), siblingBefore.getName());
}
}
代码示例来源:origin: info.magnolia/magnolia-core
public static void renameNode(Node node, String newName) throws RepositoryException {
if (node.getName().equals(newName)) {
return;
}
final Node parent = node.getParent();
final String newPath = combinePathAndName(parent.getPath(), newName);
final Node siblingAfter = NodeUtil.getSiblingAfter(node);
node.getSession().move(node.getPath(), newPath);
if (siblingAfter != null) {
parent.orderBefore(newName, siblingAfter.getName());
}
}
代码示例来源:origin: info.magnolia/magnolia-core
@Override
protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException {
final Node node = installContext.getJCRSession(repository).getNode(path);
node.getParent().orderBefore(node.getName(), orderBeforeNodeName);
}
代码示例来源:origin: apache/jackrabbit-oak
@Test
public void orderSameNode() throws Exception {
Session session = getAdminSession();
Node n = session.getRootNode().addNode("test", "nt:unstructured");
Node a = n.addNode("a");
n.orderBefore("a", "a");
}
代码示例来源:origin: apache/jackrabbit
public void testReorderWithAdd() throws Exception {
testRootNode.orderBefore("C", "A");
session.getNode(testRoot).addNode("D");
session.save();
try {
superuser.save();
fail("must throw InvalidItemStateException");
} catch (InvalidItemStateException e) {
// expected
}
}
代码示例来源:origin: apache/jackrabbit
@Override
public void testRevertReorderToEnd() throws RepositoryException {
testRootNode.orderBefore(getRelPath(child1), null);
testOrder(testRootNode, new Node[] { child2, child3, child4, child1});
// NEW child nodes -> must be removed upon refresh
testRootNode.refresh(false);
NodeIterator it = testRootNode.getNodes();
if (it.hasNext()) {
fail("Reverting creation and reordering of new children must remove the children again.");
}
}
}
代码示例来源:origin: apache/jackrabbit
@Override
public void testRevertReorderToEnd() throws RepositoryException {
testRootNode.orderBefore(getRelPath(child1), null);
testOrder(testRootNode, new Node[] { child2, child3, child4, child1});
// NEW child nodes -> must be removed upon refresh
testRootNode.refresh(false);
NodeIterator it = testRootNode.getNodes(nodeName2);
if (it.hasNext()) {
fail("Reverting creation and reordering of new SNSs must remove the children again.");
}
}
}
代码示例来源:origin: apache/jackrabbit
public void testReorderTwice() throws RepositoryException {
testRootNode.orderBefore(getRelPath(child2), null);
testRootNode.orderBefore(getRelPath(child4), getRelPath(child1));
testOrder(testRootNode, new Node[] { child4, child1, child3, child2});
testRootNode.save();
testOrder(testRootNode, new Node[] { child4, child1, child3, child2});
}
代码示例来源:origin: apache/jackrabbit
@Override
public void testRevertReorder() throws RepositoryException {
testRootNode.orderBefore(getRelPath(child4), getRelPath(child2));
testOrder(testRootNode, new Node[] { child1, child4, child2, child3});
// NEW child nodes -> must be removed upon refresh
testRootNode.refresh(false);
NodeIterator it = testRootNode.getNodes();
if (it.hasNext()) {
fail("Reverting creation and reordering of new children must remove the children again.");
}
}
代码示例来源:origin: apache/jackrabbit
public void testReorder3() throws RepositoryException {
String pathBefore = child3.getPath();
testRootNode.orderBefore(getRelPath(child3), getRelPath(child1));
testRootNode.save();
Item itemIndex3 = testRootNode.getSession().getItem(pathBefore);
assertTrue(itemIndex3.isSame(child2));
Item item3 = testRootNode.getSession().getItem(child3.getPath());
assertTrue(item3.isSame(child3));
}
}
代码示例来源:origin: apache/jackrabbit
public void testReorderToEnd() throws RepositoryException, ConstraintViolationException, UnsupportedRepositoryOperationException, VersionException {
testRootNode.orderBefore(getRelPath(child2), null);
testOrder(testRootNode, new Node[] { child1, child3, child4, child2});
testRootNode.save();
testOrder(testRootNode, new Node[] { child1, child3, child4, child2});
}
代码示例来源:origin: apache/jackrabbit-oak
@Test
public void testReorder3() throws Exception {
Node n = testSession.getNode(path);
// give 'add_child_nodes', 'nt-management' and 'remove_child_nodes' at
// 'path' -> reorder must succeed
allow(path, privilegesFromNames(new String[] {Privilege.JCR_ADD_CHILD_NODES,
Privilege.JCR_REMOVE_CHILD_NODES, Privilege.JCR_NODE_TYPE_MANAGEMENT}));
n.orderBefore(Text.getName(childNPath2), Text.getName(childNPath));
testSession.save();
}
代码示例来源:origin: apache/jackrabbit
@Override
public void testRevertReorder() throws RepositoryException {
testRootNode.orderBefore(getRelPath(child4), getRelPath(child2));
testOrder(testRootNode, new Node[] { child1, child4, child2, child3});
testRootNode.refresh(false);
testOrder(testRootNode, new Node[] { child1, child2 });
}
代码示例来源:origin: apache/jackrabbit
public void testReorder() throws RepositoryException {
testRootNode.orderBefore(getRelPath(child1), getRelPath(child3));
testOrder(testRootNode, new Node[] { child2, child1, child3, child4});
testRootNode.save();
testOrder(testRootNode, new Node[] { child2, child1, child3, child4});
}
内容来源于网络,如有侵权,请联系作者删除!