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

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

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

Node.getAncestor介绍

暂无

代码示例

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

  1. @Override
  2. public Item getAncestor(int depth) throws ItemNotFoundException, AccessDeniedException, RepositoryException {
  3. return this.baseNode.getAncestor(depth);
  4. }

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

  1. /**
  2. * Test if getting the ancestor of negative depth throws an
  3. * <code>ItemNotFoundException</code>.
  4. */
  5. public void testGetAncestorOfNegativeDepth() throws RepositoryException {
  6. try {
  7. testRootNode.getAncestor(-1);
  8. fail("Getting ancestor of depth < 0 must throw an ItemNotFoundException.");
  9. } catch (ItemNotFoundException e) {
  10. // success
  11. }
  12. }

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

  1. @Override
  2. public Item getAncestor(int depth) throws ItemNotFoundException, AccessDeniedException, RepositoryException {
  3. return getWrappedNode().getAncestor(depth);
  4. }

代码示例来源:origin: nl.vpro/jcr-criteria

  1. @Override
  2. public Item getAncestor(int depth) throws RepositoryException {
  3. return getNode().getAncestor(depth);
  4. }

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

  1. /**
  2. * Get all Ancestors until level 1.
  3. */
  4. public static Collection<Node> getAncestors(Node node) throws RepositoryException {
  5. List<Node> allAncestors = new ArrayList<Node>();
  6. int level = node.getDepth();
  7. while (level != 0) {
  8. try {
  9. allAncestors.add((Node) node.getAncestor(--level));
  10. } catch (AccessDeniedException e) {
  11. log.debug("Node {} didn't allow access to Ancestor's ", node.getIdentifier());
  12. }
  13. }
  14. return allAncestors;
  15. }

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

  1. /**
  2. * Test if getting the ancestor of depth = n, where n is greater than depth
  3. * of this <code>Node</code>, throws an <code>ItemNotFoundException</code>.
  4. */
  5. public void testGetAncestorOfGreaterDepth() throws RepositoryException {
  6. try {
  7. int greaterDepth = testRootNode.getDepth() + 1;
  8. testRootNode.getAncestor(greaterDepth);
  9. fail("Getting ancestor of depth n, where n is greater than depth of" +
  10. "this Node must throw an ItemNotFoundException");
  11. } catch (ItemNotFoundException e) {
  12. // success
  13. }
  14. }

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

  1. @Override
  2. public Content getAncestor(int level) throws PathNotFoundException, RepositoryException, AccessDeniedException {
  3. if (level > this.getLevel()) {
  4. throw new PathNotFoundException();
  5. }
  6. return wrapAsContent((Node) this.node.getAncestor(level));
  7. }

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

  1. /**
  2. * Test if the ancestor at depth = n, where n is the depth of this
  3. * <code>Item</code>, returns this <code>Node</code> itself.
  4. */
  5. public void testGetAncestorOfNodeDepth() throws RepositoryException {
  6. Node nodeAtDepth = (Node) testRootNode.getAncestor(testRootNode.getDepth());
  7. assertTrue("The ancestor of depth = n, where n is the depth of this " +
  8. "Node must be the item itself.", testRootNode.isSame(nodeAtDepth));
  9. }

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

  1. @Override
  2. protected void leaving(Node node, int level) throws RepositoryException {
  3. if (node.isNodeType(HippoNodeType.NT_DERIVED)) {
  4. if (!node.isCheckedOut()) {
  5. for (int depth = node.getDepth(); depth > 0; depth--) {
  6. Node ancestor = (Node) node.getAncestor(depth);
  7. if (ancestor.isNodeType("mix:versionable")) {
  8. ancestor.checkout();
  9. break;
  10. }
  11. }
  12. }
  13. node.setProperty("hippo:compute", (String) null);
  14. }
  15. }
  16. });

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

  1. public Document copyFrom(Document offspring, Document targetFolder, String targetName, Map<String,String> arguments)
  2. throws WorkflowException, MappingException, RepositoryException, RemoteException {
  3. if (targetName == null || targetName.equals("")) {
  4. throw new WorkflowException("No target name given");
  5. }
  6. String path = subject.getPath().substring(1);
  7. Node folder = (path.equals("") ? rootSession.getRootNode() : rootSession.getRootNode().getNode(path));
  8. Node destination = targetFolder.getNode(rootSession);
  9. Node source = offspring.getNode(rootSession);
  10. if (folder.isSame(destination)) {
  11. //throw new WorkflowException("Cannot copy document to same folder, use duplicate instead");
  12. return duplicate(source, targetName);
  13. }
  14. if (source.getAncestor(folder.getDepth()).isSame(folder)) {
  15. return ((EmbedWorkflow)workflowContext.getWorkflow("embedded", new Document(destination))).copyTo(new Document(subject), offspring, targetName, arguments);
  16. }
  17. return null;
  18. }

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

  1. public Document moveFrom(Document offspring, Document targetFolder, String targetName, Map<String,String> arguments)
  2. throws WorkflowException, MappingException, RepositoryException, RemoteException {
  3. String path = subject.getPath().substring(1);
  4. Node folder = (path.equals("") ? rootSession.getRootNode() : rootSession.getRootNode().getNode(path));
  5. Node destination = targetFolder.getNode(rootSession);
  6. if (folder.isSame(destination)) {
  7. throw new WorkflowException("Cannot move document to same folder");
  8. }
  9. Node source = offspring.getNode(rootSession);
  10. if (!folder.isCheckedOut()) {
  11. folder.checkout();
  12. }
  13. if (source.getAncestor(folder.getDepth()).isSame(folder)) {
  14. ((EmbedWorkflow)workflowContext.getWorkflow("internal", new Document(destination))).moveTo(new Document(subject), offspring, targetName, arguments);
  15. }
  16. return null;
  17. }

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

  1. @Test(expected = ItemNotFoundException.class)
  2. public void testGetAncestorWithNegativeDepth() throws Exception {
  3. // GIVEN
  4. final Node sub1 = root.addNode("sub1");
  5. // WHEN
  6. sub1.getAncestor(-1);
  7. }

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

  1. @Test(expected = ItemNotFoundException.class)
  2. public void testGetAncestorWithToBigDepth() throws Exception {
  3. // GIVEN
  4. final Node sub1 = root.addNode("sub1");
  5. // WHEN
  6. sub1.getAncestor(3);
  7. }

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

  1. @Test
  2. public void testGetAncestor() throws Exception {
  3. // GIVEN
  4. final Node sub1 = root.addNode("sub1");
  5. final Node sub2 = sub1.addNode("sub2");
  6. // WHEN
  7. Item result = sub2.getAncestor(1);
  8. // THEN
  9. assertEquals(sub1, result);
  10. }

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

  1. /**
  2. * Returns the *oldest* ancestor node of the provided node which has the specified nodeType.
  3. */
  4. public Node root(Node content, String nodeTypeName) throws RepositoryException {
  5. if (content == null) {
  6. return null;
  7. }
  8. if (nodeTypeName == null) {
  9. return (Node) content.getAncestor(0);
  10. }
  11. if (isRoot(content) && content.isNodeType(nodeTypeName)) {
  12. return content;
  13. }
  14. Node parentNode = this.parent(content, nodeTypeName);
  15. while (parent(parentNode, nodeTypeName) != null) {
  16. parentNode = this.parent(parentNode, nodeTypeName);
  17. }
  18. return parentNode;
  19. }

