Search in sources :

Example 61 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 62 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 63 with ValueMap

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

Example 64 with ValueMap

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

Example 65 with ValueMap

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