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

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

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

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

  1. protected String getPathToNonExistingNode() throws RepositoryException {
  2. String name = "nonexisting";
  3. String path = name;
  4. int i = 0;
  5. while (testRootNode.hasNode(path)) {
  6. path = name + i;
  7. i++;
  8. }
  9. path = testRootNode.getPath() + "/" + path;
  10. return path;
  11. }

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

  1. /**
  2. * Get the Magnolia system node created under the given node.
  3. *
  4. * @throws RepositoryException if failed to create system node
  5. */
  6. protected synchronized Node getSystemNode(Node node) throws RepositoryException {
  7. if (node.hasNode(SYSTEM_NODE)) {
  8. return node.getNode(SYSTEM_NODE);
  9. }
  10. return node.addNode(SYSTEM_NODE, NodeTypes.System.NAME);
  11. }
  12. }

代码示例来源:origin: exoplatform/platform

  1. private Node getUserSettingHome(Session session) throws Exception {
  2. Node settingNode = session.getRootNode().getNode(AbstractService.SETTING_NODE);
  3. Node userHomeNode = null;
  4. if (settingNode.hasNode(AbstractService.SETTING_USER_NODE) == false) {
  5. userHomeNode = settingNode.addNode(AbstractService.SETTING_USER_NODE, AbstractService.STG_SUBCONTEXT);
  6. session.save();
  7. } else {
  8. userHomeNode = settingNode.getNode(AbstractService.SETTING_USER_NODE);
  9. }
  10. return userHomeNode;
  11. }

代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons

  1. private void setFolderTitle(Node child, String title) throws RepositoryException{
  2. if (!child.getPath().equals(jcrBasePath)) {
  3. if(child.hasNode(JcrConstants.JCR_CONTENT)){
  4. child.getNode(JcrConstants.JCR_CONTENT).setProperty(JcrConstants.JCR_TITLE, title);
  5. }else{
  6. child.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_UNSTRUCTURED).setProperty(JcrConstants.JCR_TITLE, title);
  7. }
  8. }
  9. }

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

  1. private void deleteMyNodes() throws RepositoryException {
  2. Node root = testRootNode;
  3. while (root.hasNode("testroot")) {
  4. root.getNode("testroot").remove();
  5. }
  6. root.getSession().save();
  7. }

代码示例来源:origin: com.onehippo.thiememeulenhoff/tmgs-bootstrap-configuration

  1. /**
  2. * Method to remove a sub node
  3. * @param node
  4. * @throws RepositoryException
  5. */
  6. protected void removeSubNode(Node node, String name) throws RepositoryException {
  7. if(log.isInfoEnabled()) {
  8. log.info("Removing subnode " + name + " of node " + node.getPath() + " (" + node.hasNode(name) + ")");
  9. }
  10. if (node.hasNode(name)) {
  11. node.getNode(name).remove();
  12. }
  13. }

