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 MockResourceTest method basicTest.
@Test
public void basicTest() throws Exception {
final MockResource r = new MockResource(null, PATH, RT);
r.addProperty("1", Integer.MAX_VALUE);
r.addProperty("2", "two");
assertTrue(r instanceof Resource);
assertEquals(PATH, r.getPath());
assertEquals(RT, r.getResourceType());
assertNull(r.getResourceSuperType());
final ValueMap m = r.adaptTo(ValueMap.class);
assertEquals(Integer.MAX_VALUE, m.get("1"));
assertEquals("two", m.get("2"));
// changes to r do not affect m
assertNull(m.get("third"));
r.getProperties().put("third", "trois");
assertNull(m.get("third"));
// but we get the new value after adapting again
assertEquals("trois", r.adaptTo(ValueMap.class).get("third"));
}
use of org.apache.sling.api.resource.ValueMap in project sling by apache.
the class DefaultConfigurationResourceResolvingStrategy method getResourceCollectionInternal.
private Collection<Resource> getResourceCollectionInternal(final Collection<String> bucketNames, final String configName, Iterator<String> paths, ResourceResolver resourceResolver) {
final Map<String, Resource> result = new LinkedHashMap<>();
final List<CollectionInheritanceDecider> deciders = this.collectionInheritanceDeciders;
final Set<String> blockedItems = new HashSet<>();
boolean inherit = false;
while (paths.hasNext()) {
final String path = paths.next();
Resource item = null;
String bucketNameUsed = null;
for (String bucketName : bucketNames) {
String name = bucketName + "/" + configName;
String configPath = buildResourcePath(path, name);
item = resourceResolver.getResource(configPath);
if (item != null) {
bucketNameUsed = bucketName;
break;
} else {
log.trace("- No collection parent resource found: {}", configPath);
}
}
if (item != null) {
log.trace("o Check children of collection parent resource: {}", item.getPath());
if (item.hasChildren()) {
for (Resource child : item.getChildren()) {
if (isValidResourceCollectionItem(child) && !result.containsKey(child.getName()) && include(deciders, bucketNameUsed, child, blockedItems)) {
log.trace("+ Found collection resource item {}", child.getPath());
result.put(child.getName(), child);
}
}
}
// check collection inheritance mode on current level - should we check on next-highest level as well?
final ValueMap valueMap = item.getValueMap();
inherit = PropertyUtil.getBooleanValueAdditionalKeys(valueMap, PROPERTY_CONFIG_COLLECTION_INHERIT, config.configCollectionInheritancePropertyNames());
if (!inherit) {
break;
}
}
}
return result.values();
}
use of org.apache.sling.api.resource.ValueMap in project sling by apache.
the class ConfigurationResolverValueMapTest method testConfigWithOverride.
@Test
public void testConfigWithOverride() {
context.registerService(ConfigurationOverrideProvider.class, new DummyConfigurationOverrideProvider("[/content]sampleName={\"stringParam\":\"override1\",\"intParam\":222}"));
context.build().resource("/conf/content/site1/sling:configs/sampleName", "stringParam", "configValue1", "intParam", 111, "boolParam", true);
ValueMap props = underTest.get(site1Page1).name("sampleName").asValueMap();
assertEquals("override1", props.get("stringParam", String.class));
assertEquals(222, (int) props.get("intParam", 0));
assertEquals(false, props.get("boolParam", false));
}
Aggregations