javax.jcr.Property Java Examples
The following examples show how to use
javax.jcr.Property.
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: BaseRepositoryService.java From urule with Apache License 2.0 | 8 votes |
@Override public InputStream readFile(String path,String version) throws Exception{ if(StringUtils.isNotBlank(version)){ repositoryInteceptor.readFile(path+":"+version); return readVersionFile(path, version); } repositoryInteceptor.readFile(path); Node rootNode=getRootNode(); int colonPos = path.lastIndexOf(":"); if (colonPos > -1) { version = path.substring(colonPos + 1, path.length()); path = path.substring(0, colonPos); return readFile(path, version); } path = processPath(path); if (!rootNode.hasNode(path)) { throw new RuleException("File [" + path + "] not exist."); } Node fileNode = rootNode.getNode(path); Property property = fileNode.getProperty(DATA); Binary fileBinary = property.getBinary(); return fileBinary.getStream(); }
Example #2
Source File: Sync.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
public boolean load(VltContext ctx) throws RepositoryException { if (!s.nodeExists(CFG_NODE_PATH)) { return false; } Node cfgNode = s.getNode(CFG_NODE_PATH); if (cfgNode.hasProperty(CFG_ENABLED)) { enabled = cfgNode.getProperty(CFG_ENABLED).getBoolean(); } if (cfgNode.hasProperty(CFG_ROOTS)) { Property roots = cfgNode.getProperty(CFG_ROOTS); for (Value v : roots.getValues()) { this.roots.add(v.getString()); } } return true; }
Example #3
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 #4
Source File: PropertyValueArtifact.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
public PropertyValueArtifact(Artifact parent, String relPath, String ext, ArtifactType type, Property prop, int index, long lastModified) throws RepositoryException { super(parent, relPath, ext, type); this.property = prop; this.path = prop.getPath(); if (prop.getDefinition().isMultiple()) { if (index < 0) { index = 0; } } else { if (index >=0) { index = -1; } } this.valueIndex = index; this.lastModified = lastModified; }
Example #5
Source File: PropertyValueArtifact.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
/** * Creates a collection of {@link PropertyValueArtifact} from the given * property. If the property is multivalued there will be an artifact * created for each value with the value index appended to it's name. * * @param parent parent artifact * @param relPath the base name for the artifact(s). * @param ext the extension * @param type the type for the artifact(s). * @param prop the property for the artifact(s). * @param lastModified the last modified date. * * @return a collection of Artifacts. * @throws RepositoryException if an error occurs */ public static Collection<PropertyValueArtifact> create(Artifact parent, String relPath, String ext, ArtifactType type, Property prop, long lastModified) throws RepositoryException { LinkedList<PropertyValueArtifact> list = new LinkedList<PropertyValueArtifact>(); if (prop.getDefinition().isMultiple()) { Value[] values = prop.getValues(); for (int i=0; i<values.length; i++) { StringBuffer n = new StringBuffer(relPath); n.append('[').append(i).append(']'); list.add(new PropertyValueArtifact(parent, n.toString(), ext, type, prop, i, lastModified)); } } else { list.add(new PropertyValueArtifact(parent, relPath, ext, type, prop, lastModified)); } return list; }
Example #6
Source File: TestBinarylessExport.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
@Before @Ignore public void setup() throws RepositoryException, PackageException, IOException { // test only works for Jackrabbit 2.0 or Oak with FileDataStore Assume.assumeTrue(!isOak() || useFileStore()); Node binaryNode = JcrUtils.getOrCreateByPath(BINARY_NODE_PATH, "nt:unstructured", admin); Binary bigBin = admin.getValueFactory().createBinary(IOUtils.toInputStream(BIG_TEXT, "UTF-8")); Property bigProperty = binaryNode.setProperty(BIG_BINARY_PROPERTY, bigBin); String referenceBigBinary = ((ReferenceBinary) bigProperty.getBinary()).getReference(); assertNotNull(referenceBigBinary); Binary smallBin = admin.getValueFactory().createBinary(IOUtils.toInputStream(SMALL_TEXT, "UTF-8")); Property smallProperty = binaryNode.setProperty(SMALL_BINARY_PROPERTY, smallBin); if (isOak()) { assertTrue(smallProperty.getBinary() instanceof ReferenceBinary); } else { assertFalse(smallProperty.getBinary() instanceof ReferenceBinary); } JcrUtils.putFile(binaryNode.getParent(), "file", "text/plain", IOUtils.toInputStream(BIG_TEXT, "UTF-8")); admin.save(); }
Example #7
Source File: NodeImpl.java From jackalope with Apache License 2.0 | 5 votes |
@Override public Property setProperty(String name, Value value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { if (value == null) { if (hasProperty(name)) getProperty(name).remove(); return null; } PropertyImpl property = getOrCreateProperty(name); property.setValue(value); session.changeItem(this); return property; }
Example #8
Source File: JcrTemplate.java From mycollab with GNU Affero General Public License v3.0 | 5 votes |
/** * Recursive method for dumping a node. This method is separate to avoid the overhead of searching and * opening/closing JCR sessions. * @param node * @return * @throws RepositoryException */ protected String dumpNode(Node node) throws RepositoryException { StringBuffer buffer = new StringBuffer(); buffer.append(node.getPath()); PropertyIterator properties = node.getProperties(); while (properties.hasNext()) { Property property = properties.nextProperty(); buffer.append(property.getPath()).append("="); if (property.getDefinition().isMultiple()) { Value[] values = property.getValues(); for (int i = 0; i < values.length; i++) { if (i > 0) { buffer.append(","); } buffer.append(values[i].getString()); } } else { buffer.append(property.getString()); } buffer.append("\n"); } NodeIterator nodes = node.getNodes(); while (nodes.hasNext()) { Node child = nodes.nextNode(); buffer.append(dumpNode(child)); } return buffer.toString(); }
Example #9
Source File: AggregateImpl.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private void include(Node parent, Property prop, String propPath) throws RepositoryException { String relPath = propPath.substring(path.length()); if (includes == null || !includes.contains(relPath)) { if (log.isDebugEnabled()) { log.trace("including {} -> {}", path, propPath); } // ensure that parent node is included as well include(parent, null); includes.add(mgr.cacheString(relPath)); if (prop.getType() == PropertyType.BINARY) { boolean includeBinary = true; if (useBinaryReferences) { Binary bin = prop.getBinary(); if (bin != null && bin instanceof ReferenceBinary) { String binaryReference = ((ReferenceBinary) bin).getReference(); // do not create a separate binary file if there is a reference if (binaryReference != null) { includeBinary = false; } } } if (includeBinary) { if (binaries == null) { binaries = new LinkedList<Property>(); } binaries.add(prop); } } } }
Example #10
Source File: GenericAggregator.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public boolean includes(Node root, Node parent, Property property, String path) throws RepositoryException { if (path == null) { path = property.getPath(); } return contentFilter.contains(property, path, PathUtil.getDepth(path) - root.getDepth()); }
Example #11
Source File: RepositoryServiceImpl.java From urule with Apache License 2.0 | 5 votes |
@Override public List<UserPermission> loadResourceSecurityConfigs(String companyId) throws Exception{ List<UserPermission> configs=new ArrayList<UserPermission>(); String filePath=RESOURCE_SECURITY_CONFIG_FILE+(companyId == null ? "" : companyId); Node rootNode=getRootNode(); Node fileNode = rootNode.getNode(filePath); Property property = fileNode.getProperty(DATA); Binary fileBinary = property.getBinary(); InputStream inputStream = fileBinary.getStream(); String content = IOUtils.toString(inputStream, "utf-8"); inputStream.close(); Document document = DocumentHelper.parseText(content); Element rootElement = document.getRootElement(); for (Object obj : rootElement.elements()) { if (!(obj instanceof Element)) { continue; } Element element = (Element) obj; if (!element.getName().equals("user-permission")) { continue; } UserPermission userResource=new UserPermission(); userResource.setUsername(element.attributeValue("username")); userResource.setProjectConfigs(parseProjectConfigs(element)); configs.add(userResource); } return configs; }
Example #12
Source File: RepositoryServiceImpl.java From urule with Apache License 2.0 | 5 votes |
@Override public List<ClientConfig> loadClientConfigs(String project) throws Exception{ if(!permissionService.isAdmin()){ throw new NoPermissionException(); } List<ClientConfig> clients=new ArrayList<ClientConfig>(); Node rootNode=getRootNode(); String filePath = processPath(project) + "/" + CLIENT_CONFIG_FILE; Node fileNode = rootNode.getNode(filePath); Property property = fileNode.getProperty(DATA); Binary fileBinary = property.getBinary(); InputStream inputStream = fileBinary.getStream(); String content = IOUtils.toString(inputStream, "utf-8"); inputStream.close(); Document document = DocumentHelper.parseText(content); Element rootElement = document.getRootElement(); for (Object obj : rootElement.elements()) { if (!(obj instanceof Element)) { continue; } Element element = (Element) obj; if (!element.getName().equals("item")) { continue; } ClientConfig client = new ClientConfig(); client.setName(element.attributeValue("name")); client.setClient(element.attributeValue("client")); client.setProject(project); clients.add(client); } return clients; }
Example #13
Source File: IsMandatoryFilter.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
public boolean matches(Item item) throws RepositoryException { if (item.isNode()) { return ((Node) item).getDefinition().isMandatory() == isMandatory; } else { return ((Property) item).getDefinition().isMandatory() == isMandatory; } }
Example #14
Source File: DeclaringTypeItemFilter.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * * Matches if the declaring node type of the item is equal to the one * specified in this filter. If the item is a node and {@code propsOnly} * flag is {@code true} it returns {@code false}. */ public boolean matches(Item item) throws RepositoryException { if (item.isNode()) { return !propsOnly && ((Node) item).getDefinition().getDeclaringNodeType().getName().equals(nodeType); } else { return ((Property) item).getDefinition().getDeclaringNodeType().getName().equals(nodeType); } }
Example #15
Source File: StorageUpdate11.java From nextreports-server with Apache License 2.0 | 5 votes |
private void convertReports() throws RepositoryException { String statement = "/jcr:root" + ISO9075.encodePath(StorageConstants.REPORTS_ROOT) + "//*[@className='ro.nextreports.server.domain.Report' and @type='Next']" + "//*[fn:name()='jcr:content' and @jcr:mimeType='text/xml']"; QueryResult queryResult = getTemplate().query(statement); NodeIterator nodes = queryResult.getNodes(); LOG.info("Converter 5.1 : Found " + nodes.getSize() + " report nodes"); while (nodes.hasNext()) { Node node = nodes.nextNode(); Node reportNode = node.getParent().getParent().getParent().getParent(); String reportName = reportNode.getName(); String reportPath = reportNode.getPath(); LOG.info(" * Start convert '" + reportPath + "'"); Property prop = node.getProperty("jcr:data"); String xml = null; try { xml = new Converter_5_2().convertFromInputStream(prop.getBinary().getStream(), true); if (xml != null) { ValueFactory valueFactory = node.getSession().getValueFactory(); Binary binaryValue = valueFactory.createBinary(new ByteArrayInputStream(xml.getBytes("UTF-8"))); node.setProperty ("jcr:data", binaryValue); LOG.info("\t -> OK"); } else { LOG.error("\t -> FAILED : null xml"); } } catch (Throwable t) { LOG.error("\t-> FAILED : " + t.getMessage(), t); } } }
Example #16
Source File: WebdavProviderTestCase.java From commons-vfs with Apache License 2.0 | 5 votes |
/** Recursively outputs the contents of the given node. */ private static void dump(final Node node) throws RepositoryException { // First output the node path message(node.getPath()); // Skip the virtual (and large!) jcr:system subtree if (node.getName().equals("jcr:system")) { return; } if (node.getName().equals("jcr:content")) { return; } // Then output the properties final PropertyIterator properties = node.getProperties(); while (properties.hasNext()) { final Property property = properties.nextProperty(); if (property.getDefinition().isMultiple()) { // A multi-valued property, print all values final Value[] values = property.getValues(); for (final Value value : values) { message(property.getPath() + " = " + value.getString()); } } else { // A single-valued property message(property.getPath() + " = " + property.getString()); } } // Finally output all the child nodes recursively final NodeIterator nodes = node.getNodes(); while (nodes.hasNext()) { dump(nodes.nextNode()); } }
Example #17
Source File: BaseRepositoryService.java From urule with Apache License 2.0 | 5 votes |
@Override public List<VersionFile> getVersionFiles(String path) throws Exception{ path = processPath(path); Node rootNode=getRootNode(); if (!rootNode.hasNode(path)) { throw new RuleException("File [" + path + "] not exist."); } List<VersionFile> files = new ArrayList<VersionFile>(); Node fileNode = rootNode.getNode(path); VersionHistory versionHistory = versionManager.getVersionHistory(fileNode.getPath()); VersionIterator iterator = versionHistory.getAllVersions(); while (iterator.hasNext()) { Version version = iterator.nextVersion(); String versionName = version.getName(); if (versionName.startsWith("jcr:")) { continue; // skip root version } Node fnode = version.getFrozenNode(); VersionFile file = new VersionFile(); file.setName(version.getName()); file.setPath(fileNode.getPath()); Property prop = fnode.getProperty(CRATE_USER); file.setCreateUser(prop.getString()); prop = fnode.getProperty(CRATE_DATE); file.setCreateDate(prop.getDate().getTime()); if(fnode.hasProperty(VERSION_COMMENT)){ prop=fnode.getProperty(VERSION_COMMENT); file.setComment(prop.getString()); } files.add(file); } return files; }
Example #18
Source File: NodeImpl.java From jackalope with Apache License 2.0 | 5 votes |
@Override public PropertyIterator getProperties() throws RepositoryException { List<Property> children = new ArrayList<>(); for (Item item : session.getChildren(this)) if (!item.isNode()) children.add((Property)item); return new PropertyIteratorImpl(children); }
Example #19
Source File: DefaultObjectWrapper.java From sling-whiteboard with Apache License 2.0 | 5 votes |
public PropertyIterator wrap(SessionWrapper s, final PropertyIterator iter) { return new PropertyIterator() { @Override public Property nextProperty() { return wrap(s, iter.nextProperty()); } @Override public void skip(long skipNum) { iter.skip(skipNum); } @Override public long getSize() { return iter.getSize(); } @Override public long getPosition() { return iter.getPosition(); } @Override public boolean hasNext() { return iter.hasNext(); } @Override public void remove() { iter.remove(); } @Override public Object next() { // TODO cast to Property ok?? return wrap(s, (Property)iter.next()); } }; }
Example #20
Source File: BaseRepositoryService.java From urule with Apache License 2.0 | 5 votes |
private InputStream readVersionFile(String path, String version) throws Exception{ path = processPath(path); Node rootNode=getRootNode(); if (!rootNode.hasNode(path)) { throw new RuleException("File [" + path + "] not exist."); } Node fileNode = rootNode.getNode(path); VersionHistory versionHistory = versionManager.getVersionHistory(fileNode.getPath()); Version v = versionHistory.getVersion(version); Node fnode = v.getFrozenNode(); Property property = fnode.getProperty(DATA); Binary fileBinary = property.getBinary(); return fileBinary.getStream(); }
Example #21
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 #22
Source File: JackrabbitSessionWrapper.java From sling-whiteboard with Apache License 2.0 | 5 votes |
@Override public Property getPropertyOrNull(String absPath) throws RepositoryException { if (super.propertyExists(absPath)) { return super.getProperty(absPath); } else { return null; } }
Example #23
Source File: Webdav4ProviderTestCase.java From commons-vfs with Apache License 2.0 | 5 votes |
/** Recursively outputs the contents of the given node. */ private static void dump(final Node node) throws RepositoryException { // First output the node path message(node.getPath()); // Skip the virtual (and large!) jcr:system subtree if (node.getName().equals("jcr:system")) { return; } if (node.getName().equals("jcr:content")) { return; } // Then output the properties final PropertyIterator properties = node.getProperties(); while (properties.hasNext()) { final Property property = properties.nextProperty(); if (property.getDefinition().isMultiple()) { // A multi-valued property, print all values final Value[] values = property.getValues(); for (final Value value : values) { message(property.getPath() + " = " + value.getString()); } } else { // A single-valued property message(property.getPath() + " = " + property.getString()); } } // Finally output all the child nodes recursively final NodeIterator nodes = node.getNodes(); while (nodes.hasNext()) { dump(nodes.nextNode()); } }
Example #24
Source File: ItemWrapper.java From sling-whiteboard with Apache License 2.0 | 5 votes |
@Override public void accept(final ItemVisitor visitor) throws RepositoryException { delegate.accept(new ItemVisitor() { @Override public void visit(Property property) throws RepositoryException { visitor.visit(sessionWrapper.getObjectWrapper().wrap(sessionWrapper, property)); } @Override public void visit(Node node) throws RepositoryException { visitor.visit(sessionWrapper.getObjectWrapper().wrap(sessionWrapper, node)); } }); }
Example #25
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 #26
Source File: IntegrationTestBase.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
public void assertPropertyMissingOrEmpty(String path) throws RepositoryException { if (!admin.propertyExists(path)) { return; } Property p = admin.getProperty(path); if (p.isMultiple()) { assertTrue(path + " should not exist or be empty", p.getValues().length == 0); } else { assertTrue(path + " should not exist or be empty", p.getString().length() == 0); } }
Example #27
Source File: NodeImpl.java From jackalope with Apache License 2.0 | 4 votes |
@Override public Property setProperty(String name, Binary value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { return setProperty(name, new ValueImpl(value)); }
Example #28
Source File: NodeImpl.java From jackalope with Apache License 2.0 | 4 votes |
@Override public Property setProperty(String name, InputStream value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { return null; //deprecated }
Example #29
Source File: NodeImpl.java From jackalope with Apache License 2.0 | 4 votes |
@Override public Property setProperty(String name, String value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { return setProperty(name, new ValueImpl(value)); }
Example #30
Source File: NodeImpl.java From jackalope with Apache License 2.0 | 4 votes |
@Override public Property setProperty(String name, String value, int type) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { // TODO: Implement type conversions throw new UnsupportedOperationException(); }