代码示例来源:origin: org.onehippo.cms7.essentials/hippo-essentials-plugin-api-implementation

  1. private static List<Node> getQueryTemplateNodes(Session session, String[] templates) throws RepositoryException {
  2. List<Node> queryTemplates = new ArrayList<>();
  3. Node hippoTemplates = session.getRootNode().getNode("hippo:configuration/hippo:queries/hippo:templates");
  4. for (String template : templates) {
  5. if (hippoTemplates.hasNode(template)) {
  6. queryTemplates.add(hippoTemplates.getNode(template));
  7. }
  8. }
  9. return queryTemplates;
  10. }

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

  1. private void migrateNoFilterHtmlProcessor(final Node moduleConfigNode) throws RepositoryException {
  2. if (!moduleConfigNode.hasNode(NO_FILTER_PROCESSOR)) {
  3. log.info("Creating default no-filter HtmlProcessor");
  4. final Node noFilter = moduleConfigNode.addNode(NO_FILTER_PROCESSOR, HIPPOSYS_MODULE_CONFIG);
  5. noFilter.setProperty("charset", "UTF-8");
  6. noFilter.setProperty("filter", false);
  7. noFilter.setProperty("omitComments", false);
  8. if (!dryRun) {
  9. session.save();
  10. }
  11. }
  12. }

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

  1. @Test
  2. public void testImportCommandDuplicateName() throws Exception {
  3. // GIVEN
  4. doReturn(true).when(importCommand).checkPermissions(RepositoryConstants.WEBSITE, targetNode.getPath(), Permission.WRITE);
  5. targetNode.addNode("about", NodeTypes.Page.NAME);
  6. targetNode.getSession().save();
  7. // WHEN
  8. importCommand.execute(context);
  9. // THEN
  10. assertTrue(targetNode.hasNodes());
  11. assertEquals(2, targetNode.getNodes("about").getSize());
  12. assertTrue(targetNode.hasNode("about[2]/extras"));
  13. assertTrue(targetNode.hasNode("about[2]/extras/extras1"));
  14. }

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

  1. public void delete(String name) throws WorkflowException, MappingException, RepositoryException, RemoteException {
  2. if (name.startsWith("/")) {
  3. name = name.substring(1);
  4. }
  5. String path = subject.getPath().substring(1);
  6. Node folder = (path.equals("") ? rootSession.getRootNode() : rootSession.getRootNode().getNode(path));
  7. if (folder.hasNode(name)) {
  8. Node offspring = folder.getNode(name);
  9. delete(folder, offspring);
  10. }
  11. }

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

  1. private void moveContainerItems(final Node from, final Node to) throws RepositoryException {
  2. Session session = from.getSession();
  3. for (Node fromChild : new NodeIterable(from.getNodes())) {
  4. String newName = fromChild.getName();
  5. int counter = 0;
  6. while (to.hasNode(newName)) {
  7. newName = fromChild.getName() + ++counter;
  8. }
  9. session.move(fromChild.getPath(), to.getPath() + "/" + newName);
  10. }
  11. }

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

  1. @Override
  2. public boolean hasModulesNode() {
  3. try {
  4. final Session session = getConfigJCRSession();
  5. return session.getRootNode().hasNode(ModuleManagerImpl.MODULES_NODE);
  6. } catch (RepositoryException e) {
  7. return false;
  8. }
  9. }

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

  1. /**
  2. * Same as {@link #testMovedNodeGetPath()}, but calls save prior to the
  3. * test.
  4. */
  5. public void testMovedNodeGetPath2() throws RepositoryException, NotExecutableException {
  6. String oldPath = moveNode.getPath();
  7. if (destParentNode.hasNode(nodeName2)) {
  8. throw new NotExecutableException("Move destination already contains a child node with name " + nodeName2);
  9. }
  10. //move the node
  11. doMove(oldPath, destParentNode.getPath() + "/" + nodeName2);
  12. superuser.save();
  13. assertEquals("After successful move the moved node must return the destination path.", destinationPath, moveNode.getPath());
  14. }

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

  1. @Test
  2. public void testCugAtUnsupportedPath() throws Exception {
  3. doImport("/", XML_CHILD_WITH_CUG);
  4. getImportSession().save();
  5. assertTrue(getImportSession().getRootNode().hasNode("child"));
  6. assertFalse(getImportSession().getRootNode().hasNode("child/rep:cugPolicy"));
  7. }
  8. }

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

  1. @Test
  2. public void testImportCommand() throws Exception {
  3. // GIVEN
  4. doReturn(true).when(importCommand).checkPermissions(RepositoryConstants.WEBSITE, targetNode.getPath(), Permission.WRITE);
  5. // WHEN
  6. importCommand.execute(context);
  7. // THEN
  8. assertTrue(targetNode.hasNodes());
  9. assertTrue(targetNode.hasNode("about"));
  10. assertTrue(targetNode.hasNode("about/extras"));
  11. assertTrue(targetNode.hasNode("about/extras/extras1"));
  12. }

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

  1. /**
  2. * Common check.
  3. */
  4. private void assertNodeExistWithProperty(Node rootNode, String nodePathToTest, String propertyName, String propertyValue) throws RepositoryException {
  5. assertTrue(nodePathToTest + " should have been moved ", rootNode.hasNode(nodePathToTest));
  6. assertTrue(nodePathToTest + " should have property " + propertyName, rootNode.getNode(nodePathToTest).hasProperty(propertyName));
  7. assertEquals(nodePathToTest + " should have property " + propertyName + " with the same value " + propertyValue, (rootNode.getNode(nodePathToTest).getProperty(propertyName)).getValue().getString(), propertyValue);
  8. }
  9. }

代码示例来源:origin: org.onehippo.cms7.essentials/hippo-essentials-plugin-api-implementation

  1. public static Node createHippoNamespace(final Session session, final String prefix) throws RepositoryException {
  2. if (StringUtils.isBlank(prefix)) {
  3. throw new RepositoryException("Unable to create namespace for empty prefix");
  4. }
  5. final Node namespaces = session.getRootNode().getNode(HippoNodeType.NAMESPACES_PATH);
  6. if (namespaces.hasNode(prefix)) {
  7. log.info("Namespace '{}' already registered", prefix);
  8. return namespaces.getNode(prefix);
  9. }
  10. return namespaces.addNode(prefix, HippoNodeType.NT_NAMESPACE);
  11. }

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

  1. @Override
  2. protected Node doExec(Node context, ErrorHandler errorHandler) throws RepositoryException {
  3. return (context.hasNode(name)) ? context.getNode(name) : context.addNode(name, nodeType);
  4. }
  5. };

代码示例来源:origin: org.onehippo.cms7.hst.toolkit-resources.addon/hst-addon-repository

  1. private void migrateBlueprint(final Node blueprintNode) throws RepositoryException {
  2. if (!blueprintNode.hasNode("hst:channel")) {
  3. getLogger().info("No need to migrate blueprint '{}' because does not have an hst:channel node.", blueprintNode.getPath());
  4. return;
  5. }
  6. final Node blueprintConfigurationNode;
  7. if (blueprintNode.hasNode("hst:configuration")) {
  8. blueprintConfigurationNode = blueprintNode.getNode("hst:configuration");
  9. } else {
  10. blueprintConfigurationNode = blueprintNode.addNode("hst:configuration", "hst:configuration");
  11. }
  12. blueprintNode.getSession().move(blueprintNode.getPath() + "/hst:channel", blueprintConfigurationNode.getPath() + "/hst:channel");
  13. }

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

  1. public void testNtFile() throws RepositoryException, IOException {
  2. while (testRootNode.hasNode(nodeName1)) {
  3. testRootNode.getNode(nodeName1).remove();
  4. }
  5. String content = "The quick brown fox jumps over the lazy dog.";
  6. Node file = JcrUtils.putFile(testRootNode, nodeName1, "text/plain",
  7. new ByteArrayInputStream(content.getBytes("UTF-8")));
  8. testRootNode.getSession().save();
  9. String xpath = testPath + "/*[jcr:contains(jcr:content, 'lazy')]";
  10. executeXPathQuery(xpath, new Node[] { file });
  11. }

相关文章