/** * 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); } }
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; }
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); } } }
/** * 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(); } }
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; }
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(); } } }
@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")); }
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); } }
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); } }
@Override public boolean hasModulesNode() { try { final Session session = getConfigJCRSession(); return session.getRootNode().hasNode(ModuleManagerImpl.MODULES_NODE); } catch (RepositoryException e) { return false; } }
/** * 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()); }
@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")); } }
@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")); }
/** * 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); } }
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); }
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"); }
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 }); }