Java Code Examples for javax.jcr.Node#setProperty()
The following examples show how to use
javax.jcr.Node#setProperty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TreeSync.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
private void writeNtFile(SyncResult res, Entry e) throws RepositoryException, IOException { Node ntFile = e.node; Node content; String action = "A"; if (ntFile == null) { e.node = ntFile = e.parentNode.addNode(e.jcrName, NodeType.NT_FILE); content = ntFile.addNode(Node.JCR_CONTENT, NodeType.NT_RESOURCE); } else { content = ntFile.getNode(Node.JCR_CONTENT); action = "U"; } Calendar cal = Calendar.getInstance(); if (preserveFileDate) { cal.setTimeInMillis(e.file.lastModified()); } InputStream in = FileUtils.openInputStream(e.file); Binary bin = content.getSession().getValueFactory().createBinary(in); content.setProperty(Property.JCR_DATA, bin); content.setProperty(Property.JCR_LAST_MODIFIED, cal); content.setProperty(Property.JCR_MIMETYPE, MimeTypes.getMimeType(e.file.getName(), MimeTypes.APPLICATION_OCTET_STREAM)); syncLog.log("%s jcr://%s", action, ntFile.getPath()); res.addEntry(e.getJcrPath(), e.getFsPath(), SyncResult.Operation.UPDATE_JCR); }
Example 2
Source File: TestImportMode.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
/** * Installs a package with the filter: "/tmp/foo", mode="update" */ @Test public void testUpdate() throws RepositoryException, IOException, PackageException { Node tmp = admin.getRootNode().addNode("tmp"); Node foo = tmp.addNode("foo"); Node old = foo.addNode("old"); Node bar = foo.addNode("bar"); bar.setProperty("testProperty", "old"); admin.save(); assertNodeExists("/tmp/foo/old"); assertNodeMissing("/tmp/foo/new"); JcrPackage pack = packMgr.upload(getStream("/test-packages/tmp_mode_update.zip"), false); pack.extract(getDefaultOptions()); assertNodeExists("/tmp/foo/old"); assertNodeExists("/tmp/foo/bar"); assertNodeExists("/tmp/foo/new"); assertProperty("/tmp/foo/bar/testProperty", "new"); }
Example 3
Source File: StorageUpdate14.java From nextreports-server with Apache License 2.0 | 5 votes |
private void createIFrameSettings() throws RepositoryException, IOException { LOG.info("Add IFrame Settings Node"); Node rootNode = getTemplate().getRootNode(); Node settingsNode = rootNode.getNode(StorageConstants.NEXT_SERVER_FOLDER_NAME + StorageConstants.PATH_SEPARATOR + StorageConstants.SETTINGS_FOLDER_NAME); Node iframeNode = settingsNode.addNode(StorageConstants.IFRAME); iframeNode.addMixin("mix:referenceable"); iframeNode.setProperty("className", IFrameSettings.class.getName()); iframeNode.setProperty(StorageConstants.IFRAME_ENABLE, true); iframeNode.setProperty(StorageConstants.IFRAME_AUTH, false); iframeNode.setProperty(StorageConstants.IFRAME_ENC, "next$"); getTemplate().save(); }
Example 4
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 5 votes |
@Override public void addMetadataFacet(RepositorySession session, String repositoryId, MetadataFacet metadataFacet) throws MetadataRepositoryException { final Session jcrSession = getSession(session); try { Node repo = getOrAddRepositoryNode(jcrSession, repositoryId); Node facets = JcrUtils.getOrAddNode(repo, "facets", FACETS_FOLDER_TYPE); String id = metadataFacet.getFacetId(); Node facetNode = JcrUtils.getOrAddNode(facets, id, FACET_ID_CONTAINER_TYPE); if (!facetNode.hasProperty("id")) { facetNode.setProperty("id", id); } Node facetInstance = getOrAddNodeByPath(facetNode, metadataFacet.getName(), FACET_NODE_TYPE, true); if (!facetInstance.hasProperty("archiva:facetId")) { facetInstance.setProperty("archiva:facetId", id); facetInstance.setProperty("archiva:name", metadataFacet.getName()); } for (Map.Entry<String, String> entry : metadataFacet.toProperties().entrySet()) { facetInstance.setProperty(entry.getKey(), entry.getValue()); } session.save(); } catch (RepositoryException | MetadataSessionException e) { throw new MetadataRepositoryException(e.getMessage(), e); } }
Example 5
Source File: PageServiceImpl.java From mycollab with GNU Affero General Public License v3.0 | 5 votes |
private static Node convertPageToNode(Node node, Page page, String createdUser) { try { node.addMixin(NodeType.MIX_VERSIONABLE); node.setProperty("wiki:subject", page.getSubject()); node.setProperty("wiki:content", page.getContent()); node.setProperty("wiki:status", page.getStatus()); node.setProperty("wiki:category", page.getCategory()); node.setProperty("wiki:isLock", page.isLock()); node.setProperty("wiki:createdUser", createdUser); return node; } catch (Exception e) { throw new MyCollabException(e); } }
Example 6
Source File: JCRBuilder.java From jackalope with Apache License 2.0 | 5 votes |
public Property build(Node parent) { if (parent == null) return null; // properties only exist in nodes so there is nothing to build. try { if (hasMultiple) parent.setProperty(name, values); else parent.setProperty(name, values[0]); return parent.getProperty(name); } catch (RepositoryException re) { throw new SlingRepositoryException(re); } }
Example 7
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 5 votes |
private Node getOrAddRepositoryNode(Session jcrSession, String repositoryId) throws RepositoryException { log.debug("getOrAddRepositoryNode " + repositoryId); Node root = jcrSession.getRootNode(); Node node = JcrUtils.getOrAddNode(root, "repositories"); log.debug("Repositories " + node); node = JcrUtils.getOrAddNode(node, repositoryId, REPOSITORY_NODE_TYPE); if (!node.hasProperty("id")) { node.setProperty("id", repositoryId); } return node; }
Example 8
Source File: HistoryImpl.java From APM with Apache License 2.0 | 5 votes |
private Node createHistoryEntryNode(Node scriptHistoryNode, Script script, ExecutionMode mode, boolean remote) throws RepositoryException { String modeName = getModeName(mode, remote); Node historyEntry = getOrCreateUniqueByPath(scriptHistoryNode, modeName, NT_UNSTRUCTURED); historyEntry.setProperty(APM_HISTORY, APM_HISTORY_ENTRY); historyEntry.setProperty(HistoryEntryImpl.CHECKSUM, script.getChecksum()); scriptHistoryNode.setProperty(ScriptHistoryImpl.LAST_CHECKSUM, script.getChecksum()); scriptHistoryNode.setProperty("last" + modeName, historyEntry.getPath()); return historyEntry; }
Example 9
Source File: StorageUpdater.java From nextreports-server with Apache License 2.0 | 5 votes |
private void resetFirstUsageDates() throws Exception { LOG.info("Reset firstUsage.date for all users"); String statement = "/jcr:root" + ISO9075.encodePath(StorageConstants.USERS_ROOT) + "//*[@className='ro.nextreports.server.domain.UserPreferences']"; QueryResult queryResult = jcrTemplate.query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("Found " + nodes.getSize() + " user preferences nodes"); while (nodes.hasNext()) { Node node = nodes.nextNode(); Node pNode = node.getNode("preferences"); try { Property property = pNode.getProperty("firstUsage.date"); if (property.getValue() != null) { LOG.info(" removed firstUsage.date = " + property.getString() + " for user " + node.getParent().getName()); String s = null; pNode.setProperty("firstUsage.date", s); } } catch (PathNotFoundException ex) { // nothing to do } } jcrTemplate.save(); }
Example 10
Source File: RCPTest.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
@Test public void testRemoveMixin() throws IOException, RepositoryException, ConfigurationException { Node a = JcrUtils.getOrCreateByPath(SRC_TEST_NODE_PATH, NodeType.NT_FOLDER, NodeType.NT_FOLDER, admin, true); RepositoryCopier rcp = new RepositoryCopier(); a.addMixin(NodeType.MIX_TITLE); a.setProperty("jcr:title", "Hello"); admin.save(); rcp.copy(admin, SRC_PATH, admin, DST_PATH, true); assertProperty(DST_TEST_NODE_PATH + "/jcr:title", "Hello"); assertProperty(DST_TEST_NODE_PATH + "/jcr:mixinTypes", new String[]{"mix:title"}); a.removeMixin(NodeType.MIX_TITLE); admin.save(); // removing a mixing should remove the undeclared properties assertPropertyMissing(SRC_TEST_NODE_PATH + "/jcr:title"); assertPropertyMissingOrEmpty(SRC_TEST_NODE_PATH + "/jcr:mixinTypes"); rcp = new RepositoryCopier(); rcp.setOnlyNewer(false); rcp.setUpdate(true); rcp.copy(admin, SRC_PATH, admin, DST_PATH, true); assertNodeExists(DST_TEST_NODE_PATH); assertPropertyMissing(DST_TEST_NODE_PATH + "/jcr:title"); assertPropertyMissingOrEmpty(DST_TEST_NODE_PATH + "/jcr:mixinTypes"); }
Example 11
Source File: TestFolderArtifactHandler.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
@Test public void testNotModifyingIntermediateNodePrimaryType() throws RepositoryException, IOException, PackageException { // create node "/var/foo" with node type "nt:unstructured" Node rootNode = admin.getRootNode(); Node testNode = rootNode.addNode("var", "nt:unstructured"); Node fooNode = testNode.addNode("foo", "nt:unstructured"); assertNodeHasPrimaryType("/var/foo", "nt:unstructured"); fooNode.setProperty("testProperty", "test"); admin.save(); try (VaultPackage vltPackage = extractVaultPackageStrict("/test-packages/folder-without-docview-element.zip")) { assertNodeHasPrimaryType("/var/foo", "nt:unstructured"); assertProperty("/var/foo/testProperty", "test"); } }
Example 12
Source File: CNDImporter.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private void doPropertyAttributes(Node pdi) throws ParseException, RepositoryException { while (currentTokenEquals(Lexer.ATTRIBUTE)) { if (currentTokenEquals(Lexer.PRIMARY)) { Value name = pdi.getProperty(JcrConstants.JCR_NAME).getValue(); if (pdi.getParent().hasProperty(JcrConstants.JCR_PRIMARYITEMNAME)) { lexer.fail("More than one primary item specified in node type '" + name.getString() + "'"); } pdi.getParent().setProperty(JcrConstants.JCR_PRIMARYITEMNAME, name); } else if (currentTokenEquals(Lexer.AUTOCREATED)) { pdi.setProperty(JcrConstants.JCR_AUTOCREATED, true); } else if (currentTokenEquals(Lexer.MANDATORY)) { pdi.setProperty(JcrConstants.JCR_MANDATORY, true); } else if (currentTokenEquals(Lexer.PROTECTED)) { pdi.setProperty(JcrConstants.JCR_PROTECTED, true); } else if (currentTokenEquals(Lexer.MULTIPLE)) { pdi.setProperty(JcrConstants.JCR_MULTIPLE, true); } else if (currentTokenEquals(Lexer.COPY)) { pdi.setProperty(JcrConstants.JCR_ONPARENTVERSION, "COPY"); } else if (currentTokenEquals(Lexer.VERSION)) { pdi.setProperty(JcrConstants.JCR_ONPARENTVERSION, "VERSION"); } else if (currentTokenEquals(Lexer.INITIALIZE)) { pdi.setProperty(JcrConstants.JCR_ONPARENTVERSION, "INITIALIZE"); } else if (currentTokenEquals(Lexer.COMPUTE)) { pdi.setProperty(JcrConstants.JCR_ONPARENTVERSION, "COMPUTE"); } else if (currentTokenEquals(Lexer.IGNORE)) { pdi.setProperty(JcrConstants.JCR_ONPARENTVERSION, "IGNORE"); } else if (currentTokenEquals(Lexer.ABORT)) { pdi.setProperty(JcrConstants.JCR_ONPARENTVERSION, "ABORT"); } nextToken(); } }
Example 13
Source File: StorageUpdate20.java From nextreports-server with Apache License 2.0 | 5 votes |
private void renamePackage(Node node, String propertyName) throws RepositoryException { String oldValue = node.getProperty(propertyName).getString(); System.out.println(node.getPath() + " > oldValue = " + oldValue); String newValue = oldValue.replace("com.asf.nextserver", "ro.nextreports.server"); System.out.println("newValue = " + newValue); node.setProperty(propertyName, newValue); }
Example 14
Source File: TestFolderArtifactHandler.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
@Test public void testModifyingContainedNodeNonNtFolderPrimaryType() throws RepositoryException, IOException, PackageException { // create node "/testroot/foo" with node type "nt:unstructured" Node rootNode = admin.getRootNode(); Node testNode = rootNode.addNode("testroot", "nt:unstructured"); Node fooNode = testNode.addNode("foo", "nt:unstructured"); fooNode.setProperty("testProperty", "test"); admin.save(); try (VaultPackage vltPackage = extractVaultPackageStrict("/test-packages/folder-without-docview-element.zip")) { // make sure the primary type from "/test/foo" got overwritten! assertPropertyMissing("/testroot/foo/testProperty"); assertNodeHasPrimaryType("/testroot/foo", "nt:folder"); } }
Example 15
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 5 votes |
private Node getOrAddArtifactNode(Session jcrSession, String repositoryId, String namespace, String projectId, String projectVersion, String id) throws RepositoryException { Node versionNode = getOrAddProjectVersionNode(jcrSession, repositoryId, namespace, projectId, projectVersion); Node node = JcrUtils.getOrAddNode(versionNode, id, ARTIFACT_NODE_TYPE); if (!node.hasProperty("id")) { node.setProperty("id", id); } return node; }
Example 16
Source File: StorageUpdate0.java From nextreports-server with Apache License 2.0 | 4 votes |
private void createSystemNodes() throws RepositoryException { LOG.info("Creating system nodes"); Node rootNode = getTemplate().getRootNode(); Node nextServerNode = rootNode.addNode(StorageConstants.NEXT_SERVER_FOLDER_NAME); nextServerNode.addMixin("mix:referenceable"); nextServerNode.setProperty("className", Folder.class.getName()); nextServerNode.setProperty("version", "-1"); Node reportsNode = nextServerNode.addNode(StorageConstants.REPORTS_FOLDER_NAME); reportsNode.addMixin("mix:referenceable"); reportsNode.setProperty("className", Folder.class.getName()); Node datasourcesNode = nextServerNode.addNode(StorageConstants.DATASOURCES_FOLDER_NAME); datasourcesNode.addMixin("mix:referenceable"); datasourcesNode.setProperty("className", Folder.class.getName()); Node schedulersNode = nextServerNode.addNode(StorageConstants.SCHEDULER_FOLDER_NAME); schedulersNode.addMixin("mix:referenceable"); schedulersNode.setProperty("className", Folder.class.getName()); Node securityNode = nextServerNode.addNode(StorageConstants.SECURITY_FOLDER_NAME); securityNode.addMixin("mix:referenceable"); securityNode.setProperty("className", Folder.class.getName()); Node usersNode = securityNode.addNode(StorageConstants.USERS_FOLDER_NAME); usersNode.addMixin("mix:referenceable"); usersNode.setProperty("className", Folder.class.getName()); Node groupsNode = securityNode.addNode(StorageConstants.GROUPS_FOLDER_NAME); groupsNode.addMixin("mix:referenceable"); groupsNode.setProperty("className", Folder.class.getName()); Node adminNode = usersNode.addNode(StorageConstants.ADMIN_USER_NAME); adminNode.addMixin("mix:referenceable"); adminNode.setProperty("className", User.class.getName()); adminNode.setProperty("admin", true); PasswordEncoder passwordEncoder = new Md5PasswordEncoder(); adminNode.setProperty("password", passwordEncoder.encodePassword("1", null)); getTemplate().save(); }
Example 17
Source File: StorageUpdate24.java From nextreports-server with Apache License 2.0 | 4 votes |
private void createOrUpdateCleanHistorySettings() throws RepositoryException, IOException { LOG.info("Update Clean History Settings Node"); Node rootNode = getTemplate().getRootNode(); Node settingsNode = rootNode.getNode(StorageConstants.NEXT_SERVER_FOLDER_NAME + StorageConstants.PATH_SEPARATOR + StorageConstants.SETTINGS_FOLDER_NAME); NodeIterator ni = settingsNode.getNodes(StorageConstants.CLEAN_HISTORY); Settings s = new Settings(); CleanHistorySettings ch = s.getCleanHistory(); boolean found = false; boolean foundSettings = false; while (ni.hasNext()) { Node nn = ni.nextNode(); // this is the node itself PropertyIterator ni2 = nn.getProperties(); foundSettings = true; while (ni2.hasNext()) { Property nn2 = ni2.nextProperty(); if (StorageConstants.DAYS_TO_DELETE.equals(nn2.getName())) { found = true; LOG.info("Found Clean History Settings Node DAYS_TO_DELETE skipping ..."); break; } } if (!found) { nn.setProperty(StorageConstants.DAYS_TO_DELETE, ch.getDaysToDelete()); getTemplate().save(); LOG.info("Did not Found Clean History Settings Node DAYS_TO_DELETE adding default ..."); break; } } if (!foundSettings) { LOG.info("Did not find Clean History Settings Node at all, adding default one"); Node cleanHistoryNode = settingsNode.addNode(StorageConstants.CLEAN_HISTORY); cleanHistoryNode.addMixin("mix:referenceable"); cleanHistoryNode.setProperty("className", CleanHistorySettings.class.getName()); cleanHistoryNode.setProperty(StorageConstants.DAYS_TO_KEEP, ch.getDaysToKeep()); cleanHistoryNode.setProperty(StorageConstants.CRON_EXPRESSION, ch.getCronExpression()); cleanHistoryNode.setProperty(StorageConstants.DAYS_TO_DELETE, ch.getDaysToDelete()); cleanHistoryNode.setProperty(StorageConstants.SHRINK_DATA_FOLDER, true); getTemplate().save(); } }
Example 18
Source File: CatalogDataResourceProviderManagerImplTest.java From commerce-cif-connector with Apache License 2.0 | 4 votes |
@Test public void testBindNullFactoryModifyRoot() throws Exception { manager.activate(componentContext); FactoryConfig factoryConfig = bindFactory(); FactoryConfig nullFactoryConfig = bindNullFactory(); String rootPath = createDataRoot(factoryConfig.factoryId); Thread.sleep(WAIT_FOR_EVENTS); Assert.assertEquals(1, getProviders().size()); Assert.assertEquals(1, getProviderRegistrations().size()); Assert.assertEquals(2, manager.getProviderFactories().values().size()); Assert.assertTrue(manager.getProviderFactories().values().contains(factoryConfig.factory)); Assert.assertTrue(manager.getProviderFactories().values().contains(nullFactoryConfig.factory)); Assert.assertTrue(getProviderRegistrations().keySet().iterator().hasNext()); Object oldProvider = getProviderRegistrations().keySet().iterator().next(); Assert.assertNotNull(oldProvider); Assert.assertTrue(session.nodeExists(rootPath)); Node root = session.getNode(rootPath); // change data root to null provider factory root.setProperty(CatalogDataResourceProviderFactory.PROPERTY_FACTORY_ID, nullFactoryConfig.factoryId); session.save(); Thread.sleep(WAIT_FOR_EVENTS); // check that no provider was created Assert.assertEquals(0, getProviders().size()); Assert.assertEquals(0, getProviderRegistrations().size()); Assert.assertEquals(2, manager.getProviderFactories().values().size()); Assert.assertTrue(manager.getProviderFactories().values().contains(factoryConfig.factory)); Assert.assertTrue(manager.getProviderFactories().values().contains(nullFactoryConfig.factory)); Assert.assertFalse(getProviderRegistrations().keySet().iterator().hasNext()); // change data root to provider factory root.setProperty(CatalogDataResourceProviderFactory.PROPERTY_FACTORY_ID, factoryConfig.factoryId); session.save(); Thread.sleep(WAIT_FOR_EVENTS); // check that provider was created Assert.assertEquals(1, getProviders().size()); Assert.assertEquals(1, getProviderRegistrations().size()); Assert.assertEquals(2, manager.getProviderFactories().values().size()); Assert.assertTrue(manager.getProviderFactories().values().contains(factoryConfig.factory)); Assert.assertTrue(manager.getProviderFactories().values().contains(nullFactoryConfig.factory)); Assert.assertTrue(getProviderRegistrations().keySet().iterator().hasNext()); Object newPovider = getProviderRegistrations().keySet().iterator().next(); Assert.assertNotNull(newPovider); // check reregistration: new provider not the same as old provider Assert.assertNotSame(oldProvider, newPovider); }
Example 19
Source File: ExampleHook.java From jackrabbit-filevault with Apache License 2.0 | 4 votes |
private void doInstalled(InstallContext ctx) throws RepositoryException { // update a property in the install Node testNode = ctx.getSession().getNode(testNodePath); testNode.setProperty("hook-example", Calendar.getInstance()); ctx.getSession().save(); }
Example 20
Source File: CNDImporter.java From jackrabbit-filevault with Apache License 2.0 | 4 votes |
private static void setProperty(Node node, String name, List<String> values, int type) throws RepositoryException { node.setProperty(name, values.toArray(new String[values.size()]), type); }