Package org.apache.sling.api.resource

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.getBundle().getLastModified());
        metadata.setModificationTime(bundle.getBundle().getLastModified());

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


     * length, last modification time and the resource path (same as
     * {@link #getPath()}).
     */
    public ResourceMetadata getResourceMetadata() {
        if (metaData == null) {
            metaData = new ResourceMetadata();
            metaData.setContentLength(file.length());
            metaData.setModificationTime(file.lastModified());
            metaData.setResolutionPath(resourcePath);
            if ( this.file.isDirectory() ) {
                metaData.put(ResourceMetadata.INTERNAL_CONTINUE_RESOLVING, Boolean.TRUE);
View Full Code Here

            } catch(MalformedURLException ignore) {
            }
        }
        final int firstDot = fullPath.indexOf(".");
       
        final ResourceMetadata metadata = new ResourceMetadata();
        final Resource r = new SyntheticResource(null, metadata, null);
        metadata.setResolutionPath(firstDot < 0 ? fullPath : fullPath.substring(0, firstDot));
        metadata.setResolutionPathInfo(firstDot < 0 ? null : fullPath.substring(firstDot));
        requestPathInfo = new SlingRequestPathInfo(r);
    }
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

        ResourceResolver resolver = requestResourceResolver.get();
        if (resolver != null) {
            try {
                final Resource resource = resolver.getResource(cleanPath(path, true));
                if (resource != null) {
                    ResourceMetadata meta = resource.getResourceMetadata();
                    long modTime = meta.getModificationTime();
                    return (modTime > 0) ? modTime : 0;
                }
            } catch (final SlingException se) {
                log.error("Cannot get last modification time for " + path, se);
            }
View Full Code Here

/** Test the StarResource */
public class StarResourceTest {

  private void assertSplit(String requestPath, String path, String pathInfo) {
    final ResourceMetadata rm = StarResource.getResourceMetadata(requestPath);
    assertEquals("For requestPath=" + requestPath + ", path matches", path, rm.getResolutionPath());
    assertEquals("For requestPath=" + requestPath + ", pathInfo matches", pathInfo, rm.getResolutionPathInfo());
  }
View Full Code Here

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

        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

    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

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

        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.