Package org.apache.sling.api.resource

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


        String firstPath = "/rootel";
        String thirdPath = "/apps/sling/sample";
        String secondPath = firstPath + "/child";

        final ResourceResolverContext ctx = getResourceResolverContext();
        final ResourceResolver firstResolver = Mockito.mock(ResourceResolver.class);
        final ResourceProvider first = Mockito.mock(ResourceProvider.class);
        Mockito.when(first.getResource(Mockito.any(ResourceResolver.class), Mockito.startsWith(firstPath))).thenReturn(new TestResource(firstResolver));
        final ResourceResolver secondResolver = Mockito.mock(ResourceResolver.class);
        final ResourceProvider second = Mockito.mock(ResourceProvider.class);
        Mockito.when(second.getResource(Mockito.any(ResourceResolver.class), Mockito.startsWith(secondPath))).thenReturn(new TestResource(secondResolver));
        final ResourceResolver thirdResolver = Mockito.mock(ResourceResolver.class);
        final ResourceProvider third = Mockito.mock(ResourceProvider.class);
        Mockito.when(third.getResource(Mockito.any(ResourceResolver.class), Mockito.startsWith(thirdPath))).thenReturn(new TestResource(thirdResolver));

        final Map<String, Object> firstProps = new HashMap<String, Object>();
        firstProps.put(Constants.SERVICE_ID, (long)1);
View Full Code Here


            // write content from form
            writeContent(jcrSession, group, reqProperties, changes);

            // update the group memberships
            ResourceResolver resourceResolver = null;
            try {
                //create a resource resolver to resolve the relative paths used for group membership values
                resourceResolver = resourceResolverFactory.getResourceResolver(jcrSession);
                Resource baseResource = resourceResolver.getResource(AuthorizableResourceProvider.SYSTEM_USER_MANAGER_GROUP_PATH);
                updateGroupMembership(baseResource, properties, group, changes);
            } finally {
                if (resourceResolver != null) {
                    resourceResolver.close();
                }
            }
        }
       
        return group;
View Full Code Here

        String firstPath = "/rootel";
        String thirdPath = "/apps/sling/sample";
        String secondPath = firstPath + "/child";

        final ResourceResolverContext ctx = getResourceResolverContext();
        final ResourceResolver firstResolver = Mockito.mock(ResourceResolver.class);
        final ResourceProvider first = Mockito.mock(ResourceProvider.class);
        Mockito.when(first.getResource(Mockito.any(ResourceResolver.class), Mockito.startsWith(firstPath))).thenReturn(new TestResource(firstResolver));
        final ResourceResolver secondResolver = Mockito.mock(ResourceResolver.class);
        final ResourceProvider second = Mockito.mock(ResourceProvider.class);
        Mockito.when(second.getResource(Mockito.any(ResourceResolver.class), Mockito.startsWith(secondPath))).thenReturn(new TestResource(secondResolver));
        final ResourceResolver thirdResolver = Mockito.mock(ResourceResolver.class);
        final ResourceProvider third = Mockito.mock(ResourceProvider.class);
        Mockito.when(third.getResource(Mockito.any(ResourceResolver.class), Mockito.startsWith(thirdPath))).thenReturn(new TestResource(thirdResolver));

        final Map<String, Object> firstProps = new HashMap<String, Object>();
        firstProps.put(Constants.SERVICE_ID, (long)1);
