Search in sources :

Example 66 with ValueMap

use of org.apache.sling.api.resource.ValueMap in project sling by apache.

the class AbstractNoSqlResourceProviderTest method testDateProperty.

@Test
public void testDateProperty() throws IOException {
    Resource resource1 = context.resourceResolver().getResource(testRoot().getPath() + "/node1");
    ValueMap props = ResourceUtil.getValueMap(resource1);
    assertEquals(DATE_VALUE, props.get("dateProp", Date.class));
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) Date(java.util.Date) Test(org.junit.Test)

Example 67 with ValueMap

use of org.apache.sling.api.resource.ValueMap in project sling by apache.

the class ContextPluginsTest method testValueMap.

@Test
public void testValueMap() {
    // read config
    ValueMap props = contextResource.adaptTo(ConfigurationBuilder.class).name(CONFIG_NAME).asValueMap();
    assertEquals("value1", props.get("stringParam", String.class));
    assertEquals((Integer) 123, props.get("intParam", Integer.class));
    assertTrue(props.get("boolParam", Boolean.class));
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Test(org.junit.Test)

Example 68 with ValueMap

use of org.apache.sling.api.resource.ValueMap in project sling by apache.

the class UrlFilter method doFilter.

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    if (request instanceof SlingHttpServletRequest && response instanceof SlingHttpServletResponse) {
        SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
        SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response;
        RequestPathInfo pathInfo = slingRequest.getRequestPathInfo();
        Resource definitionResource = findUrlFilterDefinitionResource(slingRequest.getResource(), slingRequest.getResourceResolver());
        if (definitionResource != null) {
            logger.debug("found url filter definition resource at {}", definitionResource.getPath());
            ValueMap properties = definitionResource.adaptTo(ValueMap.class);
            if (properties != null) {
                if (checkSelector(pathInfo, properties) && checkSuffix(pathInfo, properties) && checkExtension(pathInfo, properties)) {
                    logger.debug("url filter definition resource at {} passed for request {}.", definitionResource.getPath(), slingRequest.getRequestPathInfo());
                } else {
                    logger.info("url filter definition resource at {} FAILED for request {}.", definitionResource.getPath(), slingRequest.getRequestPathInfo());
                    slingResponse.sendError(403);
                    return;
                }
            }
        }
    }
    chain.doFilter(request, response);
}
Also used : SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) RequestPathInfo(org.apache.sling.api.request.RequestPathInfo) ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest)

Example 69 with ValueMap

use of org.apache.sling.api.resource.ValueMap in project sling by apache.

the class SubjectLettersEntropy method countLetters.

private void countLetters(Resource r) {
    messages++;
    ValueMap properties = r.adaptTo(ValueMap.class);
    String subj = properties.get("Subject", (String) null);
    for (int i = 0; i < Math.min(subj.length(), SAMPLE_LENGTH); i++) {
        Character c = Character.toLowerCase(subj.charAt(i));
        if (c.toString().matches("[a-z]")) {
            count[i][c - 'a']++;
        }
    }
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap)

Example 70 with ValueMap

use of org.apache.sling.api.resource.ValueMap in project sling by apache.

the class RatingsServiceImpl method getRating.

/**
     * @see org.apache.sling.sample.slingshot.ratings.RatingsService#getRating(org.apache.sling.api.resource.Resource, java.lang.String)
     */
@Override
public double getRating(final Resource resource, final String userId) {
    final String fullPath = getRatingsResourcePath(resource);
    double rating = 0;
    final Resource r = resource.getResourceResolver().getResource(fullPath + "/" + userId);
    if (r != null) {
        final ValueMap vm = r.getValueMap();
        rating = vm.get(RatingsUtil.PROPERTY_RATING, 0.0);
    }
    return rating;
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) Resource(org.apache.sling.api.resource.Resource)

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