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));
}
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));
}
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);
}
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']++;
}
}
}
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;
}
Aggregations