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

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

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

Node.getNodes介绍

[英]Returns all child nodes of this node accessible through the current Session. Does not include properties of this Node. The same reacquisition semantics apply as with #getNode(String). If this node has no accessible child nodes, then an empty iterator is returned.
[中]返回可通过当前Session访问的此节点的所有子节点。不包括此Node的属性。与#getNode(String)相同的重新获取语义也适用。如果该节点没有可访问的子节点,则返回一个空迭代器。

代码示例

代码示例来源:origin: javax.jcr/jcr

propIter.nextProperty().accept(this);
NodeIterator nodeIter = node.getNodes();
while (nodeIter.hasNext()) {
  nodeIter.nextNode().accept(this);
  nextQueue.addLast(propIter.nextProperty());
NodeIterator nodeIter = node.getNodes();
while (nodeIter.hasNext()) {
  nextQueue.addLast(nodeIter.nextNode());

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

private Node getFirstChild(Node parentNode, Collection<String> childNames) throws RepositoryException {
  NodeIterator nodes = parentNode.getNodes();
  while (nodes.hasNext()) {
    Node child = nodes.nextNode();
    if (childNames.contains(child.getName())) {
      return child;
    }
  }
  return null;
}

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

private void moveContainerItems(final Node from, final Node to) throws RepositoryException {
  Session session = from.getSession();
  for (Node fromChild : new NodeIterable(from.getNodes())) {
    String newName = fromChild.getName();
    int counter = 0;
    while (to.hasNode(newName)) {
      newName = fromChild.getName() + ++counter;
    }
    session.move(fromChild.getPath(), to.getPath() + "/" + newName);
  }
}

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

protected void addContentIfEmpty( Session session ) throws Exception {
  if (session.getRootNode().getNodes().getSize() == 1L) {
    if (addedContent) {
      fail("Already added content and should see some existing content");
    }
    session.getRootNode().addNode("topLevel", "nt:unstructured");
    session.save();
    addedContent = true;
  }
}

代码示例来源: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: apache/jackrabbit

/**
 * Tests the <code>first()</code> function.
 * <p>
 * For configuration description see {@link XPathDocOrderTest}.
 */
public void testDocOrderFirstFunction() throws Exception {
  String xpath = xpathRoot + "/*[first()]";
  String resultPath = testRootNode.getNodes().nextNode().getPath();
  docOrderTest(new Statement(xpath, qsXPATH), resultPath);
}

代码示例来源:origin: com.thinkbiganalytics.kylo/kylo-metadata-modeshape

public void setMetrics(Set<Metric> metrics) {
  try {
    NodeIterator nodes = getNode().getNodes(METRICS);
    while (nodes.hasNext()) {
      Node metricNode = (Node) nodes.next();
      metricNode.remove();
    }
    for (Metric metric : metrics) {
      Node metricNode = getNode().addNode(METRICS, METRIC_TYPE);
      JcrPropertyUtil.setProperty(metricNode, NAME, metric.getClass().getSimpleName());
      JcrPropertyUtil.setProperty(metricNode, DESCRIPTION, metric.getDescription());
      JcrUtil.addGenericJson(metricNode, JSON, metric);
    }
  } catch (RepositoryException e) {
    throw new MetadataRepositoryException("Failed to retrieve the metric nodes", e);
  }
}

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

@Test
public void testImportCommandDuplicateName() throws Exception {
  // GIVEN
  doReturn(true).when(importCommand).checkPermissions(RepositoryConstants.WEBSITE, targetNode.getPath(), Permission.WRITE);
  targetNode.addNode("about", NodeTypes.Page.NAME);
  targetNode.getSession().save();
  // WHEN
  importCommand.execute(context);
  // THEN
  assertTrue(targetNode.hasNodes());
  assertEquals(2, targetNode.getNodes("about").getSize());
  assertTrue(targetNode.hasNode("about[2]/extras"));
  assertTrue(targetNode.hasNode("about[2]/extras/extras1"));
}

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

private static void dumpChanges(Node node, PrintWriter out) throws RepositoryException {
  if (node.isModified()) {
    out.println(node.getPath() + " is modified");
  } else if (node.isNew()) {
    out.println(node.getPath() + " is new");
  }
  for (Iterator iter = node.getNodes(); iter.hasNext(); ) {
    Node child = (Node) iter.next();
    dumpChanges(child, out);
  }
}

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

@Test
public void testOrdering() throws RepositoryException, TaskExecutionException {
  // GIVEN
  final Session session = new MockSession(RepositoryConstants.CONFIG);
  InstallContext ctx = mock(InstallContext.class);
  when(ctx.getJCRSession(RepositoryConstants.CONFIG)).thenReturn(session);
  Node parent = session.getRootNode();
  parent.addNode("A", NodeTypes.ContentNode.NAME);
  parent.addNode("B", NodeTypes.ContentNode.NAME);
  Node childC = parent.addNode("C", NodeTypes.ContentNode.NAME);
  final OrderNodeToFirstPositionTask nodeto1stPosTask = new OrderNodeToFirstPositionTask("order-C-tp1st-Pos", "orders the node 'C' to 1st position", RepositoryConstants.CONFIG, "C");
  // WHEN
  nodeto1stPosTask.doExecute(ctx);
  // THEN
  assertTrue(NodeUtil.isSame(childC, parent.getNodes().nextNode()));
}

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

private Node getLastChild(Node parent, Collection<String> childNames) throws RepositoryException {
  Node lastMatch = null;
  NodeIterator nodes = parent.getNodes();
  while (nodes.hasNext()) {
    Node child = nodes.nextNode();
    if (childNames.contains(child.getName())) {
      lastMatch = child;
    }
  }
  return lastMatch;
}

代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility

@Test
public void testDoesNothingGivenProperty() throws Exception {
  // GIVEN
  Node root = session.getRootNode();
  Node node = root.addNode("nodeName");
  node.setProperty("propertyName", "propertyValue");
  long nodeCountBefore = node.getNodes().getSize();
  DuplicateNodeAction action = new DuplicateNodeAction(definition, new JcrPropertyAdapter(node.getProperty("propertyName")), eventBus);
  // WHEN
  action.execute();
  // THEN
  assertEquals(nodeCountBefore, node.getNodes().getSize());
  assertFalse(node.hasNode("nodeName0"));
  assertTrue(eventBus.isEmpty());
}

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

private void assertNodeOrder(Node node, String[] names) throws RepositoryException {
    NodeIterator nodes = node.getNodes();
    for (String name : names) {
      Node childNode = nodes.nextNode();
      if (!childNode.getName().equals(name)) {
        fail("Expected [" + name + "] was [" + childNode.getName() + "]");
      }
    }
  }
}

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

private void removeContainerItems(final Node page) throws RepositoryException {
  final List<Node> containers = findContainers(page);
  for (Node container : containers) {
    for (Node child : new NodeIterable(container.getNodes())) {
      log.debug("Remove container item '{}' for container '{}'.", child.getName(), container.getPath());
      child.remove();
    }
  }
}

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

/**
 * Tests if &lt;somepath&gt;/% returns no nodes if node at &lt;somepath&gt;
 * is a leaf.
 * @throws NotExecutableException
 */
public void testDescendantLeaf() throws RepositoryException, NotExecutableException {
  // find leaf
  Node leaf = testRootNode;
  while (leaf.hasNodes()) {
    leaf = leaf.getNodes().nextNode();
  }
  String sql = getStatement(leaf.getPath() + "/%");
  executeSqlQuery(session, sql, new Node[0]);
}

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

@Test
public void shouldReturnEmptyIterator() throws RepositoryException {
  Node jcrRootNode = session.getRootNode();
  Node rootNode = jcrRootNode.addNode("mapSuperclassTest");
  Node newNode = rootNode.addNode("newNode");
  assertNotNull(newNode);
  NodeIterator nodeIterator = rootNode.getNodes("myMap");
  assertFalse(nodeIterator.hasNext());
  session.save();
  nodeIterator = rootNode.getNodes("myMap");
  assertFalse(nodeIterator.hasNext());
}

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

protected void exportNode(final Node sourceNode, final DefinitionNodeImpl parentNode, final Set<String> excludedPaths) throws RepositoryException {
  final String path = sourceNode.getPath();
  if (!isVirtual(sourceNode) && !shouldExcludeNode(path) && !excludedPaths.contains(path)) {
    final DefinitionNodeImpl definitionNode = parentNode.addNode(createNodeName(sourceNode));
    exportProperties(sourceNode, definitionNode);
    for (final Node childNode : new NodeIterable(sourceNode.getNodes())) {
      exportNode(childNode, definitionNode, excludedPaths);
    }
  }
}

代码示例来源:origin: com.cognifide.cq/cqsm-bundle

private List<String> crawl(final Node node) throws RepositoryException {
  List<String> paths = new ArrayList<>();
  paths.add(node.getPath());
  for (NodeIterator iter = node.getNodes(); iter.hasNext(); ) {
    paths.addAll(crawl(iter.nextNode()));
  }
  return paths;
}

代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility

@Test
public void doesNothingGivenProperty() throws Exception {
  // GIVEN
  Node node = root.addNode(NODE_NAME);
  node.setProperty("propertyName", "propertyValue");
  long nodeCountBefore = node.getNodes().getSize();
  AddNodeAction action = new AddNodeAction(definition, new JcrPropertyAdapter(node.getProperty("propertyName")), eventBus);
  // WHEN
  action.execute();
  // THEN
  assertEquals(nodeCountBefore, node.getNodes().getSize());
  assertFalse(node.hasNode(NEW_NODE_NAME));
  assertTrue(eventBus.isEmpty());
}

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

private void assertNodeOrder(Node node, String[] names) throws RepositoryException {
    NodeIterator nodes = node.getNodes();
    for (String name : names) {
      Node childNode = nodes.nextNode();
      if (!childNode.getName().equals(name)) {
        fail("Expected [" + name + "] was [" + childNode.getName() + "]");
      }
    }
  }
}

相关文章

微信公众号

最新文章

更多