javax.jcr.Value Java Examples
The following examples show how to use
javax.jcr.Value.
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: DocViewPropertyTest.java From jackrabbit-filevault with Apache License 2.0 | 7 votes |
@Test public void testEmptyMVBoolean() throws Exception { Property p = Mockito.mock(Property.class); Value value = Mockito.mock(Value.class); Mockito.when(value.getString()).thenReturn("false"); Value[] values = new Value[]{value}; PropertyDefinition pd = Mockito.mock(PropertyDefinition.class); Mockito.when(pd.isMultiple()).thenReturn(true); Mockito.when(p.getType()).thenReturn(PropertyType.BOOLEAN); Mockito.when(p.getName()).thenReturn("foo"); Mockito.when(p.getValues()).thenReturn(values); Mockito.when(p.getDefinition()).thenReturn(pd); String result = DocViewProperty.format(p); Assert.assertEquals("formatted property", "{Boolean}[false]", result); // now round trip back DocViewProperty dp = DocViewProperty.parse("foo", result); Assert.assertEquals(new DocViewProperty("foo", new String[] {"false"}, true, PropertyType.BOOLEAN), dp); }
Example #2
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 #3
Source File: JackrabbitACLImporter.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
void convertRestrictions(JackrabbitAccessControlList acl, ValueFactory vf, Map<String, Value> svRestrictions, Map<String, Value[]> mvRestrictions) throws RepositoryException { for (String restName : acl.getRestrictionNames()) { DocViewProperty restriction = restrictions.get(restName); if (restriction != null) { Value[] values = new Value[restriction.values.length]; int type = acl.getRestrictionType(restName); for (int i=0; i<values.length; i++) { values[i] = vf.createValue(restriction.values[i], type); } if (restriction.isMulti) { mvRestrictions.put(restName, values); } else { svRestrictions.put(restName, values[0]); } } } }
Example #4
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 #5
Source File: ValueFactoryImpl.java From jackalope with Apache License 2.0 | 6 votes |
@Override public Value createValue(String value, int type) throws ValueFormatException { switch (type) { case PropertyType.STRING: return createValue(value); case PropertyType.LONG: return createValue(Long.valueOf(value)); case PropertyType.DOUBLE: return createValue(Double.valueOf(value)); case PropertyType.BOOLEAN: return createValue(Boolean.valueOf(value)); case PropertyType.DECIMAL: return createValue(new BigDecimal(value)); case PropertyType.DATE: // TODO: parse dates case PropertyType.BINARY: return createValue(createBinary(value)); default: return null; } }
Example #6
Source File: SetProperty.java From APM with Apache License 2.0 | 6 votes |
private ActionResult process(final Context context, boolean simulate) { ActionResult actionResult = context.createActionResult(); try { Authorizable authorizable = context.getCurrentAuthorizable(); actionResult.setAuthorizable(authorizable.getID()); LOGGER.info(String.format("Setting property %s for authorizable with id = %s", nameProperty, authorizable.getID())); final Value value = context.getValueFactory().createValue(valueProperty); if (!simulate) { authorizable.setProperty(nameProperty, value); } actionResult.logMessage( "Property " + nameProperty + " for " + authorizable.getID() + " added vith value: " + valueProperty); } catch (RepositoryException | ActionExecutionException e) { actionResult.logError(MessagingUtils.createMessage(e)); } return actionResult; }
Example #7
Source File: JcrPackageDefinitionImpl.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public void setDependencies(@NotNull Dependency[] dependencies, boolean autoSave) { try { final List<Value> values = new ArrayList<>(dependencies.length); final ValueFactory fac = defNode.getSession().getValueFactory(); for (Dependency d: dependencies) { if (d != null) { values.add(fac.createValue(d.toString())); } } defNode.setProperty(PN_DEPENDENCIES, values.toArray(new Value[values.size()])); if (autoSave) { defNode.getSession().save(); } } catch (RepositoryException e) { log.error("Error during setDependencies()", e); } }
Example #8
Source File: JcrPackageDefinitionImpl.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public void unwrap(Archive archive, boolean autoSave) throws RepositoryException, IOException { if (archive != null) { MetaInf inf = archive.getMetaInf(); // explode definition if present if (inf.hasDefinition()) { extractDefinition(archive); } if (inf.getFilter() != null) { JcrWorkspaceFilter.saveFilter(inf.getFilter(), defNode, false); } if (inf.getProperties() != null) { writeProperties(inf.getProperties()); } } defNode.setProperty("unwrapped", (Value) null); defNode.setProperty(PN_LAST_UNWRAPPED, Calendar.getInstance()); if (autoSave) { defNode.getSession().save(); } }
Example #9
Source File: ValueComparator.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
public int compare(Value o1, Value o2) { try { // assume types are equal switch (o1.getType()) { case PropertyType.BINARY: throw new IllegalArgumentException("sorting of binary values not supported."); case PropertyType.DATE: return o1.getDate().compareTo(o2.getDate()); case PropertyType.DECIMAL: return o1.getDecimal().compareTo(o2.getDecimal()); case PropertyType.DOUBLE: return ((Double) o1.getDouble()).compareTo(o2.getDouble()); case PropertyType.LONG: return ((Long) o1.getLong()).compareTo(o2.getLong()); default: return o1.getString().compareTo(o2.getString()); } } catch (RepositoryException e) { throw new IllegalArgumentException(e); } }
Example #10
Source File: PropertyResourceImpl.java From jackalope with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { try { return (type == String.class) ? (AdapterType)property.getString() : (type == Boolean.class) ? (AdapterType)Boolean.valueOf(property.getBoolean()) : (type == Long.class) ? (AdapterType)Long.valueOf(property.getLong()) : (type == Double.class) ? (AdapterType)new Double(property.getDouble()) : (type == BigDecimal.class) ? (AdapterType)property.getDecimal() : (type == Calendar.class) ? (AdapterType)property.getDate() : (type == Value.class) ? (AdapterType)property.getValue() : (type == String[].class) ? (AdapterType)Values.convertValuesToStrings(property.getValues()) : (type == Value[].class) ? (AdapterType)property.getValues() : super.adaptTo(type); } catch (RepositoryException re) { return super.adaptTo(type); } }
Example #11
Source File: JcrPackageDefinitionImpl.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
/** * Seals the package for assembly: * - touches this package * - increments the build count * - updates the created(by) properties * - updates the lastUnwrapped(by) properties * - clears the unwrapped property * * @param now the date or {@code null} */ void sealForAssembly(Calendar now) { try { if (now == null) { now = Calendar.getInstance(); } defNode.setProperty(PN_BUILD_COUNT, String.valueOf(getBuildCount() + 1)); defNode.setProperty(PN_CREATED, now); defNode.setProperty(PN_CREATED_BY, getUserId()); defNode.setProperty(PN_LAST_WRAPPED, now); defNode.setProperty(PN_LAST_WRAPPED_BY, getUserId()); defNode.setProperty(PN_LAST_UNWRAPPED, now); defNode.setProperty(PN_LAST_UNWRAPPED_BY, getUserId()); defNode.setProperty("unwrapped", (Value) null); touch(now, false); defNode.getSession().save(); } catch (RepositoryException e) { log.error("Error during sealForAssembly()", e); } }
Example #12
Source File: Restrictions.java From APM with Apache License 2.0 | 5 votes |
private Value[] createRestrictions(ValueFactory valueFactory, List<String> names) throws ValueFormatException { Value[] values = new Value[names.size()]; for (int index = 0; index < names.size(); index++) { values[index] = valueFactory.createValue(names.get(index), PropertyType.NAME); } return values; }
Example #13
Source File: IntegrationTestBase.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
public String dumpPermissions(String path) throws RepositoryException { StringBuilder ret = new StringBuilder(); AccessControlPolicy[] ap = admin.getAccessControlManager().getPolicies(path); for (AccessControlPolicy p: ap) { if (p instanceof JackrabbitAccessControlList) { JackrabbitAccessControlList acl = (JackrabbitAccessControlList) p; for (AccessControlEntry ac: acl.getAccessControlEntries()) { if (ac instanceof JackrabbitAccessControlEntry) { JackrabbitAccessControlEntry ace = (JackrabbitAccessControlEntry) ac; ret.append(ace.isAllow() ? "\n- allow " : "deny "); ret.append(ace.getPrincipal().getName()); char delim = '['; for (Privilege priv: ace.getPrivileges()) { ret.append(delim).append(priv.getName()); delim=','; } ret.append(']'); for (String restName: ace.getRestrictionNames()) { Value[] values; if ("rep:glob".equals(restName)) { values = new Value[]{ace.getRestriction(restName)}; } else { values = ace.getRestrictions(restName); } for (Value value : values) { ret.append(" rest=").append(value.getString()); } } } } } } return ret.toString(); }
Example #14
Source File: Restrictions.java From APM with Apache License 2.0 | 5 votes |
private void addRestrictions(ValueFactory valueFactory, Map<String, Value[]> result, String key, List<String> names) throws ValueFormatException { if (names != null && !names.isEmpty()) { result.put(key, createRestrictions(valueFactory, names)); } }
Example #15
Source File: CNDSerializer.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private void writeRequiredTypes(Writer out, Value[] reqTypes) throws IOException, RepositoryException { if (reqTypes.length > 0) { String delim = " ("; for (Value value : reqTypes) { out.write(delim); out.write(value.getString()); delim = ", "; } out.write(")"); } }
Example #16
Source File: CNDSerializer.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private void writeDefaultValues(Writer out, Value[] dva) throws IOException, RepositoryException { if (dva != null && dva.length > 0) { String delim = " = '"; for (Value value : dva) { out.write(delim); out.write(escape(value.getString())); out.write("'"); delim = ", '"; } } }
Example #17
Source File: LinkHelper.java From sling-samples with Apache License 2.0 | 5 votes |
public void createLink(Node source, Node target, String name) throws PathNotFoundException, RepositoryException { String targetPath = target.getPath(); ArrayList<String> newSourceLinks = new ArrayList<String>(); if (source.hasProperty(name)) { Value[] sourceLinks = source.getProperty(name).getValues(); for (Value sourceLink : sourceLinks) { newSourceLinks.add(sourceLink.getString()); } } if (!newSourceLinks.contains(targetPath)) { newSourceLinks.add(targetPath); } String[] newSourceLinksArray = new String[newSourceLinks.size()]; source.setProperty(name, newSourceLinks.toArray(newSourceLinksArray)); }
Example #18
Source File: CNDSerializer.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private void writeValueConstraints(Writer out, Value[] vca) throws IOException, RepositoryException { String delim = "\n" + INDENT + " < "; for (Value v: vca) { out.write(delim); out.write("'"); out.write(escape(v.getString())); out.write("'"); delim = ", "; } }
Example #19
Source File: Restrictions.java From APM with Apache License 2.0 | 5 votes |
public Map<String, Value[]> getMultiValueRestrictions(ValueFactory valueFactory) throws ValueFormatException { Map<String, Value[]> result = new HashMap<>(); addRestrictions(valueFactory, result, "rep:ntNames", ntNames); addRestrictions(valueFactory, result, "rep:itemNames", itemNames); return result; }
Example #20
Source File: DocViewSAXImporter.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
public Value getValue(Session session) throws RepositoryException, IOException { Artifact a = artifacts.get(0); try (InputStream input = a.getInputStream()) { return session.getValueFactory().createValue(input); } }
Example #21
Source File: PropertyImpl.java From jackalope with Apache License 2.0 | 5 votes |
@Override @Nonnull public long[] getLengths() throws ValueFormatException, RepositoryException { if (!isMultiple()) throw new ValueFormatException(); List<Long> lengths = new ArrayList<>(); for (Value value : values) lengths.add((long)value.getString().length()); return Longs.toArray(lengths); }
Example #22
Source File: PermissionActionHelper.java From APM with Apache License 2.0 | 5 votes |
private void addEntry(boolean allow, final List<Privilege> privileges, final Principal principal, final JackrabbitAccessControlList jackrabbitAcl) throws RepositoryException { Map<String, Value> singleValueRestrictions = restrictions.getSingleValueRestrictions(valueFactory); Map<String, Value[]> multiValueRestrictions = restrictions.getMultiValueRestrictions(valueFactory); jackrabbitAcl.addEntry(principal, privileges.toArray(new Privilege[privileges.size()]), allow, singleValueRestrictions, multiValueRestrictions); }
Example #23
Source File: DocViewSaxFormatterTest.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * Tests if an 'empty' node serialization includes the jcr namespace. see JCRVLT-266 */ @Test public void testFormatterIncludesJcrNamespace() throws Exception { // rep:itemNames restrictions are only supported in oak. Assume.assumeTrue(isOak()); JcrUtils.getOrCreateByPath("/testroot", NodeType.NT_UNSTRUCTURED, admin); admin.save(); // setup access control AccessControlManager acMgr = admin.getAccessControlManager(); JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, "/testroot"); Privilege[] privs = new Privilege[]{acMgr.privilegeFromName(Privilege.JCR_READ)}; Map<String, Value[]> rest = new HashMap<>(); rest.put("rep:itemNames", new Value[]{ admin.getValueFactory().createValue("jcr:mixinTypes", PropertyType.NAME), admin.getValueFactory().createValue("jcr:primaryType", PropertyType.NAME) }); acl.addEntry(EveryonePrincipal.getInstance(), privs, false, null, rest); acMgr.setPolicy("/testroot", acl); admin.save(); Session guest = repository.login(new GuestCredentials()); DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter(); filter.add(new PathFilterSet("/testroot")); RepositoryAddress addr = new RepositoryAddress("/" + admin.getWorkspace().getName() + "/"); VaultFileSystem jcrfs = Mounter.mount(null, filter, addr, null, guest); Aggregate a = jcrfs.getAggregateManager().getRoot().getAggregate("testroot"); DocViewSerializer s = new DocViewSerializer(a); ByteArrayOutputStream out = new ByteArrayOutputStream(); s.writeContent(out); assertEquals("valid xml", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<jcr:root xmlns:jcr=\"http://www.jcp.org/jcr/1.0\"/>\n", out.toString("utf-8")); }
Example #24
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 #25
Source File: JcrPackageDefinitionImpl.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * Returns the list of sub packages set on the definition node via the {@link #PN_SUB_PACKAGES} property. * @return the list of sub package ids * @throws RepositoryException if an error occurs. */ List<PackageId> getSubPackages() throws RepositoryException { LinkedList<PackageId> subPackages = new LinkedList<>(); if (defNode.hasProperty(PN_SUB_PACKAGES)) { Value[] subIds = defNode.getProperty(PN_SUB_PACKAGES).getValues(); for (Value v : subIds) { // reverse installation order subPackages.add(PackageId.fromString(v.getString())); } } return subPackages; }
Example #26
Source File: TestCugHandling.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
public static void assertProperty(Node node, String name, Set<String> values) throws RepositoryException { Set<String> strings = new HashSet(); for (Value v: node.getProperty(name).getValues()) { strings.add(v.getString()); } assertEquals(node.getPath() + "/" + name + " should contain " + values, values, strings); }
Example #27
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 #28
Source File: ProductsSuggestionOmniSearchHandler.java From commerce-cif-connector with Apache License 2.0 | 5 votes |
@Override public QueryResult execute() throws InvalidQueryException, RepositoryException { // Get JCR results QueryResult queryResult = query.execute(); // Get CIF products Iterator<Resource> it = getVirtualResults(resolver, Collections.singletonMap("fulltext", searchTerm), 10, 0); if (it == null || !it.hasNext()) { return queryResult; // No CIF results } ValueFactory valueFactory = resolver.adaptTo(Session.class).getValueFactory(); List<Row> rows = new ArrayList<>(); while (it.hasNext()) { String title = it.next().getValueMap().get(JcrConstants.JCR_TITLE, String.class); Value value = valueFactory.createValue(title); rows.add(new SuggestionRow(value)); } RowIterator suggestionIterator = queryResult.getRows(); while (suggestionIterator.hasNext()) { rows.add(suggestionIterator.nextRow()); } SuggestionQueryResult result = new SuggestionQueryResult(rows); return result; }
Example #29
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 5 votes |
public QueryResult runNativeJcrQuery(final Session jcrSession, final String q, final Map<String, String> bindingParam, long offset, long maxEntries) throws MetadataRepositoryException { Map<String, String> bindings; if (bindingParam == null) { bindings = new HashMap<>(); } else { bindings = bindingParam; } try { log.debug("Query: offset={}, limit={}, query={}", offset, maxEntries, q); Query query = jcrSession.getWorkspace().getQueryManager().createQuery(q, Query.JCR_SQL2); query.setLimit(maxEntries); query.setOffset(offset); ValueFactory valueFactory = jcrSession.getValueFactory(); for (Entry<String, String> entry : bindings.entrySet()) { log.debug("Binding: {}={}", entry.getKey(), entry.getValue()); Value value = valueFactory.createValue(entry.getValue()); log.debug("Binding value {}={}", entry.getKey(), value); query.bindValue(entry.getKey(), value); } long start = System.currentTimeMillis(); log.debug("Execute query {}", query); QueryResult result = query.execute(); long end = System.currentTimeMillis(); log.info("JCR Query ran in {} milliseconds: {}", end - start, q); return result; } catch (RepositoryException e) { throw new MetadataRepositoryException(e.getMessage(), e); } }
Example #30
Source File: PropertyImpl.java From jackalope with Apache License 2.0 | 5 votes |
@Override public void setValue(@Nonnull String[] values) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { List<Value> valueList = new ArrayList<>(values.length); for (String value : values) valueList.add(new ValueImpl(value)); setValue(valueList.toArray(new Value[valueList.size()])); }