use of org.apache.sling.api.resource.ValueMap in project sling by apache.
the class DeepReadValueMapDecorator method getValueMap.
private ValueMap getValueMap(final String name) {
final int pos = name.lastIndexOf("/");
if (pos == -1) {
return this.base;
}
final Resource rsrc = this.resolver.getResource(pathPrefix + name.substring(0, pos));
if (rsrc != null) {
final ValueMap vm = rsrc.adaptTo(ValueMap.class);
if (vm != null) {
return vm;
}
}
// fall back
return ValueMap.EMPTY;
}
use of org.apache.sling.api.resource.ValueMap in project sling by apache.
the class ValueMapDecoratorTest method testDelegateToValueMap.
@Test
public void testDelegateToValueMap() {
ValueMap original = mock(ValueMap.class);
ValueMap decorated = new ValueMapDecorator(original);
decorated.get("prop1", String.class);
verify(original, times(1)).get("prop1", String.class);
decorated.get("prop1", "defValue");
verify(original, times(1)).get("prop1", "defValue");
}
use of org.apache.sling.api.resource.ValueMap in project sling by apache.
the class ResourceAdapterFactory method getAdapter.
@Override
public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
if (type == ResourceAdapterUseObject.class && adaptable instanceof Resource) {
Resource resource = (Resource) adaptable;
ValueMap properties = resource.adaptTo(ValueMap.class);
String title = (String) properties.get("jcr:title");
return (AdapterType) new ResourceAdapterUseObjectImpl(title);
}
return null;
}
use of org.apache.sling.api.resource.ValueMap in project sling by apache.
the class Test method init.
public void init(Bindings bindings) {
Resource resource = (Resource) bindings.get(SlingBindings.RESOURCE);
ValueMap properties = (ValueMap) bindings.get(PROPERTIES);
if (properties != null) {
text = properties.get(TEXT, resource.getPath());
tag = properties.get(TAG, String.class);
includeChildren = properties.get(INCLUDE_CHIDLREN, false);
if (includeChildren) {
children = resource.listChildren();
}
}
}
use of org.apache.sling.api.resource.ValueMap in project sling by apache.
the class AbstractNoSqlResourceProviderTest method testSimpleProperties.
@Test
public void testSimpleProperties() throws IOException {
Resource resource1 = context.resourceResolver().getResource(testRoot().getPath() + "/node1");
assertTrue(resource1 instanceof NoSqlResource);
assertNotNull(resource1);
assertEquals("node1", resource1.getName());
ValueMap props = ResourceUtil.getValueMap(resource1);
assertEquals(STRING_VALUE, props.get("stringProp", String.class));
assertArrayEquals(STRING_ARRAY_VALUE, props.get("stringArrayProp", String[].class));
assertEquals((Integer) INTEGER_VALUE, props.get("integerProp", Integer.class));
assertEquals(DOUBLE_VALUE, props.get("doubleProp", Double.class), 0.0001);
assertEquals(BOOLEAN_VALUE, props.get("booleanProp", Boolean.class));
}
Aggregations