use of org.apache.sling.api.resource.ModifiableValueMap in project sling by apache.
the class LoaderContentHandler method createResource.
private Resource createResource(Resource parentResource, String childName, Map<String, Object> content) throws PersistenceException {
// collect all properties first
boolean hasJcrData = false;
Map<String, Object> props = new HashMap<String, Object>();
for (Map.Entry<String, Object> entry : content.entrySet()) {
final String name = entry.getKey();
if (StringUtils.equals(name, JCR_DATA_PLACEHOLDER)) {
hasJcrData = true;
} else {
props.put(name, entry.getValue());
}
}
// create resource
Resource resource = resourceResolver.create(parentResource, childName, props);
if (hasJcrData) {
ModifiableValueMap valueMap = resource.adaptTo(ModifiableValueMap.class);
// we cannot import binary data here - but to avoid complaints by JCR we create it with empty binary data
valueMap.put(JcrConstants.JCR_DATA, new ByteArrayInputStream(new byte[0]));
}
return resource;
}
use of org.apache.sling.api.resource.ModifiableValueMap in project sling by apache.
the class SlingCrudResourceResolverTest method testStringToCalendarConversion.
@Test
public void testStringToCalendarConversion() throws IOException {
Resource resource1 = resourceResolver.getResource(testRoot.getPath() + "/node1");
ModifiableValueMap modProps = resource1.adaptTo(ModifiableValueMap.class);
modProps.put("dateISO8601String", ISO8601.format(CALENDAR_VALUE));
resourceResolver.commit();
resource1 = resourceResolver.getResource(testRoot.getPath() + "/node1");
ValueMap props = ResourceUtil.getValueMap(resource1);
assertEquals(CALENDAR_VALUE.getTime(), props.get("calendarProp", Calendar.class).getTime());
}
use of org.apache.sling.api.resource.ModifiableValueMap in project sling by apache.
the class PlumberImpl method writeStatus.
/**
* writes the status of the pipe
* @param pipe
* @param status
*/
protected void writeStatus(Pipe pipe, String status) throws RepositoryException {
if (StringUtils.isNotBlank(status)) {
ModifiableValueMap vm = pipe.getResource().adaptTo(ModifiableValueMap.class);
vm.put(PN_STATUS, status);
Calendar cal = new GregorianCalendar();
cal.setTime(new Date());
vm.put(PN_STATUS_MODIFIED, cal);
}
}
use of org.apache.sling.api.resource.ModifiableValueMap in project sling by apache.
the class WritePipe method copyProperties.
/**
* Write properties from the configuration to the target resource,
* instantiating both property names & values
*
* @param conf configured resource that holds all properties to write (and children)
* @param target target resource on which configured values will be written
* @throws RepositoryException issues occuring when traversing nodes
*/
private void copyProperties(Resource conf, Resource target) throws RepositoryException {
ValueMap writeMap = conf.adaptTo(ValueMap.class);
ModifiableValueMap properties = target.adaptTo(ModifiableValueMap.class);
//writing current node
if (properties != null && writeMap != null) {
for (Map.Entry<String, Object> entry : writeMap.entrySet()) {
if (!IGNORED_PROPERTIES.contains(entry.getKey())) {
String key = parent != null ? bindings.instantiateExpression(entry.getKey()) : entry.getKey();
Object value = computeValue(target, key, entry.getValue());
if (value == null) {
//null value are not handled by modifiable value maps,
//removing the property if it exists
addPropertyToRemove(target.getChild(key));
} else {
logger.info("writing {}={}", target.getPath() + "@" + key, value);
if (!isDryRun()) {
properties.put(key, value);
}
}
}
}
}
}
use of org.apache.sling.api.resource.ModifiableValueMap in project sling by apache.
the class AbstractCreateOperation method updateMixins.
protected void updateMixins(final ResourceResolver resolver, final String path, final Map<String, RequestProperty> reqProperties, final List<Modification> changes, final VersioningConfiguration versioningConfiguration) throws PersistenceException {
final String[] mixins = getMixinTypes(reqProperties, path);
if (mixins != null) {
final Resource rsrc = resolver.getResource(path);
final ModifiableValueMap mvm = rsrc.adaptTo(ModifiableValueMap.class);
if (mvm != null) {
this.jcrSsupport.checkoutIfNecessary(rsrc, changes, versioningConfiguration);
mvm.put(JcrConstants.JCR_MIXINTYPES, mixins);
for (final String mixin : mixins) {
// the mix:versionable mixin does an implicit checkout
if (mixin.equals(JcrConstants.MIX_VERSIONABLE) && versioningConfiguration.isCheckinOnNewVersionableNode()) {
changes.add(Modification.onCheckout(path));
}
}
}
}
}
Aggregations