View Full Code Here

    @Test public void testRemoveTheOnlyProvider() {
        final ResourceProviderEntry e = new ResourceProviderEntry("/", null);
        long counter = 1;

        for(String path : new String[] { "/foo", "/", "/foo/bar" }) {
            final ResourceResolver resolver = Mockito.mock(ResourceResolver.class);
            final ResourceProvider p = Mockito.mock(ResourceProvider.class);
            Mockito.when(p.getResource(Mockito.any(ResourceResolver.class), Mockito.startsWith(path))).thenReturn(new TestResource(resolver));
            final ResourceResolverContext ctx = getResourceResolverContext();

            final Map<String, Object> props = new HashMap<String, Object>();
View Full Code Here

        if (parent == null) {
            throw new NullPointerException("parent is null");
        }
        try {
            String path = parent.getPath();
            ResourceResolver resourceResolver = parent.getResourceResolver();

            // handle children of /system/userManager
            if (SYSTEM_USER_MANAGER_PATH.equals(path)) {
                List<Resource> resources = new ArrayList<Resource>();
                if (resourceResolver != null) {
                    resources.add(getResource(resourceResolver,
                        SYSTEM_USER_MANAGER_USER_PATH));
                    resources.add(getResource(resourceResolver,
                        SYSTEM_USER_MANAGER_GROUP_PATH));
                }
                return resources.iterator();
            }

            int searchType = -1;
            if (SYSTEM_USER_MANAGER_USER_PATH.equals(path)) {
                searchType = PrincipalManager.SEARCH_TYPE_NOT_GROUP;
            } else if (SYSTEM_USER_MANAGER_GROUP_PATH.equals(path)) {
                searchType = PrincipalManager.SEARCH_TYPE_GROUP;
            }
            if (searchType != -1) {
                PrincipalIterator principals = null;
                Session session = resourceResolver.adaptTo(Session.class);
                if (session != null) {
                    PrincipalManager principalManager = AccessControlUtil.getPrincipalManager(session);
                    principals = principalManager.getPrincipals(searchType);
                }
View Full Code Here

    @Activate
    protected void activate() {


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

            Session session = resourceResolver.adaptTo(Session.class);

            JackrabbitSession jackrabbitSession = (JackrabbitSession) session;

            UserManager userManager =  jackrabbitSession.getUserManager();
View Full Code Here

        }

        public Resource next() {
            Principal nextPrincipal = principals.nextPrincipal();
            try {
                ResourceResolver resourceResolver = parent.getResourceResolver();
                if (resourceResolver != null) {
                    Session session = resourceResolver.adaptTo(Session.class);
                    if (session != null) {
                        UserManager userManager = AccessControlUtil.getUserManager(session);
                        if (userManager != null) {
                            Authorizable authorizable = userManager.getAuthorizable(nextPrincipal.getName());
                            if (authorizable != null) {
View Full Code Here

    /**
     * Set the thread context resource resolver.
     */
    ResourceResolver setRequestResourceResolver(final ResourceResolver resolver) {
        final ResourceResolver old = requestResourceResolver.get();
        requestResourceResolver.set(resolver);
        return old;
    }
View Full Code Here

        logger.debug("New comment from {} : {} - {}", new Object[] {userId, title, description});
        // TODO - check values

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

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

            final Map<String, Object> properties = new HashMap<String, Object>();
            properties.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, SlingshotConstants.RESOURCETYPE_COMMENT);
            properties.put(SlingshotConstants.PROPERTY_TITLE, title);
            properties.put(SlingshotConstants.PROPERTY_DESCRIPTION, description);
            properties.put(SlingshotConstants.PROPERTY_USER, userId);

            // we try it five times
            PersistenceException exception = null;
            Resource newResource = null;
            for(int i=0; i<5; i++) {
                try {
                    exception = null;
                    final String name = ResourceUtil.createUniqueChildName(reqResource, Util.filter(title));
                    newResource = resolver.create(reqResource, name, properties);

                    resolver.commit();
                    break;
                } catch ( final PersistenceException pe) {
                    resolver.revert();
                    resolver.refresh();
                    exception = pe;
                }
            }
            if ( exception != null ) {
                throw exception;
            }
            // order node at the top (if jcr based)
            final Node newNode = newResource.adaptTo(Node.class);
            if ( newNode != null ) {
                try {
                    final Node parent = newNode.getParent();
                    final Node firstNode = parent.getNodes().nextNode();
                    if ( !firstNode.getName().equals(newNode.getName()) ) {
                        parent.orderBefore(newNode.getName(), firstNode.getName());
                        newNode.getSession().save();
                    }
                } catch ( final RepositoryException re) {
                    logger.error("Unable to order comment to the top", re);
                }
            }
        } catch ( final LoginException le ) {
            throw new ServletException("Unable to login", le);
        } finally {
            if ( resolver != null ) {
                resolver.close();
            }
        }

        // send redirect at the end
        final String path = request.getResource().getParent().getPath();
View Full Code Here

    public InputStream getInputStream(final String path)
            throws FileNotFoundException, IOException {
        if ( path.startsWith(":") ) {
            return this.classLoaderWriter.getInputStream(path.substring(1));
        }
        ResourceResolver resolver = requestResourceResolver.get();
        if (resolver != null) {
            try {
                final Resource resource = resolver.getResource(cleanPath(path, true));
                if (resource != null) {
                    final InputStream stream = resource.adaptTo(InputStream.class);
                    if (stream != null) {
                        return stream;
                    }
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.