Examples of RequestPathInfo


Examples of org.apache.sling.api.request.RequestPathInfo

        assertEquals("Selector string must not be null", "1",
            p.getSelectorString());
    }

    public void testJIRA_250_d() {
        RequestPathInfo p = new SlingRequestPathInfo(new MockResource("/",
            ".json"));
        assertEquals("/", p.getResourcePath());
        assertEquals("json", p.getExtension());
        assertNull("Suffix is null",p.getSuffix());
        assertNull("Selectors are null",p.getSelectorString());
    }
View Full Code Here

Examples of org.apache.sling.api.request.RequestPathInfo

        assertEquals("ext", p.getExtension());

        // test to replace selectors with a new one
        RequestDispatcherOptions o = new RequestDispatcherOptions();
        o.setReplaceSelectors("a");
        RequestPathInfo result = p.merge(o);
        assertEquals("a", result.getSelectorString());
        assertEquals("ext", result.getExtension());

        // test to replace selector with the empty string
        o.setReplaceSelectors("");
        result = p.merge(o);
        assertEquals(null, result.getSelectorString());
        assertEquals("ext", result.getExtension());

        // now add a selector
        o.setAddSelectors("b");
        result = p.merge(o);
        assertEquals("b", result.getSelectorString());
        assertEquals("ext", result.getExtension());

        // replace ext
        o.setReplaceSuffix("html");
        result = p.merge(o);
        assertEquals("b", result.getSelectorString());
        assertEquals("html", result.getSuffix());
    }
View Full Code Here

Examples of org.apache.sling.api.request.RequestPathInfo

   
    @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;
            }
        });
       
View Full Code Here

Examples of org.apache.sling.api.request.RequestPathInfo

    }

    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
View Full Code Here

Examples of org.apache.sling.api.request.RequestPathInfo

     * @throws NullPointerException if request or target is <code>null</code>.
     */
    private static StringBuilder appendSelectorsExtensionSuffixQuery(
            SlingHttpServletRequest request, StringBuilder target) {
        // append current selectors, extension and suffix
        final RequestPathInfo rpi = request.getRequestPathInfo();
        if (rpi.getExtension() != null) {

            if (rpi.getSelectorString() != null) {
                target.append('.').append(rpi.getSelectorString());
            }

            target.append('.').append(rpi.getExtension());

            if (rpi.getSuffix() != null) {
                target.append(rpi.getSuffix());
            }
        }

        // append current querystring
        if (request.getQueryString() != null) {
View Full Code Here

Examples of org.apache.sling.api.request.RequestPathInfo

        }

        @Override
        protected void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
            final String url = request.getParameter(PARAMETER_URL);
            final RequestPathInfo requestPathInfo = new DecomposedURL(url).getRequestPathInfo();
            String method = request.getParameter(PARAMETER_METHOD);
            if (StringUtils.isBlank(method)) {
                method = "GET";
            }

            final String CONSOLE_PATH_WARNING =
                    "<em>"
                    + "Note that in a real Sling request, the path might vary depending on the existence of"
                    + " resources that partially match it."
                    + "<br/>This utility does not take this into account and uses the first dot to split"
                    + " between path and selectors/extension."
                    + "<br/>As a workaround, you can replace dots with underline characters, for example, when testing such an URL."
                    + "</em>";

            ResourceResolver resourceResolver = null;
            try {
                resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);

                final PrintWriter pw = response.getWriter();

                pw.print("<form method='get'>");
                pw.println("<table class='content' cellpadding='0' cellspacing='0' width='100%'>");

                titleHtml(
                        pw,
                        "Servlet Resolver Test",
                        "To check which servlet is responsible for rendering a response, enter a request path into " +
                                 "the field and click 'Resolve' to resolve it.");

                tr(pw);
                tdLabel(pw, "URL");
                tdContent(pw);

                pw.print("<input type='text' name='");
                pw.print(PARAMETER_URL);
                pw.print("' value='");
                if ( url != null ) {
                    pw.print(ResponseUtil.escapeXml(url));
                }
                pw.println("' class='input' size='50'>");
                closeTd(pw);
                closeTr(pw);
                closeTr(pw);

                tr(pw);
                tdLabel(pw, "Method");
                tdContent(pw);
                pw.print("<select name='");
                pw.print(PARAMETER_METHOD);
                pw.println("'>");
                pw.println("<option value='GET'>GET</option>");
                pw.println("<option value='POST'>POST</option>");
                pw.println("</select>");
                pw.println("&nbsp;&nbsp;<input type='submit' value='Resolve' class='submit'>");

                closeTd(pw);
                closeTr(pw);

                if (StringUtils.isNotBlank(url)) {
                    tr(pw);
                    tdLabel(pw, "Decomposed URL");
                    tdContent(pw);
                    pw.println("<dl>");
                    pw.println("<dt>Path</dt>");
                    pw.print("<dd>");
                    pw.print(ResponseUtil.escapeXml(requestPathInfo.getResourcePath()));
                    pw.print("<br/>");
                    pw.print(CONSOLE_PATH_WARNING);
                    pw.println("</dd>");
                    pw.println("<dt>Selectors</dt>");
                    pw.print("<dd>");
                    if (requestPathInfo.getSelectors().length == 0) {
                        pw.print("&lt;none&gt;");
                    } else {
                        pw.print("[");
                        pw.print(ResponseUtil.escapeXml(StringUtils.join(requestPathInfo.getSelectors(), ", ")));
                        pw.print("]");
                    }
                    pw.println("</dd>");
                    pw.println("<dt>Extension</dt>");
                    pw.print("<dd>");
                    pw.print(ResponseUtil.escapeXml(requestPathInfo.getExtension()));
                    pw.println("</dd>");
                    pw.println("</dl>");
                    pw.println("</dd>");
                    pw.println("<dt>Suffix</dt>");
                    pw.print("<dd>");
                    pw.print(ResponseUtil.escapeXml(requestPathInfo.getSuffix()));
                    pw.println("</dd>");
                    pw.println("</dl>");
                    closeTd(pw);
                    closeTr(pw);
                }

                if (StringUtils.isNotBlank(requestPathInfo.getResourcePath())) {
                    final Collection<Resource> servlets;
                    Resource resource = resourceResolver.resolve(requestPathInfo.getResourcePath());
                    if (resource.adaptTo(Servlet.class) != null) {
                        servlets = Collections.singleton(resource);
                    } else {
                        final ResourceCollector locationUtil = ResourceCollector.create(
                                resource,
                                requestPathInfo.getExtension(),
                                executionPaths,
                                defaultExtensions,
                                method,
                                requestPathInfo.getSelectors());
                        servlets = locationUtil.getServlets(resourceResolver);
                    }
                    tr(pw);
                    tdLabel(pw, "&nbsp;");
                    tdContent(pw);
View Full Code Here

Examples of org.apache.sling.api.request.RequestPathInfo

            // required for a null resource
        }
    }

    public void testTrailingDot() {
        RequestPathInfo p = new SlingRequestPathInfo(new MockResource(
            "/some/path", "."));
        assertEquals("/some/path", p.getResourcePath());
        assertNull("Selectors are null",p.getSelectorString());
        assertEquals(0, p.getSelectors().length);
        assertNull("Extension is null",p.getExtension());
        assertNull("Suffix is null", p.getSuffix());
    }
