Package org.apache.sling.api.resource

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


        if (maxRecursionLevels == -1 || currentLevel < maxRecursionLevels) {
            final Iterator<Resource> children = ResourceUtil.listChildren(resource);
            while (children.hasNext()) {
                count++;
                final Resource res = children.next();
                // SLING-2320: always allow enumeration of one's children;
                // DOS-limitation is for deeper traversals.
                if (count > maxResources && maxRecursionLevels != 1) {
                    return currentLevel;
                }
View Full Code Here


        // the child nodes
        if (recursionLevelActive(currentRecursionLevel, maxRecursionLevels)) {
            final Iterator<Resource> children = ResourceUtil.listChildren(resource);
            while (children.hasNext()) {
                final Resource n = children.next();
                createSingleResource(n, obj, currentRecursionLevel,
                    maxRecursionLevels);
            }
        }
View Full Code Here

        return testRoot;
    }

    @Test
    public void testGetResourcesAndValues() throws IOException, RepositoryException {
        Resource resource1 = resourceResolver.getResource(getTestRootNode().getPath() + "/node1");
        assertNotNull(resource1);
        assertEquals("node1", resource1.getName());

        ValueMap props = ResourceUtil.getValueMap(resource1);
        assertEquals(STRING_VALUE, props.get("stringProp", String.class));
        assertArrayEquals(STRING_ARRAY_VALUE, props.get("stringArrayProp", String[].class));
        assertEquals((Integer) INTEGER_VALUE, props.get("integerProp", Integer.class));
        assertEquals(DOUBLE_VALUE, props.get("doubleProp", Double.class), 0.0001);
        assertEquals(BOOLEAN_VALUE, props.get("booleanProp", Boolean.class));
        assertEquals(DATE_VALUE, props.get("dateProp", Date.class));
        assertEquals(CALENDAR_VALUE.getTime(), props.get("calendarProp", Calendar.class).getTime());

        Resource binaryPropResource = resource1.getChild("binaryProp");
        InputStream is = binaryPropResource.adaptTo(InputStream.class);
        byte[] dataFromResource = IOUtils.toByteArray(is);
        is.close();
        assertArrayEquals(BINARY_VALUE, dataFromResource);

        // read second time to ensure not the original input stream was returned
        InputStream is2 = binaryPropResource.adaptTo(InputStream.class);
        byte[] dataFromResource2 = IOUtils.toByteArray(is2);
        is2.close();
        assertArrayEquals(BINARY_VALUE, dataFromResource2);

        List<Resource> children = ImmutableList.copyOf(resource1.listChildren());
View Full Code Here

        assertEquals("node12", children.get(1).getName());
    }

    @Test
    public void testCreateNodeType() throws RepositoryException, PersistenceException {
        Resource parent = resourceResolver.getResource(getTestRootNode().getPath());

        Resource child = resourceResolver.create(parent, "nodeTypeResource", ImmutableMap.<String, Object> builder()
                .put("sling:resourceType", JcrConstants.NT_UNSTRUCTURED).build());
        assertNotNull(child);
        assertEquals(JcrConstants.NT_UNSTRUCTURED, child.getResourceType());
        assertEquals(JcrConstants.NT_UNSTRUCTURED, child.adaptTo(Node.class).getPrimaryNodeType().getName());
    }
View Full Code Here

        contentLoader.json("/json-import-samples/dam.json", "/content/dam/sample");
    }

    @Test
    public void testDamAssetMetadata() {
        Resource assetMetadata = this.resourceResolver
                .getResource("/content/dam/sample/portraits/scott_reynolds.jpg/jcr:content/metadata");
        ValueMap props = ResourceUtil.getValueMap(assetMetadata);

        assertEquals("Canon\u0000", props.get("tiff:Make", String.class));
        assertEquals((Long) 807L, props.get("tiff:ImageWidth", Long.class));
View Full Code Here

        assertEquals("user1", resolver1.getAttribute(ResourceResolverFactory.USER));
        assertEquals("user2", resolver2.getAttribute(ResourceResolverFactory.USER));
        */
       
        // add a resource in resolver 1
        Resource root = resolver1.getResource("/");
        resolver1.create(root, "test", ImmutableMap.<String, Object>of());
        resolver1.commit();
       
        // try to get resource in resolver 2
        Resource testResource2 = resolver2.getResource("/test");
        assertNotNull(testResource2);
       
        // delete resource and make sure it is removed in resolver 1 as well
        resolver2.delete(testResource2);
        resolver2.commit();
View Full Code Here

    @Test
    public void testBinaryFile() throws IOException {
        contentLoader.binaryFile("/sample-image.gif", "/content/binary/sample-image.gif");

        Resource fileResource = resourceResolver.getResource("/content/binary/sample-image.gif");
        assertSampleImageFileSize(fileResource);
        assertMimeType(fileResource.getChild(JcrConstants.JCR_CONTENT), "image/gif");
    }
View Full Code Here

    @Test
    public void testBinaryFileWithMimeType() throws IOException {
        contentLoader.binaryFile("/sample-image.gif", "/content/binary/sample-image.gif", "mime/test");

        Resource fileResource = resourceResolver.getResource("/content/binary/sample-image.gif");
        assertSampleImageFileSize(fileResource);
        assertMimeType(fileResource.getChild(JcrConstants.JCR_CONTENT), "mime/test");
    }
View Full Code Here

    @Test
    public void testBinaryResource() throws IOException {
        contentLoader.binaryResource("/sample-image.gif", "/content/binary/sample-image.gif");

        Resource fileResource = resourceResolver.getResource("/content/binary/sample-image.gif");
        assertSampleImageFileSize(fileResource);
        assertMimeType(fileResource, "image/gif");
    }
View Full Code Here

    @Test
    public void testBinaryResourceWithMimeType() throws IOException {
        contentLoader.binaryResource("/sample-image.gif", "/content/binary/sample-image.gif", "mime/test");

        Resource fileResource = resourceResolver.getResource("/content/binary/sample-image.gif");
        assertSampleImageFileSize(fileResource);
        assertMimeType(fileResource, "mime/test");
    }
View Full Code Here

TOP

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

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.