Search in sources :

Example 31 with ResourceMetadata

use of org.apache.sling.api.resource.ResourceMetadata in project acs-aem-commons by Adobe-Consulting-Services.

the class DataSourceBuilderImpl method addDataSource.

@Override
public void addDataSource(final SlingHttpServletRequest slingRequest, final List<DataSourceOption> options) {
    final ArrayList<Resource> resourceList = new ArrayList<Resource>();
    DataSource dataSource = null;
    for (final DataSourceOption option : options) {
        final Map map = new HashMap();
        map.put(TEXT, option.getText());
        map.put(VALUE, option.getValue());
        resourceList.add(new ValueMapResource(slingRequest.getResourceResolver(), new ResourceMetadata(), "", new ValueMapDecorator(map)));
    }
    if (resourceList.size() > 0) {
        dataSource = new SimpleDataSource(resourceList.iterator());
    } else {
        dataSource = EmptyDataSource.instance();
    }
    slingRequest.setAttribute(DataSource.class.getName(), dataSource);
}
Also used : HashMap(java.util.HashMap) DataSourceOption(com.adobe.acs.commons.wcm.datasources.DataSourceOption) SimpleDataSource(com.adobe.granite.ui.components.ds.SimpleDataSource) ValueMapResource(com.adobe.granite.ui.components.ds.ValueMapResource) Resource(org.apache.sling.api.resource.Resource) ArrayList(java.util.ArrayList) ValueMapResource(com.adobe.granite.ui.components.ds.ValueMapResource) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator) ResourceMetadata(org.apache.sling.api.resource.ResourceMetadata) ValueMap(org.apache.sling.api.resource.ValueMap) HashMap(java.util.HashMap) Map(java.util.Map) EmptyDataSource(com.adobe.granite.ui.components.ds.EmptyDataSource) SimpleDataSource(com.adobe.granite.ui.components.ds.SimpleDataSource) DataSource(com.adobe.granite.ui.components.ds.DataSource)

Aggregations

ResourceMetadata (org.apache.sling.api.resource.ResourceMetadata)31 Resource (org.apache.sling.api.resource.Resource)15 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)7 Test (org.junit.Test)6 AbstractResourceImpl (com.adobe.acs.commons.mcp.impl.AbstractResourceImpl)5 ValueMap (org.apache.sling.api.resource.ValueMap)5 InputStream (java.io.InputStream)4 ValueMapResource (com.adobe.granite.ui.components.ds.ValueMapResource)3 HashMap (java.util.HashMap)3 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)3 BufferedInputStream (java.io.BufferedInputStream)2 ArrayList (java.util.ArrayList)2 Session (javax.jcr.Session)2 AccessControlManager (javax.jcr.security.AccessControlManager)2 Privilege (javax.jcr.security.Privilege)2 SlingException (org.apache.sling.api.SlingException)2 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)2 ScriptingResourceResolverProvider (org.apache.sling.scripting.api.resource.ScriptingResourceResolverProvider)2 SourceIdentifier (org.apache.sling.scripting.sightly.impl.engine.compiled.SourceIdentifier)2 ResolveContext (org.apache.sling.spi.resource.provider.ResolveContext)2