use of org.apache.sling.api.resource.ValueMap 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.ValueMap in project sling by apache.
the class WritePipeTest method assertPiped.
/**
*
* @param resource
*/
public static void assertPiped(Resource resource) {
ValueMap properties = resource.adaptTo(ValueMap.class);
String[] array = new String[] { "cabbage", "carrot" };
assertArrayEquals("Second fruit should have been correctly instantiated & patched, added to the first", new String[] { "apple", "banana" }, properties.get("fruits", String[].class));
assertArrayEquals("Fixed mv should be there", array, properties.get("fixedVegetables", String[].class));
assertArrayEquals("Expr fixed mv should there and computed", array, properties.get("computedVegetables", String[].class));
}
use of org.apache.sling.api.resource.ValueMap in project sling by apache.
the class AbstractNoSqlResourceProviderTest method testCalendarPropertyToDate.
@Test
public void testCalendarPropertyToDate() throws IOException {
Resource resource1 = context.resourceResolver().getResource(testRoot().getPath() + "/node1");
ValueMap props = ResourceUtil.getValueMap(resource1);
Date dateValue = props.get("calendarProp", Date.class);
assertNotNull(dateValue);
assertEquals(CALENDAR_VALUE.getTime(), dateValue);
}
use of org.apache.sling.api.resource.ValueMap in project sling by apache.
the class AbstractContentLoaderJsonTest method testUTF8Chars.
@Test
public void testUTF8Chars() {
Resource resource = context.resourceResolver().getResource(path + "/sample/en/jcr:content");
ValueMap props = ResourceUtil.getValueMap(resource);
assertEquals("äöü߀", props.get("utf8Property"));
}
use of org.apache.sling.api.resource.ValueMap in project sling by apache.
the class AbstractContentLoaderJsonTest method assertPrimaryNodeType.
private void assertPrimaryNodeType(final Resource resource, final String nodeType) throws RepositoryException {
Node node = resource.adaptTo(Node.class);
if (node != null) {
assertEquals(nodeType, node.getPrimaryNodeType().getName());
} else {
ValueMap props = ResourceUtil.getValueMap(resource);
assertEquals(nodeType, props.get(JcrConstants.JCR_PRIMARYTYPE));
}
}
Aggregations