use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.
the class UrlFilterTest method null_selector.
@Test
public void null_selector() {
UrlFilter filter = new UrlFilter();
final RequestPathInfo testInfo = context.mock(RequestPathInfo.class);
this.context.checking(new Expectations() {
{
allowing(testInfo).getSelectorString();
will(returnValue(null));
}
});
assertTrue(filter.checkSelector(testInfo, null));
}
use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.
the class JsonRendererServletTest method setup.
@Before
public void setup() {
request = Mockito.mock(SlingHttpServletRequest.class);
final RequestPathInfo rpi = Mockito.mock(RequestPathInfo.class);
Mockito.when(request.getRequestPathInfo()).thenReturn(rpi);
Mockito.when(rpi.getSelectors()).thenAnswer(new Answer<String[]>() {
public String[] answer(InvocationOnMock invocation) {
return selectors;
}
});
final Resource resource = Mockito.mock(Resource.class);
Mockito.when(request.getResource()).thenReturn(resource);
response = Mockito.mock(SlingHttpServletResponse.class);
jrs = new JsonRendererServlet(42);
}
use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.
the class ResourceCollector method create.
/**
* Creates a <code>ResourceCollector</code> for the given
* <code>request</code>. If the request is a GET or HEAD request, a
* specialized instance is returned which also takes the request selectors
* and request extension into account for finding servlet resources.
* Otherwise an instance of this class itself is returned which just takes
* the resource type and request method name into account.
*
* @param request The <code>SlingHttpServletRequest</code> for which to
* return a <code>ResourceCollector</code>.
* @return The <code>ResourceCollector</code> to find servlets and scripts
* suitable for handling the <code>request</code>.
*/
public static ResourceCollector create(final SlingHttpServletRequest request, final String[] executionPaths, final String[] defaultExtensions) {
final RequestPathInfo requestPathInfo = request.getRequestPathInfo();
final boolean isDefaultExtension = ArrayUtils.contains(defaultExtensions, requestPathInfo.getExtension());
return new ResourceCollector(request.getResource(), requestPathInfo.getExtension(), executionPaths, isDefaultExtension, request.getMethod(), requestPathInfo.getSelectors());
}
use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.
the class DeleteOperation method doRun.
@Override
protected void doRun(final SlingHttpServletRequest request, final PostResponse response, final List<Modification> changes) throws PersistenceException {
// SLING-3203: selectors, extension and suffix make no sense here and
// might lead to deleting other resources than the one the user means.
final RequestPathInfo rpi = request.getRequestPathInfo();
if ((rpi.getSelectors() != null && rpi.getSelectors().length > 0) || (rpi.getExtension() != null && rpi.getExtension().length() > 0) || (rpi.getSuffix() != null && rpi.getSuffix().length() > 0)) {
response.setStatus(HttpServletResponse.SC_FORBIDDEN, "DeleteOperation request cannot include any selectors, extension or suffix");
return;
}
final VersioningConfiguration versioningConfiguration = getVersioningConfiguration(request);
final boolean deleteChunks = isDeleteChunkRequest(request);
final Iterator<Resource> res = getApplyToResources(request);
if (res == null) {
final Resource resource = request.getResource();
deleteResource(resource, changes, versioningConfiguration, deleteChunks);
} else {
while (res.hasNext()) {
final Resource resource = res.next();
deleteResource(resource, changes, versioningConfiguration, deleteChunks);
}
}
}
use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.
the class IncludeTagFilter method buildUrl.
private String buildUrl(Configuration config, SlingHttpServletRequest request) {
final boolean synthetic = ResourceUtil.isSyntheticResource(request.getResource());
final Resource resource = request.getResource();
final StringBuilder builder = new StringBuilder();
final RequestPathInfo pathInfo = request.getRequestPathInfo();
final String resourcePath = pathInfo.getResourcePath();
builder.append(resourcePath);
if (pathInfo.getSelectorString() != null) {
builder.append('.').append(sanitize(pathInfo.getSelectorString()));
}
builder.append('.').append(config.getIncludeSelector());
builder.append('.').append(pathInfo.getExtension());
if (synthetic) {
builder.append('/').append(resource.getResourceType());
} else {
builder.append(sanitize(pathInfo.getSuffix()));
}
return builder.toString();
}
Aggregations