Package org.apache.sling.api.resource

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


    @Test
    public void testSlingModelsOsgiService() {
        context.registerService(new MockMimeTypeService());

        ResourceResolver resolver = MockSling.newResourceResolver();
        OsgiServiceModel model = resolver.adaptTo(OsgiServiceModel.class);
        assertNotNull(model.getMimeTypeService());
        assertEquals("text/html", model.getMimeTypeService().getMimeType("html"));
    }
View Full Code Here


    @Test
    public void testOsgiService() {
        bundleContext.registerService(MimeTypeService.class.getName(), new MockMimeTypeService(), null);

        ResourceResolver resolver = MockSling.newResourceResolver();
        OsgiServiceModel model = resolver.adaptTo(OsgiServiceModel.class);
        assertNotNull(model);
        assertNotNull(model.getMimeTypeService());
        assertEquals("text/html", model.getMimeTypeService().getMimeType("html"));
    }
View Full Code Here

    private ResourceResolver resourceResolver;

    protected abstract ResourceResolverType getResourceResolverType();

    protected ResourceResolver newResourceResolver() {
        ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType());

        if (getResourceResolverType() == ResourceResolverType.JCR_MOCK) {
            try {
                // dummy namespace registrations to make sure sling JCR resolver
                // does not get mixed up with the prefixes
                NamespaceRegistry namespaceRegistry = resolver.adaptTo(Session.class).getWorkspace()
                        .getNamespaceRegistry();
                namespaceRegistry.registerNamespace("sling", "http://mock/sling");
                namespaceRegistry.registerNamespace("app", "http://mock/app");
                namespaceRegistry.registerNamespace("dam", "http://mock/dam");
            } catch (RepositoryException ex) {
View Full Code Here

    }
   
    @Test
    public void testMultipleResourceResolver() throws Exception {
        ResourceResolverFactory factory = newResourceResolerFactory();
        ResourceResolver resolver1 = factory.getResourceResolver(ImmutableMap.<String, Object>of(
                ResourceResolverFactory.USER, "user1"));
        ResourceResolver resolver2 = factory.getResourceResolver(ImmutableMap.<String, Object>of(
                ResourceResolverFactory.USER, "user2"));
       
        // validate user names
        // TODO: enable this tests when updated to latest jcr-mock/resourceresolver-mock versions
        /*
        assertEquals("user1", resolver1.getAttribute(ResourceResolverFactory.USER));
        assertEquals("user2", resolver2.getAttribute(ResourceResolverFactory.USER));
        */
       
        // add a resource in resolver 1
        Resource root = resolver1.getResource("/");
        resolver1.create(root, "test", ImmutableMap.<String, Object>of());
        resolver1.commit();
       
        // try to get resource in resolver 2
        Resource testResource2 = resolver2.getResource("/test");
        assertNotNull(testResource2);
       
        // delete resource and make sure it is removed in resolver 1 as well
        resolver2.delete(testResource2);
        resolver2.commit();
       
        assertNull(resolver1.getResource("/test"));
    }
View Full Code Here

* Abstract base class for injectors to consolidate common functionality.
*/
abstract class AbstractInjector {

    protected ResourceResolver getResourceResolver(Object adaptable) {
        ResourceResolver resolver = null;
        if (adaptable instanceof Resource) {
            resolver = ((Resource) adaptable).getResourceResolver();
        } else if (adaptable instanceof SlingHttpServletRequest) {
            resolver = ((SlingHttpServletRequest) adaptable).getResourceResolver();
        }
View Full Code Here

    private final HttpServletRequest request;

    private final Map<String, Boolean> featureCache;

    public ExecutionContextImpl(final HttpServletRequest request) {
        ResourceResolver resourceResolver = null;
        if (request != null) {
            Object resolverObject = request.getAttribute(REQUEST_ATTRIBUTE_RESOLVER);
            if (resolverObject instanceof ResourceResolver) {
                resourceResolver = (ResourceResolver) resolverObject;
            }
View Full Code Here

                }
            }
        }

        if (resourcePath != null) {
            ResourceResolver resolver = getResourceResolver(adaptable);
            if (resolver != null) {
                return resolver.getResource(resourcePath);
            }
        }

        return null;
    }
View Full Code Here

    /**
     * Delete this view from the repository
     */
    public void remove(boolean logErrorOnFailure) {
        final ResourceResolver resourceResolver = getResource().getResourceResolver();
        try{
            resourceResolver.delete(getResource());
            resourceResolver.commit();
        } catch(PersistenceException pe) {
            if (logErrorOnFailure) {
                logger.error("remove: Could not remove node: " + pe, pe);
            } else {
                logger.info("remove: Could not remove node: "+pe);
            }
            resourceResolver.refresh();
        }
    }
View Full Code Here

            }
            if (requestedClass.equals(SlingScriptHelper.class)) {
                return getSlingScriptHelper(request);
            }
        } else if (adaptable instanceof ResourceResolver) {
            ResourceResolver resourceResolver = (ResourceResolver) adaptable;
            if (requestedClass.equals(ResourceResolver.class)) {
                return resourceResolver;
            }
        } else if (adaptable instanceof Resource) {
            Resource resource = (Resource) adaptable;
View Full Code Here

        // try to connect
        try {
            handleImpersonation(request, authInfo);
            handlePasswordChange(request, authInfo);
            ResourceResolver resolver = resourceResolverFactory.getResourceResolver(authInfo);
            final boolean impersChanged = setSudoCookie(request, response, authInfo);

            if (sendLoginEvent != null) {
                postLoginEvent(authInfo);
            }

            // provide the resource resolver to the feedback handler
            request.setAttribute(REQUEST_ATTRIBUTE_RESOLVER, resolver);

            boolean processRequest = true;

            // custom feedback handler with option to redirect
            if (feedbackHandler != null) {
                processRequest = !feedbackHandler.authenticationSucceeded(request, response, authInfo);
            }

            if (processRequest) {
                if (AuthUtil.isValidateRequest(request)) {
                    AuthUtil.sendValid(response);
                    processRequest = false;
                } else if (impersChanged || feedbackHandler == null) {
                    processRequest = !DefaultAuthenticationFeedbackHandler.handleRedirect(request, response);
                }
            }

            if (processRequest) {
                // process: set required attributes
                setAttributes(resolver, authInfo.getAuthType(), request);
            } else {
                // terminate: cleanup
                resolver.close();
            }

            return processRequest;

        } catch (LoginException re) {
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.