本文整理了Java中javax.jcr.Node.getAncestor()
方法的一些代码示例,展示了Node.getAncestor()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.getAncestor()
方法的具体详情如下:
包路径:javax.jcr.Node
类名称:Node
方法名:getAncestor
暂无
代码示例来源:origin: info.magnolia/magnolia-core
@Override
public Item getAncestor(int depth) throws ItemNotFoundException, AccessDeniedException, RepositoryException {
return this.baseNode.getAncestor(depth);
}
代码示例来源:origin: apache/jackrabbit
/**
* Test if getting the ancestor of negative depth throws an
* <code>ItemNotFoundException</code>.
*/
public void testGetAncestorOfNegativeDepth() throws RepositoryException {
try {
testRootNode.getAncestor(-1);
fail("Getting ancestor of depth < 0 must throw an ItemNotFoundException.");
} catch (ItemNotFoundException e) {
// success
}
}
代码示例来源:origin: info.magnolia/magnolia-core
@Override
public Item getAncestor(int depth) throws ItemNotFoundException, AccessDeniedException, RepositoryException {
return getWrappedNode().getAncestor(depth);
}
代码示例来源:origin: nl.vpro/jcr-criteria
@Override
public Item getAncestor(int depth) throws RepositoryException {
return getNode().getAncestor(depth);
}
代码示例来源:origin: info.magnolia/magnolia-core
/**
* Get all Ancestors until level 1.
*/
public static Collection<Node> getAncestors(Node node) throws RepositoryException {
List<Node> allAncestors = new ArrayList<Node>();
int level = node.getDepth();
while (level != 0) {
try {
allAncestors.add((Node) node.getAncestor(--level));
} catch (AccessDeniedException e) {
log.debug("Node {} didn't allow access to Ancestor's ", node.getIdentifier());
}
}
return allAncestors;
}
代码示例来源:origin: apache/jackrabbit
/**
* Test if getting the ancestor of depth = n, where n is greater than depth
* of this <code>Node</code>, throws an <code>ItemNotFoundException</code>.
*/
public void testGetAncestorOfGreaterDepth() throws RepositoryException {
try {
int greaterDepth = testRootNode.getDepth() + 1;
testRootNode.getAncestor(greaterDepth);
fail("Getting ancestor of depth n, where n is greater than depth of" +
"this Node must throw an ItemNotFoundException");
} catch (ItemNotFoundException e) {
// success
}
}
代码示例来源:origin: info.magnolia/magnolia-core
@Override
public Content getAncestor(int level) throws PathNotFoundException, RepositoryException, AccessDeniedException {
if (level > this.getLevel()) {
throw new PathNotFoundException();
}
return wrapAsContent((Node) this.node.getAncestor(level));
}
代码示例来源:origin: apache/jackrabbit
/**
* Test if the ancestor at depth = n, where n is the depth of this
* <code>Item</code>, returns this <code>Node</code> itself.
*/
public void testGetAncestorOfNodeDepth() throws RepositoryException {
Node nodeAtDepth = (Node) testRootNode.getAncestor(testRootNode.getDepth());
assertTrue("The ancestor of depth = n, where n is the depth of this " +
"Node must be the item itself.", testRootNode.isSame(nodeAtDepth));
}
代码示例来源:origin: org.onehippo.cms7/hippo-repository-engine
@Override
protected void leaving(Node node, int level) throws RepositoryException {
if (node.isNodeType(HippoNodeType.NT_DERIVED)) {
if (!node.isCheckedOut()) {
for (int depth = node.getDepth(); depth > 0; depth--) {
Node ancestor = (Node) node.getAncestor(depth);
if (ancestor.isNodeType("mix:versionable")) {
ancestor.checkout();
break;
}
}
}
node.setProperty("hippo:compute", (String) null);
}
}
});
代码示例来源:origin: org.onehippo.cms7/hippo-repository-workflow
public Document copyFrom(Document offspring, Document targetFolder, String targetName, Map<String,String> arguments)
throws WorkflowException, MappingException, RepositoryException, RemoteException {
if (targetName == null || targetName.equals("")) {
throw new WorkflowException("No target name given");
}
String path = subject.getPath().substring(1);
Node folder = (path.equals("") ? rootSession.getRootNode() : rootSession.getRootNode().getNode(path));
Node destination = targetFolder.getNode(rootSession);
Node source = offspring.getNode(rootSession);
if (folder.isSame(destination)) {
//throw new WorkflowException("Cannot copy document to same folder, use duplicate instead");
return duplicate(source, targetName);
}
if (source.getAncestor(folder.getDepth()).isSame(folder)) {
return ((EmbedWorkflow)workflowContext.getWorkflow("embedded", new Document(destination))).copyTo(new Document(subject), offspring, targetName, arguments);
}
return null;
}
代码示例来源:origin: org.onehippo.cms7/hippo-repository-workflow
public Document moveFrom(Document offspring, Document targetFolder, String targetName, Map<String,String> arguments)
throws WorkflowException, MappingException, RepositoryException, RemoteException {
String path = subject.getPath().substring(1);
Node folder = (path.equals("") ? rootSession.getRootNode() : rootSession.getRootNode().getNode(path));
Node destination = targetFolder.getNode(rootSession);
if (folder.isSame(destination)) {
throw new WorkflowException("Cannot move document to same folder");
}
Node source = offspring.getNode(rootSession);
if (!folder.isCheckedOut()) {
folder.checkout();
}
if (source.getAncestor(folder.getDepth()).isSame(folder)) {
((EmbedWorkflow)workflowContext.getWorkflow("internal", new Document(destination))).moveTo(new Document(subject), offspring, targetName, arguments);
}
return null;
}
代码示例来源:origin: info.magnolia/magnolia-core
@Test(expected = ItemNotFoundException.class)
public void testGetAncestorWithNegativeDepth() throws Exception {
// GIVEN
final Node sub1 = root.addNode("sub1");
// WHEN
sub1.getAncestor(-1);
}
代码示例来源:origin: info.magnolia/magnolia-core
@Test(expected = ItemNotFoundException.class)
public void testGetAncestorWithToBigDepth() throws Exception {
// GIVEN
final Node sub1 = root.addNode("sub1");
// WHEN
sub1.getAncestor(3);
}
代码示例来源:origin: info.magnolia/magnolia-core
@Test
public void testGetAncestor() throws Exception {
// GIVEN
final Node sub1 = root.addNode("sub1");
final Node sub2 = sub1.addNode("sub2");
// WHEN
Item result = sub2.getAncestor(1);
// THEN
assertEquals(sub1, result);
}
代码示例来源:origin: info.magnolia/magnolia-templating
/**
* Returns the *oldest* ancestor node of the provided node which has the specified nodeType.
*/
public Node root(Node content, String nodeTypeName) throws RepositoryException {
if (content == null) {
return null;
}
if (nodeTypeName == null) {
return (Node) content.getAncestor(0);
}
if (isRoot(content) && content.isNodeType(nodeTypeName)) {
return content;
}
Node parentNode = this.parent(content, nodeTypeName);
while (parent(parentNode, nodeTypeName) != null) {
parentNode = this.parent(parentNode, nodeTypeName);
}
return parentNode;
}
代码示例来源:origin: info.magnolia/magnolia-module-standard-templating-kit
private NavigationModel createVerticalNavigation() throws RepositoryException {
int startLevel = siteRoot.getDepth();
boolean rootIsHome = true;
if (isShowHorizontalNavigation()) {
startLevel = getStartLevel();
rootIsHome = false;
}
Node root = (Node) currentNode.getAncestor(startLevel);
boolean allOpen = siteNavigation.getVertical().getAllOpen();
return new NavigationModel(root, currentNode, getVerticalLevel(), allOpen, rootIsHome);
}
代码示例来源:origin: apache/jackrabbit
public void testRefreshMovedTree() throws RepositoryException {
testRootNode.refresh(true);
String msg = "Refresh must not revert a moved tree.";
assertFalse(msg, superuser.itemExists(srcPath + "/" + nodeName2 + "/" + nodeName3));
int degree = destParentNode.getDepth();
List<Item> l = new ArrayList<Item>();
l.add(childNode);
l.add(childProperty);
l.add(grandChildNode);
for (Iterator<Item> it = l.iterator(); it.hasNext();) {
Item item = it.next();
assertTrue(msg, item.isNew());
assertTrue(msg, childNode.getAncestor(degree).isSame(destParentNode));
}
}
}
代码示例来源:origin: apache/jackrabbit
public void testTreeAncestors() throws RepositoryException {
int degree = destParentNode.getDepth();
Item ancestor = childNode.getAncestor(degree);
assertTrue("Moving a node must move all child items as well.", ancestor.isSame(destParentNode));
ancestor = childProperty.getAncestor(degree);
assertTrue("Moving a node must move all child items as well.", ancestor.isSame(destParentNode));
ancestor = grandChildNode.getAncestor(degree);
assertTrue("Moving a node must move all child items as well.", ancestor.isSame(destParentNode));
}
代码示例来源:origin: apache/jackrabbit
public void testTreeAncestors() throws RepositoryException {
int degree = destParentNode.getDepth();
Item ancestor = childNode.getAncestor(degree);
assertTrue("Moving a node must move all child items as well.", ancestor.isSame(destParentNode));
ancestor = childProperty.getAncestor(degree);
assertTrue("Moving a node must move all child items as well.", ancestor.isSame(destParentNode));
ancestor = grandChildNode.getAncestor(degree);
assertTrue("Moving a node must move all child items as well.", ancestor.isSame(destParentNode));
}
代码示例来源:origin: apache/jackrabbit
public void testAncestorAfterRevert() throws RepositoryException {
superuser.refresh(false);
Item ancestor = grandChildNode.getAncestor(srcParentNode.getDepth());
assertTrue("Reverting a move-operation must move the tree back.", ancestor.isSame(srcParentNode));
}
内容来源于网络,如有侵权,请联系作者删除!