本文整理了Java中javax.jcr.Node.hasNode()
方法的一些代码示例,展示了Node.hasNode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.hasNode()
方法的具体详情如下:
包路径:javax.jcr.Node
类名称:Node
方法名:hasNode
[英]Indicates whether a node exists at relPath
Returns true
if a node accessible through the current Session
exists at relPath
and false
otherwise.
[中]指示节点是否存在于relPath
如果可通过当前Session
访问的节点存在于relPath
,则返回true
,否则返回false
。
代码示例来源:origin: apache/jackrabbit
protected String getPathToNonExistingNode() throws RepositoryException {
String name = "nonexisting";
String path = name;
int i = 0;
while (testRootNode.hasNode(path)) {
path = name + i;
i++;
}
path = testRootNode.getPath() + "/" + path;
return path;
}
代码示例来源:origin: info.magnolia/magnolia-core
/**
* Get the Magnolia system node created under the given node.
*
* @throws RepositoryException if failed to create system node
*/
protected synchronized Node getSystemNode(Node node) throws RepositoryException {
if (node.hasNode(SYSTEM_NODE)) {
return node.getNode(SYSTEM_NODE);
}
return node.addNode(SYSTEM_NODE, NodeTypes.System.NAME);
}
}
代码示例来源:origin: exoplatform/platform
private Node getUserSettingHome(Session session) throws Exception {
Node settingNode = session.getRootNode().getNode(AbstractService.SETTING_NODE);
Node userHomeNode = null;
if (settingNode.hasNode(AbstractService.SETTING_USER_NODE) == false) {
userHomeNode = settingNode.addNode(AbstractService.SETTING_USER_NODE, AbstractService.STG_SUBCONTEXT);
session.save();
} else {
userHomeNode = settingNode.getNode(AbstractService.SETTING_USER_NODE);
}
return userHomeNode;
}
代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons
private void setFolderTitle(Node child, String title) throws RepositoryException{
if (!child.getPath().equals(jcrBasePath)) {
if(child.hasNode(JcrConstants.JCR_CONTENT)){
child.getNode(JcrConstants.JCR_CONTENT).setProperty(JcrConstants.JCR_TITLE, title);
}else{
child.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_UNSTRUCTURED).setProperty(JcrConstants.JCR_TITLE, title);
}
}
}
代码示例来源:origin: apache/jackrabbit
private void deleteMyNodes() throws RepositoryException {
Node root = testRootNode;
while (root.hasNode("testroot")) {
root.getNode("testroot").remove();
}
root.getSession().save();
}
代码示例来源:origin: com.onehippo.thiememeulenhoff/tmgs-bootstrap-configuration
/**
* Method to remove a sub node
* @param node
* @throws RepositoryException
*/
protected void removeSubNode(Node node, String name) throws RepositoryException {
if(log.isInfoEnabled()) {
log.info("Removing subnode " + name + " of node " + node.getPath() + " (" + node.hasNode(name) + ")");
}
if (node.hasNode(name)) {
node.getNode(name).remove();
}
}
代码示例来源:origin: org.onehippo.cms7.essentials/hippo-essentials-plugin-api-implementation
private static List<Node> getQueryTemplateNodes(Session session, String[] templates) throws RepositoryException {
List<Node> queryTemplates = new ArrayList<>();
Node hippoTemplates = session.getRootNode().getNode("hippo:configuration/hippo:queries/hippo:templates");
for (String template : templates) {
if (hippoTemplates.hasNode(template)) {
queryTemplates.add(hippoTemplates.getNode(template));
}
}
return queryTemplates;
}
代码示例来源:origin: org.onehippo.cms7/hippo-repository-engine
private void migrateNoFilterHtmlProcessor(final Node moduleConfigNode) throws RepositoryException {
if (!moduleConfigNode.hasNode(NO_FILTER_PROCESSOR)) {
log.info("Creating default no-filter HtmlProcessor");
final Node noFilter = moduleConfigNode.addNode(NO_FILTER_PROCESSOR, HIPPOSYS_MODULE_CONFIG);
noFilter.setProperty("charset", "UTF-8");
noFilter.setProperty("filter", false);
noFilter.setProperty("omitComments", false);
if (!dryRun) {
session.save();
}
}
}
代码示例来源: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: org.onehippo.cms7/hippo-repository-workflow
public void delete(String name) throws WorkflowException, MappingException, RepositoryException, RemoteException {
if (name.startsWith("/")) {
name = name.substring(1);
}
String path = subject.getPath().substring(1);
Node folder = (path.equals("") ? rootSession.getRootNode() : rootSession.getRootNode().getNode(path));
if (folder.hasNode(name)) {
Node offspring = folder.getNode(name);
delete(folder, offspring);
}
}
代码示例来源: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: info.magnolia/magnolia-core
@Override
public boolean hasModulesNode() {
try {
final Session session = getConfigJCRSession();
return session.getRootNode().hasNode(ModuleManagerImpl.MODULES_NODE);
} catch (RepositoryException e) {
return false;
}
}
代码示例来源:origin: apache/jackrabbit
/**
* Same as {@link #testMovedNodeGetPath()}, but calls save prior to the
* test.
*/
public void testMovedNodeGetPath2() throws RepositoryException, NotExecutableException {
String oldPath = moveNode.getPath();
if (destParentNode.hasNode(nodeName2)) {
throw new NotExecutableException("Move destination already contains a child node with name " + nodeName2);
}
//move the node
doMove(oldPath, destParentNode.getPath() + "/" + nodeName2);
superuser.save();
assertEquals("After successful move the moved node must return the destination path.", destinationPath, moveNode.getPath());
}
代码示例来源:origin: apache/jackrabbit-oak
@Test
public void testCugAtUnsupportedPath() throws Exception {
doImport("/", XML_CHILD_WITH_CUG);
getImportSession().save();
assertTrue(getImportSession().getRootNode().hasNode("child"));
assertFalse(getImportSession().getRootNode().hasNode("child/rep:cugPolicy"));
}
}
代码示例来源:origin: info.magnolia/magnolia-core
@Test
public void testImportCommand() throws Exception {
// GIVEN
doReturn(true).when(importCommand).checkPermissions(RepositoryConstants.WEBSITE, targetNode.getPath(), Permission.WRITE);
// WHEN
importCommand.execute(context);
// THEN
assertTrue(targetNode.hasNodes());
assertTrue(targetNode.hasNode("about"));
assertTrue(targetNode.hasNode("about/extras"));
assertTrue(targetNode.hasNode("about/extras/extras1"));
}
代码示例来源:origin: info.magnolia/magnolia-core
/**
* Common check.
*/
private void assertNodeExistWithProperty(Node rootNode, String nodePathToTest, String propertyName, String propertyValue) throws RepositoryException {
assertTrue(nodePathToTest + " should have been moved ", rootNode.hasNode(nodePathToTest));
assertTrue(nodePathToTest + " should have property " + propertyName, rootNode.getNode(nodePathToTest).hasProperty(propertyName));
assertEquals(nodePathToTest + " should have property " + propertyName + " with the same value " + propertyValue, (rootNode.getNode(nodePathToTest).getProperty(propertyName)).getValue().getString(), propertyValue);
}
}
代码示例来源:origin: org.onehippo.cms7.essentials/hippo-essentials-plugin-api-implementation
public static Node createHippoNamespace(final Session session, final String prefix) throws RepositoryException {
if (StringUtils.isBlank(prefix)) {
throw new RepositoryException("Unable to create namespace for empty prefix");
}
final Node namespaces = session.getRootNode().getNode(HippoNodeType.NAMESPACES_PATH);
if (namespaces.hasNode(prefix)) {
log.info("Namespace '{}' already registered", prefix);
return namespaces.getNode(prefix);
}
return namespaces.addNode(prefix, HippoNodeType.NT_NAMESPACE);
}
代码示例来源:origin: info.magnolia/magnolia-core
@Override
protected Node doExec(Node context, ErrorHandler errorHandler) throws RepositoryException {
return (context.hasNode(name)) ? context.getNode(name) : context.addNode(name, nodeType);
}
};
代码示例来源:origin: org.onehippo.cms7.hst.toolkit-resources.addon/hst-addon-repository
private void migrateBlueprint(final Node blueprintNode) throws RepositoryException {
if (!blueprintNode.hasNode("hst:channel")) {
getLogger().info("No need to migrate blueprint '{}' because does not have an hst:channel node.", blueprintNode.getPath());
return;
}
final Node blueprintConfigurationNode;
if (blueprintNode.hasNode("hst:configuration")) {
blueprintConfigurationNode = blueprintNode.getNode("hst:configuration");
} else {
blueprintConfigurationNode = blueprintNode.addNode("hst:configuration", "hst:configuration");
}
blueprintNode.getSession().move(blueprintNode.getPath() + "/hst:channel", blueprintConfigurationNode.getPath() + "/hst:channel");
}
代码示例来源:origin: apache/jackrabbit-oak
public void testNtFile() throws RepositoryException, IOException {
while (testRootNode.hasNode(nodeName1)) {
testRootNode.getNode(nodeName1).remove();
}
String content = "The quick brown fox jumps over the lazy dog.";
Node file = JcrUtils.putFile(testRootNode, nodeName1, "text/plain",
new ByteArrayInputStream(content.getBytes("UTF-8")));
testRootNode.getSession().save();
String xpath = testPath + "/*[jcr:contains(jcr:content, 'lazy')]";
executeXPathQuery(xpath, new Node[] { file });
}
内容来源于网络,如有侵权,请联系作者删除!