Package org.apache.sling.api.resource

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


     */
    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

    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

            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

     * @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

            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

    private void prepareOriginalResource(Resource mockResource, String path) {
        // prepare resource
        when(mockResource.getPath()).thenReturn(path);
        when(mockResource.getResourceType()).thenReturn(RESOURCE_TYPE);
        when(mockResource.getResourceSuperType()).thenReturn(null);
        ResourceMetadata resourceMetadata = new ResourceMetadata();
        resourceMetadata.setResolutionPath(path);
        when(mockResource.getResourceMetadata()).thenReturn(resourceMetadata);
        when(mockResource.getResourceResolver()).thenReturn(resourceResolver);

        // mount in resource tree
        when(resourceResolver.getResource(path)).thenReturn(mockResource);
View Full Code Here

        // Now know how to get the input stream, we still have to decide
        // on the encoding of the stream's data. Primarily we assume it is
        // UTF-8, which is a default in many places in JCR. Secondarily
        // we try to get a jcr:encoding property besides the data property
        // to provide a possible encoding
        final ResourceMetadata meta = this.scriptResource.getResourceMetadata();
        String encoding = meta.getCharacterEncoding();
        if (encoding == null) {
            encoding = "UTF-8";
        }
        this.scriptEncoding = encoding;
    }
View Full Code Here

        super.assertEquals(expected, actual);
    }

    private void assertResourceMetaData(Object metaData) throws Exception {
        if (metaData instanceof ResourceMetadata) {
            ResourceMetadata rm = (ResourceMetadata) metaData;
            rm.getResolutionPath().equals(node.getPath());
        } else {
            fail("Expected ResourceMetadata, got " + metaData);
        }
    }
View Full Code Here

        private final ResourceMetadata metadata;

        TestResource(Node node) throws RepositoryException {
            this.node = node;
            this.path = node.getPath();
            this.metadata = new ResourceMetadata();
            this.metadata.setResolutionPath(this.path);
        }
View Full Code Here

TOP

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

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.