Search in sources :

Example 6 with ValueMap

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;
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource)

Example 7 with ValueMap

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");
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Test(org.junit.Test)

Example 8 with ValueMap

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"));
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 9 with ValueMap

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();
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) ContextResource(org.apache.sling.caconfig.resource.spi.ContextResource) LinkedHashMap(java.util.LinkedHashMap) CollectionInheritanceDecider(org.apache.sling.caconfig.resource.spi.CollectionInheritanceDecider) HashSet(java.util.HashSet)

Example 10 with ValueMap

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));
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) DummyConfigurationOverrideProvider(org.apache.sling.caconfig.impl.override.DummyConfigurationOverrideProvider) Test(org.junit.Test)

Aggregations

ValueMap (org.apache.sling.api.resource.ValueMap)278 Resource (org.apache.sling.api.resource.Resource)205 Test (org.junit.Test)160 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)59 HashMap (java.util.HashMap)54 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)44 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)26 Map (java.util.Map)21 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)21 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)20 RewriterResponse (org.apache.sling.security.impl.ContentDispositionFilter.RewriterResponse)20 Expectations (org.jmock.Expectations)20 ArrayList (java.util.ArrayList)18 PersistenceException (org.apache.sling.api.resource.PersistenceException)17 Calendar (java.util.Calendar)16 Date (java.util.Date)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)12 InputStream (java.io.InputStream)11 Node (javax.jcr.Node)11