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

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

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

Node.getIndex介绍

[英]This method returns the index of this node within the ordered set of its same-name sibling nodes. This index is the one used to address same-name siblings using the square-bracket notation, e.g., /a[3]/b[4]. Note that the index always starts at 1 (not 0), for compatibility with XPath. As a result, for nodes that do not have same-name-siblings, this method will always return 1.
[中]此方法返回该节点在其同名同级节点的有序集中的索引。此索引用于使用方括号表示法(例如,/a[3]/b[4])来表示同名同级。注意,为了与XPath兼容,索引总是从1(而不是0)开始。因此,对于没有同名同级的节点,此方法将始终返回1。

代码示例

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

  1. /**
  2. * @inheritDoc
  3. */
  4. public int getIndex() throws RepositoryException {
  5. return node.getIndex();
  6. }

代码示例来源:origin: org.apache.sling/org.apache.sling.scripting.javascript

  1. public int jsFunction_getIndex() {
  2. try {
  3. return node.getIndex();
  4. } catch (RepositoryException re) {
  5. return 1;
  6. }
  7. }

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

  1. @Override
  2. public int getIndex() throws RepositoryException {
  3. return this.node.getIndex();
  4. }

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

  1. private String nameOf( Node node ) throws RepositoryException {
  2. int index = node.getIndex();
  3. String childName = node.getName();
  4. return index == 1 ? childName : childName + "[" + index + "]";
  5. }

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

  1. protected String nodeName( Node node ) throws RepositoryException {
  2. int index = node.getIndex();
  3. String name = node.getName();
  4. if (index != 1) name = name + "[" + index + "]";
  5. return name;
  6. }

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

  1. protected static List<String> namesOfChildren( Node node ) throws RepositoryException {
  2. List<String> children = new LinkedList<String>();
  3. for (NodeIterator iter = node.getNodes(); iter.hasNext();) {
  4. Node child = iter.nextNode();
  5. String name = child.getIndex() == 1 ? child.getName() : child.getName() + "[" + child.getIndex() + "]";
  6. children.add(name);
  7. }
  8. return children;
  9. }

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

  1. /** {@inheritDoc} */
  2. public int getIndex() throws RepositoryException, RemoteException {
  3. try {
  4. return node.getIndex();
  5. } catch (RepositoryException ex) {
  6. throw getRepositoryException(ex);
  7. }
  8. }

