use of javax.jcr.ValueFactory in project jackrabbit-oak by apache.
the class NodeTypeTest method updateNodeType.
@Test
public void updateNodeType() throws Exception {
Session session = getAdminSession();
Node root = session.getRootNode();
ValueFactory vf = session.getValueFactory();
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
Node n = root.addNode("q1", "nt:query");
n.setProperty("jcr:statement", vf.createValue("statement"));
session.save();
NodeTypeDefinition ntd = manager.getNodeType("nt:query");
NodeTypeTemplate ntt = manager.createNodeTypeTemplate(ntd);
try {
manager.registerNodeType(ntt, true);
// no changes to the type, so the registration should be a no-op
} catch (ConstraintViolationException unexpected) {
fail();
}
// make the (still missing) jcr:language property mandatory
@SuppressWarnings("unchecked") List<PropertyDefinitionTemplate> pdts = ntt.getPropertyDefinitionTemplates();
for (PropertyDefinitionTemplate pdt : pdts) {
if ("jcr:language".equals(pdt.getName())) {
pdt.setMandatory(true);
}
}
try {
manager.registerNodeType(ntt, true);
fail();
} catch (ConstraintViolationException expected) {
// the registration fails because of the would-be invalid content
}
// add the jcr:language property so it can be made mandatory
n.setProperty("jcr:language", vf.createValue("language"));
session.save();
try {
manager.registerNodeType(ntt, true);
// now the mandatory property exists, so the type change is OK
} catch (ConstraintViolationException unexpected) {
fail();
}
}
use of javax.jcr.ValueFactory in project jackrabbit-oak by apache.
the class L6_AccessControlContentTest method testRestrictionContent.
public void testRestrictionContent() throws RepositoryException {
ValueFactory vf = superuser.getValueFactory();
acl.addEntry(testPrincipal, testPrivileges, false, ImmutableMap.of(AccessControlConstants.REP_GLOB, vf.createValue("")), ImmutableMap.of(AccessControlConstants.REP_PREFIXES, new Value[] { vf.createValue("jcr"), vf.createValue("mix") }));
acMgr.setPolicy(testRoot, acl);
// EXERCISE
String policyPath = null;
Node aclNode = superuser.getNode(policyPath);
Node ace = aclNode.getNodes().nextNode();
// EXERCISE: retrieve the restrictions defined for the single ACE node
// EXERCISE: verify the expected properties and their value(s)
}
use of javax.jcr.ValueFactory in project jackrabbit-oak by apache.
the class PropertyImpl method setValue.
@Override
public void setValue(String[] strings) throws RepositoryException {
if (strings == null) {
remove();
} else {
ValueFactory factory = getValueFactory();
Value[] values = new Value[strings.length];
for (int i = 0; i < strings.length; i++) {
if (strings[i] != null) {
values[i] = factory.createValue(strings[i]);
}
}
internalSetValue(values);
}
}
use of javax.jcr.ValueFactory in project sling by apache.
the class JcrModifiableValueMapTest method createValue.
Value createValue(final Object value, final Session session) throws RepositoryException {
Value val;
ValueFactory fac = session.getValueFactory();
if (value instanceof Calendar) {
val = fac.createValue((Calendar) value);
} else if (value instanceof InputStream) {
val = fac.createValue(fac.createBinary((InputStream) value));
} else if (value instanceof Node) {
val = fac.createValue((Node) value);
} else if (value instanceof BigDecimal) {
val = fac.createValue((BigDecimal) value);
} else if (value instanceof Long) {
val = fac.createValue((Long) value);
} else if (value instanceof Short) {
val = fac.createValue((Short) value);
} else if (value instanceof Integer) {
val = fac.createValue((Integer) value);
} else if (value instanceof Number) {
val = fac.createValue(((Number) value).doubleValue());
} else if (value instanceof Boolean) {
val = fac.createValue((Boolean) value);
} else if (value instanceof String) {
val = fac.createValue((String) value);
} else {
val = null;
}
return val;
}
use of javax.jcr.ValueFactory in project sling by apache.
the class DefaultContentCreator method createProperty.
/**
* @see org.apache.sling.jcr.contentloader.ContentCreator#createProperty(java.lang.String, int, java.lang.String[])
*/
public void createProperty(String name, int propertyType, String[] values) throws RepositoryException {
final Node node = this.parentNodeStack.peek();
// check if the property already exists and isPropertyOverwrite() is false, don't overwrite it in this case
if (node.hasProperty(name) && !this.configuration.isPropertyOverwrite() && !node.getProperty(name).isNew()) {
return;
}
if (propertyType == PropertyType.REFERENCE) {
String propPath = node.getPath() + "/" + name;
boolean hasAll = true;
String[] uuids = new String[values.length];
String[] uuidOrPaths = new String[values.length];
for (int i = 0; i < values.length; i++) {
uuids[i] = getUUID(node.getSession(), propPath, getAbsPath(node, values[i]));
uuidOrPaths[i] = uuids[i] != null ? uuids[i] : getAbsPath(node, values[i]);
if (uuids[i] == null)
hasAll = false;
}
checkoutIfNecessary(node);
node.setProperty(name, uuids, propertyType);
if (this.importListener != null) {
this.importListener.onCreate(node.getProperty(name).getPath());
}
if (!hasAll) {
delayedMultipleReferences.put(propPath, uuidOrPaths);
}
} else if (propertyType == PropertyType.DATE) {
checkoutIfNecessary(node);
try {
// This modification is to remove the colon in the JSON Timezone
ValueFactory valueFactory = node.getSession().getValueFactory();
Value[] jcrValues = new Value[values.length];
for (int i = 0; i < values.length; i++) {
jcrValues[i] = valueFactory.createValue(parseDateString(values[i]));
}
node.setProperty(name, jcrValues, propertyType);
} catch (ParseException e) {
// If this fails, fallback to the default
log.warn("Could not create dates for property, falling back to defaults", e);
node.setProperty(name, values, propertyType);
}
if (this.importListener != null) {
this.importListener.onCreate(node.getProperty(name).getPath());
}
} else {
checkoutIfNecessary(node);
if (propertyType == PropertyType.UNDEFINED) {
node.setProperty(name, values);
} else {
node.setProperty(name, values, propertyType);
}
if (this.importListener != null) {
this.importListener.onCreate(node.getProperty(name).getPath());
}
}
}
Aggregations