Package org.apache.sling.api.resource

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


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

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


   * @see org.apache.sling.api.resource.ResourceDecorator#decorate(org.apache.sling.api.resource.Resource)
   */
  public Resource decorate(Resource resource) {
    Resource result = null;
    if (resource != null) {
      ResourceMetadata resourceMetadata = resource.getResourceMetadata();
      if (resourceMetadata != null) {
        String resolutionPathInfo = resourceMetadata.getResolutionPathInfo();
        result = getResourceEditorResourceWrapper(resource,resolutionPathInfo);
      }
    }
    return result;
  }
View Full Code Here

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

            } else {
                GenericList list = listPage.adaptTo(GenericList.class);
                if (list == null) {
                    return null;
                } else {
                    ResourceMetadata rm = new ResourceMetadata();
                    rm.setResolutionPath(path);
                    return new JsonResource(list, resourceResolver, rm);
                }
            }
        }
    }
View Full Code Here

        this.resourceResolver = resourceResolver;
        this.bundle = bundle;
        this.mappedPath = mappedPath;

        metadata = new ResourceMetadata();
        metadata.setResolutionPath(resourcePath);
        metadata.setCreationTime(bundle.getLastModified());
        metadata.setModificationTime(bundle.getLastModified());

        if (resourcePath.endsWith("/")) {
View Full Code Here

        }

        Resource resource = request.getResource();

        // 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;
        }

        // fall back to plain text rendering if the resource has no stream
        InputStream stream = resource.adaptTo(InputStream.class);
        if (stream == null) {
            super.doGet(request, response);
            return;
        }

        // finally stream the resource
        try {

            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

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

    static class MockResource implements Resource {

        private final ResourceMetadata metadata;

        MockResource(String resolutionPath) {
            metadata = new ResourceMetadata();
            metadata.setResolutionPath(resolutionPath);
        }
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.servlet = servlet;
        this.path = path;
        this.resourceType = ServletResourceProviderFactory.ensureServletNameExtension(path);

        this.metadata = new ResourceMetadata();
        metadata.setResolutionPath(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.