代码示例来源:origin: stackoverflow.com

  1. // loop to get each item from ArrayList
  2. for( int i = 0; i < web.size(); i++ ){
  3. // get a node from array
  4. Node thisNode = (Node)web.get(i);
  5. // print its title
  6. System.out.println( thisNode.getTitle() );
  7. // print other properties if needed
  8. System.out.println( thisNode.getIndex() );
  9. }

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

  1. @Override
  2. public int getIndex() throws RepositoryException {
  3. return getWrappedNode().getIndex();
  4. }

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

  1. protected String createNodeName(final Node sourceNode) throws RepositoryException {
  2. final String name = sourceNode.getName();
  3. if (sourceNode.getIndex() > 1) {
  4. return name + "[" + sourceNode.getIndex() + "]";
  5. } else {
  6. if (sourceNode.getDefinition().allowsSameNameSiblings() && sourceNode.getParent().hasNode(name + "[2]")) {
  7. return name + "[1]";
  8. }
  9. }
  10. return name;
  11. }

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

  1. protected Node getParentNode( Property property ) throws RepositoryException {
  2. Node parentNode = property.getParent();
  3. if (JcrConstants.JCR_CONTENT.equalsIgnoreCase(parentNode.getName()) && parentNode.getIndex() == 1) {
  4. parentNode = parentNode.getParent();
  5. }
  6. return parentNode;
  7. }

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

  1. private void saveState() throws RepositoryException {
  2. // save top-level nodes for tearDown validation
  3. topLevelNodes = new HashSet<String>();
  4. for (Node node : new NodeIterable(session.getRootNode().getNodes())) {
  5. topLevelNodes.add(node.getName() + "[" + node.getIndex() + "]");
  6. }
  7. jcrStates = new ArrayList<>();
  8. for (String pathToCheck : getPathsToCheck()) {
  9. jcrStates.add(new JcrState(pathToCheck, session, log));
  10. }
  11. }

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

  1. @Override
  2. protected Node doExecute(Node node) throws Exception {
  3. Node parent = node.getParent();
  4. context.getFolderWorkflow(parent).delete(node.getName() + (node.getIndex() > 1 ? "[" + node.getIndex() + "]" : ""));
  5. parent.getSession().refresh(false);
  6. return parent;
  7. }

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

  1. private static void checkIndex(Node node, int expectedIndex) throws RepositoryException {
  2. int index = node.getIndex();
  3. if (index != expectedIndex) {
  4. fail("Unexpected index " + index + ". Expected index was " + expectedIndex);
  5. }
  6. }
  7. }

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

  1. /**
  2. * Implementation specific:
  3. * Same as {@link #testMovedNodeGetPath()}, but calls save prior to the
  4. * test.
  5. */
  6. public void testMovedNodeGetPath2() throws RepositoryException, NotExecutableException {
  7. int index = destSibling.getIndex() + 1;
  8. //move the node
  9. doMove(moveNode.getPath(), destParentNode.getPath() + "/" + nodeName2);
  10. superuser.save();
  11. assertEquals("After successful move the moved node must return the destination path.", destinationPath + "["+ index +"]", moveNode.getPath());
  12. }

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

  1. /**
  2. * Implementation specific:
  3. * Test if the path of a moved node, contains the index of the last sibling.
  4. */
  5. public void testMovedNodeGetPath() throws RepositoryException, NotExecutableException {
  6. int index = destSibling.getIndex() + 1;
  7. //move the node
  8. doMove(moveNode.getPath(),destinationPath);
  9. assertEquals("After successful move the moved node must return the destination path.", destinationPath + "["+ index +"]", moveNode.getPath());
  10. }

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

  1. public void testIndexAfterReorder() throws RepositoryException {
  2. testRootNode.orderBefore(getRelPath(child1), getRelPath(child3));
  3. assertTrue(child1.getIndex() == 2);
  4. assertTrue(child2.getIndex() == 1);
  5. assertTrue(child3.getIndex() == 3);
  6. assertTrue(child4.getIndex() == 4);
  7. testRootNode.save();
  8. assertTrue(child1.getIndex() == 2);
  9. assertTrue(child2.getIndex() == 1);
  10. assertTrue(child3.getIndex() == 3);
  11. assertTrue(child4.getIndex() == 4);
  12. }

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

  1. protected void assertFolder( Node node,
  2. File dir ) throws Exception {
  3. assertThat(dir.exists(), is(true));
  4. assertThat(dir.canRead(), is(true));
  5. assertThat(dir.isDirectory(), is(true));
  6. assertThat(node.getName(), is(dir.getName()));
  7. assertThat(node.getIndex(), is(1));
  8. assertThat(node.getPrimaryNodeType().getName(), is("nt:folder"));
  9. assertThat(node.getProperty("jcr:created").getLong(), is(createdTimeFor(dir)));
  10. }

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

  1. protected void assertFile( Node node,
  2. File file ) throws Exception {
  3. assertThat(node.getName(), is(file.getName()));
  4. assertThat(node.getIndex(), is(1));
  5. assertThat(node.getPrimaryNodeType().getName(), is("nt:file"));
  6. assertThat(node.getProperty("jcr:created").getLong(), is(createdTimeFor(file)));
  7. Node content = node.getNode("jcr:content");
  8. assertThat(content.getName(), is("jcr:content"));
  9. assertThat(content.getIndex(), is(1));
  10. assertThat(content.getPrimaryNodeType().getName(), is("nt:resource"));
  11. assertThat(content.getProperty("jcr:lastModified").getLong(), is(file.lastModified()));
  12. }

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

  1. @Test
  2. public void shouldHaveSameNameSiblingIndex() throws Exception {
  3. assertThat(altima.getIndex(), is(1));
  4. javax.jcr.Node altima2 = hybrid.addNode("Nissan Altima");
  5. try {
  6. assertThat(altima2, is(notNullValue()));
  7. assertThat(altima2.getIndex(), is(2));
  8. } finally {
  9. altima2.remove(); // remove the node we added in this test to not interfere with other tests
  10. }
  11. }

相关文章