Package org.apache.sling.api.resource

Examples of org.apache.sling.api.resource.ResourceResolver


     */
    public long lastModified(final String path) {
        if ( path.startsWith(":") ) {
            return this.classLoaderWriter.getLastModified(path.substring(1));
        }
        ResourceResolver resolver = requestResourceResolver.get();
        if (resolver != null) {
            try {
                final Resource resource = resolver.getResource(cleanPath(path, true));
                if (resource != null) {
                    ResourceMetadata meta = resource.getResourceMetadata();
                    long modTime = meta.getModificationTime();
                    return (modTime > 0) ? modTime : 0;
                }
View Full Code Here


    // ---------- Helper Methods for JspServletContext -------------------------


    URL getURL(final String path) throws MalformedURLException {
        ResourceResolver resolver = requestResourceResolver.get();
        if (resolver != null) {
            try {
                final Resource resource = resolver.getResource(cleanPath(path, true));
                return (resource != null) ? resource.adaptTo(URL.class) : null;
            } catch (final SlingException se) {
                throw (MalformedURLException) new MalformedURLException(
                    "Cannot get URL for " + path).initCause(se);
            }
View Full Code Here

    }

    Set<String> getResourcePaths(final String path) {
        final Set<String> paths = new HashSet<String>();

        ResourceResolver resolver = requestResourceResolver.get();
        if (resolver != null) {
            try {
                final String cleanedPath = cleanPath(path, false);
                final boolean startsWithWebInfTags = cleanedPath.startsWith(WEB_INF_TAGS);

                Resource resource = resolver.getResource(startsWithWebInfTags ? cleanedPath.substring(WEB_INF_TAGS.length()) : cleanedPath);
                if (resource != null) {
                    Iterator<Resource> entries = resolver.listChildren(resource);
                    while (entries.hasNext()) {
                        final String entryPath = entries.next().getPath();
                        if (startsWithWebInfTags) {
                            paths.add(WEB_INF_TAGS + entryPath);
                        } else {
View Full Code Here

        }

        final int query = localTarget.indexOf('?');
        final String path = (query > 0) ? localTarget.substring(0, query) : localTarget;

        ResourceResolver resolver = getResourceResolver(request);
        if (resolver != null) {
            // assume all is fine if the path resolves to a resource
            if (!ResourceUtil.isNonExistingResource(resolver.resolve(request, path))) {
                return true;
            }

            // not resolving to a resource, check for illegal characters
        }
View Full Code Here

    private static final String[] USERS = new String[] {"slingshot1", "slingshot2"};

    @Activate
    protected void activate() throws LoginException, PersistenceException, RepositoryException {
        logger.info("Setting up SlingShot...");
        ResourceResolver resolver = null;
        try {
            resolver = this.factory.getAdministrativeResourceResolver(null);
            setupUsers(resolver);
            setupContent(resolver);
            setupACL(resolver);
        } finally {
            if ( resolver != null ) {
                resolver.close();
            }
        }
        logger.info("Finished setting up SlingShot");
    }
View Full Code Here

        final String userId = request.getRemoteUser();

        logger.debug("New rating from {} : {}", userId, rating);

        // save rating
        ResourceResolver resolver = null;
        try {
            resolver = factory.getAdministrativeResourceResolver(null);

            final Resource reqResource = resolver.getResource(request.getResource().getPath());

            SlingshotUtil.setOwnRating(reqResource.getParent(), userId, Integer.valueOf(rating));
        } catch ( final LoginException le ) {
            throw new ServletException("Unable to login", le);
        } finally {
            if ( resolver != null ) {
                resolver.close();
            }
        }

        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");
View Full Code Here

    protected SessionProvider getSessionProvider() {
        return new SessionProvider() {

            public Session getSession(final HttpServletRequest req, final Repository repository, final String workspace)
                    throws LoginException, RepositoryException, ServletException {
                final ResourceResolver resolver = (ResourceResolver) req.getAttribute(AuthenticationSupport.REQUEST_ATTRIBUTE_RESOLVER);
                if (resolver != null) {
                    final Session session = resolver.adaptTo(Session.class);
                    if (session != null) {
                        final Session newSession = getLongLivedSession(session);
                        log.debug("getSession: Creating new Session ({}) for {}", newSession, newSession.getUserID());
                        return newSession;
                    }
View Full Code Here

                    + "<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);

                    if (servlets == null || servlets.isEmpty()) {
                        pw.println("Could not find a suitable servlet for this request!");
                    } else {
                        pw.print("Candidate servlets and scripts in order of preference for method ");
                        pw.print(ResponseUtil.escapeXml(method));
                        pw.println(":<br/>");
                        pw.println("<ol class='servlets'>");
                        outputServlets(pw, servlets.iterator());
                        pw.println("</ol>");
                    }
                    pw.println("</td>");
                    closeTr(pw);
                }

                pw.println("</table>");
                pw.print("</form>");
            } catch (LoginException e) {
                throw new ServletException(e);
            } finally {
                if (resourceResolver != null) {
                    resourceResolver.close();
                }
            }
        }
View Full Code Here

                return;
            }
        }
       
        assertNotNull("Expecting ResourceResolverFactory within " + timeout + " seconds");
        ResourceResolver rr = null;
        try {
            final ResourceResolverFactory f = (ResourceResolverFactory)bundleContext.getService(ref);
            rr = f.getAdministrativeResourceResolver(null);
            rr.getResource("/");
        } finally {
            if(rr != null) {
                rr.close();
            }
            bundleContext.ungetService(ref);
        }
    }
View Full Code Here

    @Before
    public void setUp() throws Exception {
        RepositoryUtil.startRepository();
        this.adminSession = RepositoryUtil.getRepository().loginAdministrative(null);
        RepositoryUtil.registerSlingNodeTypes(adminSession);
        final ResourceResolver resolver = Mockito.mock(ResourceResolver.class);
        Mockito.when(resolver.adaptTo(Mockito.any(Class.class))).thenReturn(this.adminSession);
        Mockito.when(resolver.getResource(Mockito.anyString())).thenReturn(new JcrTestNodeResource(resolver, this.adminSession.getNode("/"), null));

        final ResourceResolverFactory factory = Mockito.mock(ResourceResolverFactory.class);
        Mockito.when(factory.getAdministrativeResourceResolver(Mockito.anyMap())).thenReturn(resolver);

        final EventAdmin mockEA = new EventAdmin() {
View Full Code Here

TOP

Related Classes of org.apache.sling.api.resource.ResourceResolver

Copyright © 2018 www.massapicom. 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.