private Color getHexColor(final ValueMap properties) { String hexcolor = properties.get(KEY_COLOR, properties.get(KEY_COLOR_ALIAS, String.class)); Color color = null; if (hexcolor != null) { try { color = Color.decode("0x" + hexcolor); } catch (NumberFormatException ex) { log.warn("Invalid hex color specified: {}", hexcolor); } } return color; }
static Date lastModified(Resource resource) { if (resource != null) { return resource.getValueMap().get(NameConstants.PN_LAST_MOD, new Date()); } return new Date(); } }
/** * Conventience method for getting a single-value Long property from a resource. * @param resource The resource from which to get the property. * @param namePattern Property name. * @return Property value. */ public static Long getPropertyLong(Resource resource, String namePattern) { return resource.getValueMap().get(namePattern, Long.class); }
private Object getValueFromMap(Class<?> type) { if (inheritanceValueMap != null) { return inheritanceValueMap.getInherited(name, type); } else { return valueMap.get(name, type); } }
protected boolean matches(String componentPath, Resource resource) { ValueMap map = resource.adaptTo(ValueMap.class); if (map == null) { return false; } String pattern = map.get("pattern", String.class); if (pattern == null) { return false; } return componentPath.matches(pattern); }
/** * Convenience method for getting a single-value Calendar property from * a resource. * * @param resource The resource from which to get the property. * @param namePattern Property name. * @return Property value. */ public static Calendar getPropertyCalendar(Resource resource, String namePattern) { return resource.getValueMap().get(namePattern, Calendar.class); }
@Override public final Layer transform(final Layer layer, final ValueMap properties) { if (properties == null || properties.isEmpty()) { log.warn("Transform [ {} ] requires parameters.", TYPE); return layer; } log.debug("Transforming with [ {} ]", TYPE); int degrees = properties.get(KEY_DEGREES, 0) % TOTAL_DEGREES; layer.rotate(degrees); return layer; } }
/** * @see org.apache.sling.api.wrappers.ValueMapDecorator#get(java.lang.Object) */ @Override public Object get(final Object key) { if ( key == null ) { return null; } final String name = key.toString(); return this.getValueMap(name).get(this.getPropertyName(name)); } }
/** * @see org.apache.sling.api.resource.ValueMap#get(java.lang.String, java.lang.Object) */ @Override public <T> T get(final String name, T defaultValue) { return this.getValueMap(name).get(this.getPropertyName(name), defaultValue); }
/** * {@inheritDoc} */ public <T> T get(String name, Class<T> type) { if (base instanceof ValueMap) { // shortcut if decorated map is ValueMap return ((ValueMap)base).get(name, type); } return ObjectConverter.convert(get(name), type); }
/** * @see org.apache.sling.api.resource.ValueMap#get(java.lang.String, java.lang.Class) */ @Override public <T> T get(final String name, final Class<T> type) { return this.getValueMap(name).get(this.getPropertyName(name), type); }
@Override protected void visit(Resource resource) { try { final String primaryType = resource.getValueMap().get(JcrConstants.JCR_PRIMARYTYPE, String.class); if (ArrayUtils.contains(contentTypes, primaryType)) { runnable.run(resource); } } catch (Exception e) { log.error("An error occurred while visiting resource [ {} ]", resource.getPath(), e); } } }
public String getMetadataValue(final String name) { Resource meta = frozenResource.getChild(METADATA_PATH); if (meta == null) { return null; } return meta.getValueMap().get(name, String.class); }
private Calendar getLastModified(ResourceResolver resourceResolver, String pageContentPath) { Resource pageContent = resourceResolver.getResource(pageContentPath); Calendar lastModified = null; if (resource != null) { lastModified = pageContent.getValueMap().get(NameConstants.PN_PAGE_LAST_MOD, Calendar.class); } return lastModified; }
private boolean isTransient(ResourceResolver resourceResolver, String workflowModelId) { Resource resource = resourceResolver.getResource(workflowModelId).getParent(); return resource.getValueMap().get("transient", false); } }
@Override public Object getValue(Object adaptable, String name, Type declaredType, AnnotatedElement element, DisposalCallbackRegistry callbackRegistry) { if (element.isAnnotationPresent(JsonValueMapValue.class)) { Resource resource = getResource(adaptable); JsonValueMapValue annotation = element.getAnnotation(JsonValueMapValue.class); String key = defaultIfEmpty(annotation.name(), name); String[] jsonStringArray = resource.getValueMap().get(key, String[].class); return parseValue(declaredType, jsonStringArray, key, resource); } return null; }
public SubStatus getSubStatus() { // Refresh state before getting the status. // Note, this gets the value from the session state, and not the cached Sling Model value as this value can change over the life of the SlingModel. resourceResolver.refresh(); subStatus = resource.getValueMap().get(PN_SUB_STATUS, String.class); if (subStatus != null) { return EnumUtils.getEnum(SubStatus.class, subStatus); } else { return null; } }
public Status getStatus() { // Refresh state before getting the status. // Note, this gets the value from the session state, and not the cached Sling Model value as this value can change over the life of the SlingModel. resourceResolver.refresh(); status = resource.getValueMap().get(PN_STATUS, Status.NOT_STARTED.toString()); return EnumUtils.getEnum(Status.class, status); }