本文整理了Java中javax.jcr.Node.getIndex()
方法的一些代码示例,展示了Node.getIndex()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.getIndex()
方法的具体详情如下:
包路径:javax.jcr.Node
类名称: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
/**
* @inheritDoc
*/
public int getIndex() throws RepositoryException {
return node.getIndex();
}
代码示例来源:origin: org.apache.sling/org.apache.sling.scripting.javascript
public int jsFunction_getIndex() {
try {
return node.getIndex();
} catch (RepositoryException re) {
return 1;
}
}
代码示例来源:origin: info.magnolia/magnolia-core
@Override
public int getIndex() throws RepositoryException {
return this.node.getIndex();
}
代码示例来源:origin: ModeShape/modeshape
private String nameOf( Node node ) throws RepositoryException {
int index = node.getIndex();
String childName = node.getName();
return index == 1 ? childName : childName + "[" + index + "]";
}
代码示例来源:origin: ModeShape/modeshape
protected String nodeName( Node node ) throws RepositoryException {
int index = node.getIndex();
String name = node.getName();
if (index != 1) name = name + "[" + index + "]";
return name;
}
代码示例来源:origin: ModeShape/modeshape
protected static List<String> namesOfChildren( Node node ) throws RepositoryException {
List<String> children = new LinkedList<String>();
for (NodeIterator iter = node.getNodes(); iter.hasNext();) {
Node child = iter.nextNode();
String name = child.getIndex() == 1 ? child.getName() : child.getName() + "[" + child.getIndex() + "]";
children.add(name);
}
return children;
}
代码示例来源:origin: apache/jackrabbit
/** {@inheritDoc} */
public int getIndex() throws RepositoryException, RemoteException {
try {
return node.getIndex();
} catch (RepositoryException ex) {
throw getRepositoryException(ex);
}
}
代码示例来源:origin: stackoverflow.com
// loop to get each item from ArrayList
for( int i = 0; i < web.size(); i++ ){
// get a node from array
Node thisNode = (Node)web.get(i);
// print its title
System.out.println( thisNode.getTitle() );
// print other properties if needed
System.out.println( thisNode.getIndex() );
}
代码示例来源:origin: info.magnolia/magnolia-core
@Override
public int getIndex() throws RepositoryException {
return getWrappedNode().getIndex();
}
代码示例来源:origin: org.onehippo.cms7/hippo-repository-engine
protected String createNodeName(final Node sourceNode) throws RepositoryException {
final String name = sourceNode.getName();
if (sourceNode.getIndex() > 1) {
return name + "[" + sourceNode.getIndex() + "]";
} else {
if (sourceNode.getDefinition().allowsSameNameSiblings() && sourceNode.getParent().hasNode(name + "[2]")) {
return name + "[1]";
}
}
return name;
}
代码示例来源:origin: ModeShape/modeshape
protected Node getParentNode( Property property ) throws RepositoryException {
Node parentNode = property.getParent();
if (JcrConstants.JCR_CONTENT.equalsIgnoreCase(parentNode.getName()) && parentNode.getIndex() == 1) {
parentNode = parentNode.getParent();
}
return parentNode;
}
代码示例来源:origin: org.onehippo.cms7/hippo-repository-testutils
private void saveState() throws RepositoryException {
// save top-level nodes for tearDown validation
topLevelNodes = new HashSet<String>();
for (Node node : new NodeIterable(session.getRootNode().getNodes())) {
topLevelNodes.add(node.getName() + "[" + node.getIndex() + "]");
}
jcrStates = new ArrayList<>();
for (String pathToCheck : getPathsToCheck()) {
jcrStates.add(new JcrState(pathToCheck, session, log));
}
}
代码示例来源:origin: org.onehippo.cms7/hippo-repository-testutils
@Override
protected Node doExecute(Node node) throws Exception {
Node parent = node.getParent();
context.getFolderWorkflow(parent).delete(node.getName() + (node.getIndex() > 1 ? "[" + node.getIndex() + "]" : ""));
parent.getSession().refresh(false);
return parent;
}
代码示例来源:origin: apache/jackrabbit
private static void checkIndex(Node node, int expectedIndex) throws RepositoryException {
int index = node.getIndex();
if (index != expectedIndex) {
fail("Unexpected index " + index + ". Expected index was " + expectedIndex);
}
}
}
代码示例来源:origin: apache/jackrabbit
/**
* Implementation specific:
* Same as {@link #testMovedNodeGetPath()}, but calls save prior to the
* test.
*/
public void testMovedNodeGetPath2() throws RepositoryException, NotExecutableException {
int index = destSibling.getIndex() + 1;
//move the node
doMove(moveNode.getPath(), destParentNode.getPath() + "/" + nodeName2);
superuser.save();
assertEquals("After successful move the moved node must return the destination path.", destinationPath + "["+ index +"]", moveNode.getPath());
}
代码示例来源:origin: apache/jackrabbit
/**
* Implementation specific:
* Test if the path of a moved node, contains the index of the last sibling.
*/
public void testMovedNodeGetPath() throws RepositoryException, NotExecutableException {
int index = destSibling.getIndex() + 1;
//move the node
doMove(moveNode.getPath(),destinationPath);
assertEquals("After successful move the moved node must return the destination path.", destinationPath + "["+ index +"]", moveNode.getPath());
}
代码示例来源:origin: apache/jackrabbit
public void testIndexAfterReorder() throws RepositoryException {
testRootNode.orderBefore(getRelPath(child1), getRelPath(child3));
assertTrue(child1.getIndex() == 2);
assertTrue(child2.getIndex() == 1);
assertTrue(child3.getIndex() == 3);
assertTrue(child4.getIndex() == 4);
testRootNode.save();
assertTrue(child1.getIndex() == 2);
assertTrue(child2.getIndex() == 1);
assertTrue(child3.getIndex() == 3);
assertTrue(child4.getIndex() == 4);
}
代码示例来源:origin: ModeShape/modeshape
protected void assertFolder( Node node,
File dir ) throws Exception {
assertThat(dir.exists(), is(true));
assertThat(dir.canRead(), is(true));
assertThat(dir.isDirectory(), is(true));
assertThat(node.getName(), is(dir.getName()));
assertThat(node.getIndex(), is(1));
assertThat(node.getPrimaryNodeType().getName(), is("nt:folder"));
assertThat(node.getProperty("jcr:created").getLong(), is(createdTimeFor(dir)));
}
代码示例来源:origin: ModeShape/modeshape
protected void assertFile( Node node,
File file ) throws Exception {
assertThat(node.getName(), is(file.getName()));
assertThat(node.getIndex(), is(1));
assertThat(node.getPrimaryNodeType().getName(), is("nt:file"));
assertThat(node.getProperty("jcr:created").getLong(), is(createdTimeFor(file)));
Node content = node.getNode("jcr:content");
assertThat(content.getName(), is("jcr:content"));
assertThat(content.getIndex(), is(1));
assertThat(content.getPrimaryNodeType().getName(), is("nt:resource"));
assertThat(content.getProperty("jcr:lastModified").getLong(), is(file.lastModified()));
}
代码示例来源:origin: ModeShape/modeshape
@Test
public void shouldHaveSameNameSiblingIndex() throws Exception {
assertThat(altima.getIndex(), is(1));
javax.jcr.Node altima2 = hybrid.addNode("Nissan Altima");
try {
assertThat(altima2, is(notNullValue()));
assertThat(altima2.getIndex(), is(2));
} finally {
altima2.remove(); // remove the node we added in this test to not interfere with other tests
}
}
内容来源于网络,如有侵权,请联系作者删除!