代码示例来源:origin: info.magnolia/magnolia-module-standard-templating-kit

  1. private NavigationModel createVerticalNavigation() throws RepositoryException {
  2. int startLevel = siteRoot.getDepth();
  3. boolean rootIsHome = true;
  4. if (isShowHorizontalNavigation()) {
  5. startLevel = getStartLevel();
  6. rootIsHome = false;
  7. }
  8. Node root = (Node) currentNode.getAncestor(startLevel);
  9. boolean allOpen = siteNavigation.getVertical().getAllOpen();
  10. return new NavigationModel(root, currentNode, getVerticalLevel(), allOpen, rootIsHome);
  11. }

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

  1. public void testRefreshMovedTree() throws RepositoryException {
  2. testRootNode.refresh(true);
  3. String msg = "Refresh must not revert a moved tree.";
  4. assertFalse(msg, superuser.itemExists(srcPath + "/" + nodeName2 + "/" + nodeName3));
  5. int degree = destParentNode.getDepth();
  6. List<Item> l = new ArrayList<Item>();
  7. l.add(childNode);
  8. l.add(childProperty);
  9. l.add(grandChildNode);
  10. for (Iterator<Item> it = l.iterator(); it.hasNext();) {
  11. Item item = it.next();
  12. assertTrue(msg, item.isNew());
  13. assertTrue(msg, childNode.getAncestor(degree).isSame(destParentNode));
  14. }
  15. }
  16. }

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

  1. public void testTreeAncestors() throws RepositoryException {
  2. int degree = destParentNode.getDepth();
  3. Item ancestor = childNode.getAncestor(degree);
  4. assertTrue("Moving a node must move all child items as well.", ancestor.isSame(destParentNode));
  5. ancestor = childProperty.getAncestor(degree);
  6. assertTrue("Moving a node must move all child items as well.", ancestor.isSame(destParentNode));
  7. ancestor = grandChildNode.getAncestor(degree);
  8. assertTrue("Moving a node must move all child items as well.", ancestor.isSame(destParentNode));
  9. }

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

  1. public void testTreeAncestors() throws RepositoryException {
  2. int degree = destParentNode.getDepth();
  3. Item ancestor = childNode.getAncestor(degree);
  4. assertTrue("Moving a node must move all child items as well.", ancestor.isSame(destParentNode));
  5. ancestor = childProperty.getAncestor(degree);
  6. assertTrue("Moving a node must move all child items as well.", ancestor.isSame(destParentNode));
  7. ancestor = grandChildNode.getAncestor(degree);
  8. assertTrue("Moving a node must move all child items as well.", ancestor.isSame(destParentNode));
  9. }

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

  1. public void testAncestorAfterRevert() throws RepositoryException {
  2. superuser.refresh(false);
  3. Item ancestor = grandChildNode.getAncestor(srcParentNode.getDepth());
  4. assertTrue("Reverting a move-operation must move the tree back.", ancestor.isSame(srcParentNode));
  5. }

相关文章