Search in sources :

Example 11 with RequestPathInfo

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));
}
Also used : RequestPathInfo(org.apache.sling.api.request.RequestPathInfo) Expectations(org.jmock.Expectations) Test(org.junit.Test)

Example 12 with RequestPathInfo

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);
}
Also used : RequestPathInfo(org.apache.sling.api.request.RequestPathInfo) SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Resource(org.apache.sling.api.resource.Resource) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) Before(org.junit.Before)

Example 13 with RequestPathInfo

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());
}
Also used : RequestPathInfo(org.apache.sling.api.request.RequestPathInfo)

Example 14 with RequestPathInfo

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);
        }
    }
}
Also used : RequestPathInfo(org.apache.sling.api.request.RequestPathInfo) Resource(org.apache.sling.api.resource.Resource) VersioningConfiguration(org.apache.sling.servlets.post.VersioningConfiguration)

Example 15 with RequestPathInfo

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();
}
Also used : RequestPathInfo(org.apache.sling.api.request.RequestPathInfo) Resource(org.apache.sling.api.resource.Resource)

Aggregations

RequestPathInfo (org.apache.sling.api.request.RequestPathInfo)33 Resource (org.apache.sling.api.resource.Resource)4 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)2 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)2 Expectations (org.jmock.Expectations)2 Test (org.junit.Test)2 Servlet (javax.servlet.Servlet)1 RequestDispatcherOptions (org.apache.sling.api.request.RequestDispatcherOptions)1 ValueMap (org.apache.sling.api.resource.ValueMap)1 SlingMainServlet (org.apache.sling.engine.impl.SlingMainServlet)1 VersioningConfiguration (org.apache.sling.servlets.post.VersioningConfiguration)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1