Examples of ValueMap


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

    /** Dump given resource in JSON, optionally recursing into its objects */
    private static JSONObject create(final Resource resource,
            final int currentRecursionLevel,
            final int maxRecursionLevels)
    throws JSONException {
        final ValueMap valueMap = resource.adaptTo(ValueMap.class);

        @SuppressWarnings("unchecked")
        final Map propertyMap = (valueMap != null)
                ? valueMap
                : resource.adaptTo(Map.class);
View Full Code Here

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

    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();
View Full Code Here

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

    @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));
        assertEquals((Integer) 595, props.get("tiff:ImageLength", Integer.class));
        assertEquals(4.64385986328125d, props.get("dam:ApertureValue", Double.class), 0.00000000001d);

        assertArrayEquals(new String[] { "stockphotography:business/business_people", "properties:style/color",
                "properties:orientation/landscape" }, props.get("app:tags", String[].class));
    }
View Full Code Here

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

     * @param config
     * @return
     */
    private static boolean isHeartBeatCurrent(
            Resource aClusterInstanceResource, final Config config) {
        final ValueMap properties = aClusterInstanceResource.adaptTo(ValueMap.class);
        final Date lastHeartbeat = properties.get("lastHeartbeat", Date.class);
        final long now = System.currentTimeMillis();
        if (lastHeartbeat == null) {
            return false;
        }
        final long then = lastHeartbeat.getTime();
View Full Code Here

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

    protected ValueMap getValueMap(Object adaptable) {
        if (adaptable instanceof ValueMap) {
            return (ValueMap) adaptable;
        } else if (adaptable instanceof Adaptable) {
            ValueMap map = ((Adaptable) adaptable).adaptTo(ValueMap.class);
            return map;
        } else {
            return null;
        }
    }
View Full Code Here

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

                }
            }

            if (resourcePath == null && name != null) {
                // try to get from value map
                ValueMap map = getValueMap(adaptable);
                if (map != null) {
                    resourcePath = map.get(name, String.class);
                }
            }
        }

        if (resourcePath != null) {
View Full Code Here

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

    /**
     * Returns the id of this view.
     * @return the id of this view
     */
    public String getViewId() {
      final ValueMap props = getResource().adaptTo(ValueMap.class);
      final String clusterId = props.get(VIEW_PROPERTY_CLUSTER_ID, String.class);
      if (clusterId != null && clusterId.length() > 0) {
        return clusterId;
      } else {
        return getResource().getName();
      }
View Full Code Here

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

        return "valuemap";
    }

    public Object getValue(Object adaptable, String name, Type type, AnnotatedElement element,
            DisposalCallbackRegistry callbackRegistry) {
        ValueMap map = getValueMap(adaptable);
        if (map == null) {
            return null;
        } else if (type instanceof Class<?>) {
            Class<?> clazz = (Class<?>) type;
            try {
                return map.get(name, clazz);
            } catch (ClassCastException e) {
                // handle case of primitive/wrapper arrays
                if (clazz.isArray()) {
                    Class<?> componentType = clazz.getComponentType();
                    if (componentType.isPrimitive()) {
                        Class<?> wrapper = ClassUtils.primitiveToWrapper(componentType);
                        if (wrapper != componentType) {
                            Object wrapperArray = map.get(name, Array.newInstance(wrapper, 0).getClass());
                            if (wrapperArray != null) {
                                return unwrapArray(wrapperArray, componentType);
                            }
                        }
                    } else {
                        Class<?> primitiveType = ClassUtils.wrapperToPrimitive(componentType);
                        if (primitiveType != componentType) {
                            Object primitiveArray = map.get(name, Array.newInstance(primitiveType, 0).getClass());
                            if (primitiveArray != null) {
                                return wrapArray(primitiveArray, componentType);
                            }
                        }
                    }
                }
                return null;
            }
        } else if (type instanceof ParameterizedType) {
            // list support
            ParameterizedType pType = (ParameterizedType) type;
            if (pType.getActualTypeArguments().length != 1) {
                return null;
            }
            Class<?> collectionType = (Class<?>) pType.getRawType();
            if (!(collectionType.equals(Collection.class) || collectionType.equals(List.class))) {
                return null;
            }

            Class<?> itemType = (Class<?>) pType.getActualTypeArguments()[0];
            Object array = map.get(name, Array.newInstance(itemType, 0).getClass());
            if (array == null) {
                return null;

            }
View Full Code Here

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

        return true;
    }

    /** Compile a string builder containing the properties of a resource - used for logging **/
    public static StringBuilder getPropertiesForLogging(final Resource resource) {
        ValueMap valueMap;
        try{
            valueMap = resource.adaptTo(ValueMap.class);
        } catch(RuntimeException re) {
            return new StringBuilder("non-existing resource: "+resource+" ("+re.getMessage()+")");
        }
        if (valueMap==null) {
            return new StringBuilder("non-existing resource: "+resource+" (no ValueMap)");
        }
        final Set<Entry<String, Object>> entrySet = valueMap.entrySet();
        final StringBuilder sb = new StringBuilder();
        for (Iterator<Entry<String, Object>> it = entrySet.iterator(); it
                .hasNext();) {
            Entry<String, Object> entry = it.next();
            sb.append(" ");
View Full Code Here

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

    private void readProperties(final Resource res) {
        final Map<String, String> props = new HashMap<String, String>();
        if (res != null) {
            final Resource propertiesChild = res.getChild("properties");
            if (propertiesChild != null) {
                final ValueMap properties = propertiesChild.adaptTo(ValueMap.class);
                if (properties != null) {
                    for (Iterator<String> it = properties.keySet().iterator(); it
                            .hasNext();) {
                        String key = it.next();
                        if (!key.equals("jcr:primaryType")) {
                            props.put(key, properties.get(key, String.class));
                        }
                    }
                }
            }
        }
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.