Package org.apache.sling.api.resource

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


                    } else {
                        throw new RuntimeException(
                                "Unsupported property type: " + p.getType());
                    }
                }
                ValueMap valueMap = new ValueMapDecorator(map);
                return (AdapterType) valueMap;
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
View Full Code Here


    }

    @Test
    public void testPageContentProperties() {
        Resource resource = this.resourceResolver.getResource("/content/sample/en/toolbar/profiles/jcr:content");
        ValueMap props = ResourceUtil.getValueMap(resource);
        assertEquals(true, props.get("hideInNav", Boolean.class));

        assertEquals((Long) 1234567890123L, props.get("longProp", Long.class));
        assertEquals(1.2345d, props.get("decimalProp", Double.class), 0.00001d);
        assertEquals(true, props.get("booleanProp", Boolean.class));

        assertArrayEquals(new Long[] { 1234567890123L, 55L }, props.get("longPropMulti", Long[].class));
        assertArrayEquals(new Double[] { 1.2345d, 1.1d }, props.get("decimalPropMulti", Double[].class));
        assertArrayEquals(new Boolean[] { true, false }, props.get("booleanPropMulti", Boolean[].class));
    }
View Full Code Here

    }

    @Test
    public void testContentProperties() {
        Resource resource = this.resourceResolver.getResource("/content/sample/en/jcr:content/header");
        ValueMap props = ResourceUtil.getValueMap(resource);
        assertEquals("/content/dam/sample/header.png", props.get("imageReference", String.class));
    }
View Full Code Here

    private void assertPrimaryNodeType(final Resource resource, final String nodeType) throws RepositoryException {
        Node node = resource.adaptTo(Node.class);
        if (node != null) {
            assertEquals(nodeType, node.getPrimaryNodeType().getName());
        } else {
            ValueMap props = ResourceUtil.getValueMap(resource);
            assertEquals(nodeType, props.get(JcrConstants.JCR_PRIMARYTYPE));
        }
    }
View Full Code Here

    }

    @Test
    public void testCalendarEcmaFormat() {
        Resource resource = this.resourceResolver.getResource("/content/sample/en/jcr:content");
        ValueMap props = ResourceUtil.getValueMap(resource);

        Calendar calendar = props.get("app:lastModified", Calendar.class);
        assertNotNull(calendar);

        calendar.setTimeZone(TimeZone.getTimeZone("GMT+2"));

        assertEquals(2014, calendar.get(Calendar.YEAR));
View Full Code Here

    }
   
    @Test
    public void testCalendarISO8601Format() {
        Resource resource = this.resourceResolver.getResource("/content/sample/en/jcr:content");
        ValueMap props = ResourceUtil.getValueMap(resource);

        Calendar calendar = props.get("dateISO8601String", Calendar.class);
        assertNotNull(calendar);

        calendar.setTimeZone(TimeZone.getTimeZone("GMT+2"));
       
        assertEquals(2014, calendar.get(Calendar.YEAR));
View Full Code Here

            throw (InstantiationException)new InstantiationException(iae.getMessage()).initCause(iae);
        }
    }

    public static ValueMap getValueMap(final Resource resource) throws InstantiationException {
        final ValueMap vm = ResourceUtil.getValueMap(resource);
        // trigger full loading
        try {
            vm.size();
        } catch ( final IllegalArgumentException iae) {
            // the JCR implementation might throw an IAE if something goes wrong
            throw (InstantiationException)new InstantiationException(iae.getMessage()).initCause(iae);
        }
        return vm;
View Full Code Here

                "/content/test1/resource2",
                ImmutableMap.<String, Object> builder().put("jcr:title", "Test Title").put("stringProp", "value1")
                        .build());
        assertNotNull(resource);
        assertEquals("resource2", resource.getName());
        ValueMap props = ResourceUtil.getValueMap(resource);
        assertEquals("Test Title", props.get("jcr:title", String.class));
        assertEquals("value1", props.get("stringProp", String.class));
    }
View Full Code Here

    public void testSimplePropertyModel() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("first", "first-value");
        map.put("third", "third-value");
        map.put("fourth", true);
        ValueMap vm = new ValueMapDecorator(map);

        Resource res = mock(Resource.class);
        when(res.adaptTo(ValueMap.class)).thenReturn(vm);

        SimplePropertyModel model = factory.getAdapter(res, SimplePropertyModel.class);
View Full Code Here

    @Test
    public void testRequiredPropertyModel() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("first", "first-value");
        map.put("third", "third-value");
        ValueMap vm = spy(new ValueMapDecorator(map));

        Resource res = mock(Resource.class);
        when(res.adaptTo(ValueMap.class)).thenReturn(vm);

        ResourceModelWithRequiredField model = factory.getAdapter(res, ResourceModelWithRequiredField.class);
View Full Code Here

TOP

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

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.