Examples of ResourceMetaData


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

     */
    private Resource buildResource(String fullpath, Iterable<Resource> children, ResourceResolver resourceResolver, ResourceProvider provider, String ... properties) {
        Resource resource = Mockito.mock(Resource.class);
        Mockito.when(resource.getName()).thenReturn(getName(fullpath));
        Mockito.when(resource.getPath()).thenReturn(fullpath);
        ResourceMetadata resourceMetadata = new ResourceMetadata();
        Mockito.when(resource.getResourceMetadata()).thenReturn(resourceMetadata);
        Mockito.when(resource.listChildren()).thenReturn(children.iterator());
        Mockito.when(resource.getResourceResolver()).thenReturn(resourceResolver);

        // register the resource with the provider
        if ( provider != null ) {
            Mockito.when(provider.listChildren(resource)).thenReturn(children.iterator());
            if ( resourceResolver != null) {
                Mockito.when(provider.getResource(Mockito.eq(resourceResolver), Mockito.eq(fullpath))).thenReturn(resource);
                Mockito.when(provider.getResource(Mockito.eq(resourceResolver), Mockito.any(HttpServletRequest.class), Mockito.eq(fullpath))).thenReturn(resource);
            } else {
                Mockito.when(provider.getResource(Mockito.any(ResourceResolver.class), Mockito.eq(fullpath))).thenReturn(resource);
                Mockito.when(provider.getResource(Mockito.any(ResourceResolver.class), Mockito.any(HttpServletRequest.class), Mockito.eq(fullpath))).thenReturn(resource);
            }
        }
        if ( properties != null ) {
            ValueMap vm = new SimpleValueMapImpl();
            for ( int i=0; i < properties.length; i+=2) {
                resourceMetadata.put(properties[i], properties[i+1]);
                vm.put(properties[i], properties[i+1]);
            }
            Mockito.when(resource.getValueMap()).thenReturn(vm);
            Mockito.when(resource.adaptTo(Mockito.eq(ValueMap.class))).thenReturn(vm);
        } else {
View Full Code Here

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

        return super.adaptTo(type);
    }

    /** Get our ResourceMetadata for given path */
    static ResourceMetadata getResourceMetadata(String path) {
        ResourceMetadata result = new ResourceMetadata();

        // The path is up to /*, what follows is pathInfo
        final int index = path.indexOf(SLASH_STAR);
        if (index >= 0) {
            result.setResolutionPath(path.substring(0, index) + SLASH_STAR);
            result.setResolutionPathInfo(path.substring(index
                    + SLASH_STAR.length()));
        } else {
            result.setResolutionPath(path);
        }
        return result;
    }
View Full Code Here

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

    public JcrPropertyResource(final ResourceResolver resourceResolver,
                               final String path,
                               final Property property)
    throws RepositoryException {
        super(resourceResolver, path, property, new ResourceMetadata());
        this.resourceType = getResourceTypeForNode(property.getParent())
                + "/" + property.getName();
        if (PropertyType.BINARY != getProperty().getType()) {
            this.getResourceMetadata().setContentType("text/plain");
            this.getResourceMetadata().setCharacterEncoding("UTF-8");
View Full Code Here

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

            this.resourceType = "sling/group";
        } else {
            this.resourceType = "sling/user";
        }

        this.metadata = new ResourceMetadata();
        metadata.setResolutionPath(path);
    }
View Full Code Here

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

    }

    protected Resource mockResource(String path) {
        final Resource result = Mockito.mock(Resource.class);
        Mockito.when(result.getPath()).thenReturn(path);
        final ResourceMetadata m = new ResourceMetadata();
        Mockito.when(result.getResourceMetadata()).thenReturn(m);
        return result;
    }
View Full Code Here

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

     */
    public SuperimposingResource(Resource mappedResource, String path) {
        this.resource = mappedResource;

        // make a copy of resource metadata object
        this.resourceMetadata = new ResourceMetadata();
        if (mappedResource.getResourceMetadata()!=null) {
            this.resourceMetadata.putAll(mappedResource.getResourceMetadata());
        }

        this.path = path;
View Full Code Here

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

    static class MockResource extends AbstractResource {

        private final ResourceMetadata metadata;

        MockResource(String resolutionPath, String resolutionPathInfo) {
            metadata = new ResourceMetadata();
            metadata.setResolutionPath(resolutionPath);
            metadata.setResolutionPathInfo(resolutionPathInfo);
        }
View Full Code Here

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

            return;
        }

        // check the last modification time and If-Modified-Since header
        if (!included) {
            ResourceMetadata meta = resource.getResourceMetadata();
            long modifTime = meta.getModificationTime();
            if (unmodified(request, modifTime)) {
                response.setStatus(SC_NOT_MODIFIED);
                return;
            }
        }
View Full Code Here

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

     * @param response
     */
    private void setHeaders(Resource resource,
            SlingHttpServletResponse response) {

        final ResourceMetadata meta = resource.getResourceMetadata();
        final long modifTime = meta.getModificationTime();
        if (modifTime > 0) {
            response.setDateHeader(HEADER_LAST_MODIFIED, modifTime);
        }

        final String defaultContentType = "application/octet-stream";
        String contentType = meta.getContentType();
        if (contentType == null || defaultContentType.equals(contentType)) {
            // if repository doesn't provide a content-type, or
            // provides the
            // default one,
            // try to do better using our servlet context
            final String ct = getServletContext().getMimeType(
                resource.getPath());
            if (ct != null) {
                contentType = ct;
            }
        }
        if (contentType != null) {
            response.setContentType(contentType);
        }

        String encoding = meta.getCharacterEncoding();
        if (encoding != null) {
            response.setCharacterEncoding(encoding);
        }
    }
View Full Code Here

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

            suffix = "                                               ".substring(
                0, 32 - displayName.length());
        }
        pw.printf("<a href='%s'>%s</a>%s", name, displayName, suffix);

        ResourceMetadata meta = resource.getResourceMetadata();
        long lastModified = meta.getModificationTime();
        pw.print("    " + new Date(lastModified) + "    ");

        long length = meta.getContentLength();
        if (length > 0) {
            pw.print(length);
        } else {
            pw.print('-');
        }
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.