Package org.apache.sling.api.resource

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


        // 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
        ResourceMetadata meta = getScriptResource().getResourceMetadata();
        String encoding = meta.getCharacterEncoding();
        if (encoding == null) {
            encoding = "UTF-8";
        }

        // access the value as a stream and return a buffered reader
View Full Code Here


     */
    public long lastModified(String fileName) {
        try {
            Resource resource = getResourceInternal(fileName);
            if (resource != null) {
                ResourceMetadata meta = resource.getResourceMetadata();
                long modTime = meta.getModificationTime();
                return (modTime > 0) ? modTime : 0;
            }

        } catch (SlingException se) {
            log.error("Cannot get last modification time for " + fileName, se);
View Full Code Here

        this.resourceResolver = resourceResolver;
        this.path = path;
        this.resourceTypeProviders = resourceTypeProviders;

        metadata = new ResourceMetadata();
        metadata.setResolutionPath(path);

        resourceSuperType = UNSET_RESOURCE_SUPER_TYPE;
    }
View Full Code Here

            renderDirectory(request, response);
            return;
        }

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

    private void streamResource(Resource resource, InputStream stream,
            SlingHttpServletResponse response) throws IOException {
        // finally stream the resource
        try {

            ResourceMetadata meta = resource.getResourceMetadata();
            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);
            }

            long length = meta.getContentLength();
            if (length > 0 && length < Integer.MAX_VALUE) {
                response.setContentLength((int) length);
            }

            OutputStream out = response.getOutputStream();
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

    static class MockResource implements Resource {

        private final ResourceMetadata metadata;

        MockResource(String resolutionPath, String resolutionPathInfo) {
            metadata = new ResourceMetadata();
            metadata.setResolutionPath(resolutionPath);
            metadata.setResolutionPathInfo(resolutionPathInfo);
        }
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.