本文整理了Java中javax.jcr.Node.getName()
方法的一些代码示例,展示了Node.getName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.getName()
方法的具体详情如下:
包路径:javax.jcr.Node
类名称:Node
方法名:getName
暂无
代码示例来源:origin: org.apache.sling/org.apache.sling.jcr.resource
private String getPath(final Node node) throws RepositoryException {
final String path;
if (parentPath == null) {
path = node.getPath();
} else {
path = "/".equals(parentPath) ? '/' + node.getName() : parentPath + '/' + node.getName();
}
return path;
}
}
代码示例来源: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: apache/jackrabbit
/**
* Tests if the name of the created node is correct.
*/
public void testName() throws RepositoryException {
Node n1 = testRootNode.addNode(nodeName1, testNodeType);
testRootNode.getSession().save();
assertEquals("Wrong node name.", n1.getName(), nodeName1);
}
代码示例来源:origin: apache/jackrabbit
/**
* A ConstraintViolationException is thrown if the operation would violate a
* node-type or other implementation-specific constraint.
*/
public void testMoveNodesConstraintViolationException() throws RepositoryException {
// if parent node is nt:base then no sub nodes can be created
String nodetype = testNodeTypeNoChildren == null ? ntBase : testNodeTypeNoChildren;
Node subNodesNotAllowedNode = testRootNode.addNode(nodeName3, nodetype);
testRootNode.getSession().save();
try {
String dstAbsPath = subNodesNotAllowedNode.getPath() + "/" + node2.getName();
workspace.move(node2.getPath(), dstAbsPath);
fail("Moving a node below a node which can not have any sub nodes should throw a ConstraintViolationException.");
} catch (ConstraintViolationException e) {
// successful
}
}
代码示例来源:origin: org.onehippo.cms7/hippo-repository-engine
private void moveToHistory(final Node node) {
try {
// the updater node was modified externally by the executor
session.refresh(false);
final String srcPath = node.getPath();
final Node history = session.getNode(UPDATE_HISTORY_PATH);
String name = node.getName();
int count = 2;
while (history.hasNode(name)) {
name = node.getName() + "-" + count++;
}
final String destPath = UPDATE_HISTORY_PATH + "/" + name;
session.move(srcPath, destPath);
session.save();
} catch (RepositoryException e) {
log.error("Failed to remove updater from queue", e);
}
}
代码示例来源:origin: info.magnolia/magnolia-core
@Test
public void findPrincipalNodes() throws Exception {
// GIVEN
final String otherTestUser = "Dagobert";
final Node folder = root.addNode("folder", NodeTypes.Folder.NAME);
folder.addNode(otherTestUser, NodeTypes.User.NAME);
session.save();
// WHEN
final NodeIterator iterator = securityManager.findPrincipalNodes(root, NodeTypes.User.NAME);
// THEN
final List<String> users = new ArrayList<>();
while (iterator.hasNext()) {
users.add(iterator.nextNode().getName());
}
assertThat(users, hasItem(TEST_USER_NAME));
assertThat(users, hasItem(otherTestUser));
}
代码示例来源:origin: apache/jackrabbit-oak
/**
* OAK-612
*/
@Test
public void testAddNode() throws Exception {
new TestContentLoader().loadTestContent(getAdminSession());
Session session = getAdminSession();
Node test = session.getRootNode().addNode("test", "test:orderableFolder");
assertTrue(test.getPrimaryNodeType().hasOrderableChildNodes());
test.addNode("a");
test.addNode("b");
session.save();
NodeIterator it = test.getNodes();
assertEquals("a", it.nextNode().getName());
assertEquals("b", it.nextNode().getName());
}
代码示例来源:origin: apache/jackrabbit
public void testNameLength() throws RepositoryException {
node.setProperty(propertyName1, vf.createValue(node.getName(), PropertyType.NAME));
superuser.save();
checkOperators(propertyName1, node.getProperty(propertyName1).getLength());
}
代码示例来源: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: 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: org.onehippo.cms7/hippo-repository-engine
private void markMissingInitializeItems(final Session session, final Set<String> itemNames) throws RepositoryException {
final Node initializeFolder = session.getNode(INIT_FOLDER_PATH);
for (Node item : new NodeIterable(initializeFolder.getNodes())) {
if (!itemNames.contains(item.getName()) && !item.getName().equals(HIPPO_LOCK)) {
log.info("Marking missing initialize item {}", item.getName());
InitializeItem.markMissing(item);
}
}
session.save();
}
代码示例来源:origin: ModeShape/modeshape
@Override
public void afterEach() throws Exception {
NodeIterator nodeIterator = session.getRootNode().getNodes();
while (nodeIterator.hasNext()) {
Node node = nodeIterator.nextNode();
if (!JcrLexicon.SYSTEM.getString().equals(node.getName())) {
node.remove();
}
}
session.save();
super.afterEach();
}
代码示例来源: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: apache/jackrabbit
/**
* A ConstraintViolationException is thrown if the operation would violate a
* node-type or other implementation-specific constraint.
*/
public void testCopyNodesConstraintViolationException() throws RepositoryException {
// if parent node is nt:base then no sub nodes can be created
String nodetype = testNodeTypeNoChildren == null ? ntBase : testNodeTypeNoChildren;
Node subNodesNotAllowedNode = testRootNode.addNode(nodeName3, nodetype);
testRootNode.getSession().save();
try {
String dstAbsPath = subNodesNotAllowedNode.getPath() + "/" + node2.getName();
workspace.copy(node2.getPath(), dstAbsPath);
fail("Copying a node below a node which can not have any sub nodes should throw a ConstraintViolationException.");
} catch (ConstraintViolationException e) {
// successful
}
}
代码示例来源:origin: apache/jackrabbit
/**
* Test if the removeExisting-flag removes an existing node in case of uuid conflict.
*/
public void testWorkspaceRestoreWithRemoveExistingJcr2() throws NotExecutableException, RepositoryException {
// create version for parentNode of childNode
superuser.getWorkspace().clone(workspaceName, wVersionableChildNode.getPath(), wVersionableChildNode.getPath(), false);
Version parentV = versionableNode.getSession().getWorkspace().getVersionManager().checkin(versionableNode.getPath());
// move child node in order to produce the uuid conflict
String newChildPath = wVersionableNode2.getPath() + "/" + wVersionableChildNode.getName();
wSuperuser.move(wVersionableChildNode.getPath(), newChildPath);
wSuperuser.save();
// restore the parent with removeExisting == true >> moved child node
// must be removed.
wSuperuser.getWorkspace().getVersionManager().restore(new Version[]{parentV}, true);
if (wSuperuser.itemExists(newChildPath)) {
fail("Workspace.restore(Version[], boolean) with the boolean flag set to true, must remove the existing node in case of Uuid conflict.");
}
}
代码示例来源:origin: info.magnolia/magnolia-core
/**
* Take action on a sibling node.<br>
* In this case, simply display in the install screen the sibling node name and path.
*/
protected void handleNode(Node node, InstallContext installContext) throws RepositoryException {
installContext.warn("Found same name sibling of '" + node.getName() + "' at '" + node.getPath() + "'");
}
代码示例来源:origin: info.magnolia/magnolia-core
@Override
public MgnlGroup doExec(Session session) throws RepositoryException {
String parentPath = StringUtils.defaultString(path, "/");
Node groupNode = session.getNode(parentPath).addNode(name, NodeTypes.Group.NAME);
session.save();
return new MgnlGroup(groupNode.getIdentifier(), groupNode.getName(), Collections.EMPTY_LIST, Collections.EMPTY_LIST);
}
代码示例来源:origin: info.magnolia/magnolia-core
@Test
public void findPrincipalNodesIgnoresNodesUnderDifferentRoot() throws Exception {
// GIVEN
final String otherTestUser = "Dagobert";
final Node folder = root.addNode("folder", NodeTypes.Folder.NAME);
folder.addNode(otherTestUser, NodeTypes.User.NAME);
session.save();
// WHEN
final NodeIterator iterator = securityManager.findPrincipalNodes(folder, NodeTypes.User.NAME);
// THEN
final List<String> users = new ArrayList<>();
while (iterator.hasNext()) {
users.add(iterator.nextNode().getName());
}
assertThat(users, not(hasItem(TEST_USER_NAME)));
assertThat(users, hasItem(otherTestUser));
}
代码示例来源:origin: apache/jackrabbit
@SuppressWarnings("deprecation")
public void testRestoreRemoved() throws RepositoryException {
Node parent = versionableNode.getParent();
String oldName = versionableNode.getName();
Version v1 = versionableNode.checkin();
versionableNode.remove();
versionableNode = null;
parent.getSession().save();
parent.restore(v1, oldName, true);
versionableNode = parent.getNode(oldName);
String value = versionableNode.getProperty(propertyName1).getString();
assertEquals("Restoring a node must set the correct property.", propertyValue2, value);
}
代码示例来源: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() + "]");
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!