use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.
the class MockSlingHttpServletRequest method getPathInfo.
@Override
public String getPathInfo() {
RequestPathInfo requestPathInfo = this.getRequestPathInfo();
if (StringUtils.isEmpty(requestPathInfo.getResourcePath())) {
return null;
}
StringBuilder pathInfo = new StringBuilder();
pathInfo.append(requestPathInfo.getResourcePath());
if (StringUtils.isNotEmpty(requestPathInfo.getSelectorString())) {
pathInfo.append('.');
pathInfo.append(requestPathInfo.getSelectorString());
}
if (StringUtils.isNotEmpty(requestPathInfo.getExtension())) {
pathInfo.append('.');
pathInfo.append(requestPathInfo.getExtension());
}
if (StringUtils.isNotEmpty(requestPathInfo.getSuffix())) {
pathInfo.append(requestPathInfo.getSuffix());
}
return pathInfo.toString();
}
use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.
the class UrlFilterTest method non_null_selector.
@Test
public void non_null_selector() {
UrlFilter filter = new UrlFilter();
final RequestPathInfo testInfo = context.mock(RequestPathInfo.class);
this.context.checking(new Expectations() {
{
allowing(testInfo).getSelectorString();
will(returnValue("sample"));
}
});
// null allowedSelectors = ok
assertTrue(filter.checkSelector(testInfo, properties));
// empty array allowedSelectors = fail
properties.put(UrlFilter.PN_ALLOWED_SELECTORS, (Object) new String[0]);
assertFalse(filter.checkSelector(testInfo, properties));
// selector string in array = ok
properties.put(UrlFilter.PN_ALLOWED_SELECTORS, (Object) new String[] { "sample", "sample2" });
assertTrue(filter.checkSelector(testInfo, properties));
// selector string not in array = fail
properties.put(UrlFilter.PN_ALLOWED_SELECTORS, (Object) new String[] { "other" });
assertFalse(filter.checkSelector(testInfo, properties));
properties.clear();
// matches regex
properties.put(UrlFilter.PN_ALLOWED_SELECTOR_PATTERN, "^s[a-z]m.*$");
assertTrue(filter.checkSelector(testInfo, properties));
// doesn't match regex
properties.put(UrlFilter.PN_ALLOWED_SELECTOR_PATTERN, "^s[1-2]m$");
assertFalse(filter.checkSelector(testInfo, properties));
properties.clear();
// matches array or regex = ok
properties.put(UrlFilter.PN_ALLOWED_SELECTORS, (Object) new String[] { "other" });
properties.put(UrlFilter.PN_ALLOWED_SELECTOR_PATTERN, "^s[a-z]m.*$");
assertTrue(filter.checkSelector(testInfo, properties));
properties.put(UrlFilter.PN_ALLOWED_SELECTORS, (Object) new String[] { "sample" });
properties.put(UrlFilter.PN_ALLOWED_SELECTOR_PATTERN, "^s[a-z]m$");
assertTrue(filter.checkSelector(testInfo, properties));
}
use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.
the class RequestData method initServlet.
public void initServlet(final Resource resource, final ServletResolver sr) {
// the resource and the request path info, will never be null
RequestPathInfo requestPathInfo = new SlingRequestPathInfo(resource);
ContentData contentData = setContent(resource, requestPathInfo);
requestProgressTracker.log("Resource Path Info: {0}", requestPathInfo);
// finally resolve the servlet for the resource
requestProgressTracker.startTimer("ServletResolution");
Servlet servlet = sr.resolveServlet(slingRequest);
requestProgressTracker.logTimer("ServletResolution", "URI={0} handled by Servlet={1}", getServletRequest().getRequestURI(), (servlet == null ? "-none-" : RequestUtil.getServletName(servlet)));
contentData.setServlet(servlet);
}
Aggregations