Package org.apache.sling.api.resource

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


    private int deleteCount;

    private void delete(final Resource rsrc )
    throws PersistenceException {
        final ResourceResolver resolver = rsrc.getResourceResolver();
        for(final Resource child : rsrc.getChildren()) {
            delete(child);
        }
        resolver.delete(rsrc);
        deleteCount++;
        if ( deleteCount >= 20 ) {
            resolver.commit();
            deleteCount = 0;
        }
    }
View Full Code Here


    }

    public void cleanup() {
        final ServiceReference ref = this.bc.getServiceReference(ResourceResolverFactory.class.getName());
        final ResourceResolverFactory factory = (ResourceResolverFactory) this.bc.getService(ref);
        ResourceResolver resolver = null;
        try {
            resolver = factory.getAdministrativeResourceResolver(null);
            final Resource rsrc = resolver.getResource(JobManagerConfiguration.DEFAULT_REPOSITORY_PATH);
            if ( rsrc != null ) {
                delete(rsrc);
                resolver.commit();
            }
        } catch ( final LoginException le ) {
            // ignore
        } catch (final PersistenceException e) {
            // ignore
        } finally {
            if ( resolver != null ) {
                resolver.close();
            }
        }
        this.sleep(1000);
    }
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

        this.max = batchSize;
    }

    public void delete(final Resource rsrc )
    throws PersistenceException {
        final ResourceResolver resolver = rsrc.getResourceResolver();
        for(final Resource child : rsrc.getChildren()) {
            delete(child);
        }
        resolver.delete(rsrc);
        count++;
        if ( count >= max ) {
            resolver.commit();
            count = 0;
        }
    }
View Full Code Here

                this.ignoreException(e);
                Thread.currentThread().interrupt();
                this.running = false;
            }
            if ( path != null && path.length() > 0 && this.running ) {
                ResourceResolver resolver = null;
                try {
                    resolver = this.resourceResolverFactory.getAdministrativeResourceResolver(null);
                    final Resource eventResource = resolver.getResource(path);
                    if ( DistributedEventAdminImpl.RESOURCE_TYPE_EVENT.equals(eventResource.getResourceType())) {
                        final Event e = this.readEvent(eventResource);
                        if ( e != null ) {
                            // we check event admin as processing is async
                            final EventAdmin localEA = this.eventAdmin;
                            if ( localEA != null ) {
                                localEA.postEvent(e);
                            } else {
                                this.logger.error("Unable to post event as no event admin is available.");
                            }
                        }
                    }
                } catch (final LoginException ex) {
                    this.logger.error("Exception during creation of resource resolver.", ex);
                } finally {
                    if ( resolver != null ) {
                        resolver.close();
                    }
                }
            }
        }
    }
View Full Code Here

        if (authorizable.isGroup()) {
            Group group = ((Group) authorizable);
            String groupPath = AuthorizableResourceProvider.SYSTEM_USER_MANAGER_GROUP_PREFIX
                + group.getID();

            ResourceResolver resolver = baseResource.getResourceResolver();
            boolean changed = false;
           
            UserManager userManager = AccessControlUtil.getUserManager(resolver.adaptTo(Session.class));

            // first remove any members posted as ":member@Delete"
            String[] membersToDelete = convertToStringArray(properties.get(SlingPostConstants.RP_PREFIX
                + "member" + SlingPostConstants.SUFFIX_DELETE));
            if (membersToDelete != null) {
View Full Code Here

    @Test
    public void test() throws Exception {
    String value = RandomStringUtils.randomAlphanumeric(10);

    ResourceResolver resolver = null;
    Node createdNode = null;
    try {
        resolver = rrFactory.getAdministrativeResourceResolver(null);
        Session session = resolver.adaptTo(Session.class);
        Node rootNode = session.getRootNode();
        createdNode = rootNode.addNode("test_" + RandomStringUtils.randomAlphanumeric(10));
        createdNode.setProperty("testProperty", value);
        session.save();

        Resource resource = resolver.getResource(createdNode.getPath());

        SlingPropertyAnnotationTestModel model = resource.adaptTo(SlingPropertyAnnotationTestModel.class);

        assertNotNull("Model is null", model);
        assertEquals("Test Property is not set correctly", value, model.getTestProperty());
    } finally {
        if (createdNode != null) {
        createdNode.remove();
        }
        if (resolver != null) {
        resolver.close();
        }
    }
    }
View Full Code Here

    @Test
    public void test() throws Exception {
        String value = RandomStringUtils.randomAlphanumeric(10);

        ResourceResolver resolver = null;
        Node createdNode = null;
        try {
            resolver = rrFactory.getAdministrativeResourceResolver(null);
            Session session = resolver.adaptTo(Session.class);
            Node rootNode = session.getRootNode();
            createdNode = rootNode.addNode("test_" + RandomStringUtils.randomAlphanumeric(10));
            createdNode.setProperty("testProperty", value);
            session.save();

            Resource resource = resolver.getResource(createdNode.getPath());
            SourceObject obj = new SourceObject(resource);

            ViaModel model = adapterManager.getAdapter(obj, ViaModel.class);

            assertNotNull("Model is null", model);
            assertEquals("Test Property is not set correctly", value, model.getTestProperty());
        } finally {
            if (createdNode != null) {
                createdNode.remove();
            }
            if (resolver != null) {
                resolver.close();
            }
        }
    }
View Full Code Here

        final String resource = AuthUtil.setLoginResourceAttribute(request,
            request.getRequestURI());

        if (includeLoginForm && (resourceResolverFactory != null)) {
            ResourceResolver resourceResolver = null;
            try {
                resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
                Resource loginFormResource = resourceResolver.resolve(loginForm);
                Servlet loginFormServlet = loginFormResource.adaptTo(Servlet.class);
                if (loginFormServlet != null) {
                    try {
                        loginFormServlet.service(request, response);
                        return true;
                    } catch (ServletException e) {
                        log.error("Failed to include the form: " + loginForm, e);
                    }
                }
            } catch (LoginException e) {
                log.error("Unable to get a resource resolver to include for the login resource. Will redirect instead.");
            } finally {
                if (resourceResolver != null) {
                    resourceResolver.close();
                }
            }
        }

        HashMap<String, String> params = new HashMap<String, String>();
View Full Code Here

        }

        final File[] children = parentFile.listFiles();

        if (children != null && children.length > 0) {
            final ResourceResolver resolver = parent.getResourceResolver();
            final String parentPath = parent.getPath();
            return new Iterator<Resource>() {
                int index = 0;

                Resource next = seek();
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.