View Full Code Here

Examples of org.apache.sling.api.request.RequestPathInfo

        assertNull("Extension is null",p.getExtension());
        assertNull("Suffix is null", p.getSuffix());
    }

    public void testTrailingDotWithSuffix() {
        RequestPathInfo p = new SlingRequestPathInfo(new MockResource(
            "/some/path", "./suffix"));
        assertEquals("/some/path", p.getResourcePath());
        assertNull("Selectors are null",p.getSelectorString());
        assertEquals(0, p.getSelectors().length);
        assertNull("Extension is null",p.getExtension());
        assertEquals("/suffix", p.getSuffix());
    }
View Full Code Here

Examples of org.apache.sling.api.request.RequestPathInfo

        assertNull("Extension is null",p.getExtension());
        assertEquals("/suffix", p.getSuffix());
    }

    public void testTrailingDotDot() {
        RequestPathInfo p = new SlingRequestPathInfo(new MockResource(
            "/some/path", ".."));
        assertEquals("/some/path", p.getResourcePath());
        assertNull("Selectors are null",p.getSelectorString());
        assertEquals(0, p.getSelectors().length);
        assertNull("Extension is null",p.getExtension());
        assertNull("Suffix is null",p.getSuffix());
    }
View Full Code Here

Examples of org.apache.sling.api.request.RequestPathInfo

        assertNull("Extension is null",p.getExtension());
        assertNull("Suffix is null",p.getSuffix());
    }

    public void testTrailingDotDotWithSuffix() {
        RequestPathInfo p = new SlingRequestPathInfo(new MockResource(
            "/some/path", "../suffix"));
        assertEquals("/some/path", p.getResourcePath());
        assertNull("Selectors are null",p.getSelectorString());
        assertEquals(0, p.getSelectors().length);
        assertNull("Extension is null",p.getExtension());
        assertEquals("/suffix", p.getSuffix());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.