Examples of ResourceMetaData


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

    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

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
        final ResourceMetadata meta = this.scriptResource.getResourceMetadata();
        String encoding = meta.getCharacterEncoding();
        if (encoding == null) {
            encoding = "UTF-8";
        }
        this.scriptEncoding = encoding;
    }
View Full Code Here

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

        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

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

        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

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

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

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

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

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

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

            } 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

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

        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

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

        }

        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
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.