public AbstractContentCapability(AbstractResource resource, String namespace, Map<String, Object> atts, Map<String, String> dirs) { super(resource, namespace, replaceAttributeTypes(atts), dirs); if (getAttribute(ContentNamespace.CONTENT_NAMESPACE) == null) getAttributes().put(ContentNamespace.CONTENT_NAMESPACE, ContentCapability.DEFAULT_DIGEST); if (getAttribute(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE) == null) getAttributes().put(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE, ContentCapability.DEFAULT_MIME_TYPE); if (getAttribute(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE) == null) getAttributes().put(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE, ContentCapability.DEFAULT_SIZE); }
@Override public void validate() { super.validate(); if (ContentNamespace.CONTENT_NAMESPACE.equals(getNamespace())) { digest = (String) getAttribute(ContentNamespace.CONTENT_NAMESPACE); if (digest == null) throw illegalStateCannotObtainAttribute(ContentNamespace.CONTENT_NAMESPACE); mimeType = (String) getAttribute(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE); if (mimeType == null) throw illegalStateCannotObtainAttribute(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE); contentURL = (URL) getAttribute(ContentNamespace.CAPABILITY_URL_ATTRIBUTE); contentStream = (InputStream) getAttribute(ContentNamespace.CAPABILITY_STREAM_ATTRIBUTE); if (contentURL == null && contentStream == null) throw illegalStateCannotObtainAttribute(ContentNamespace.CAPABILITY_URL_ATTRIBUTE); size = (Long) getAttribute(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE); if (size == null) throw illegalStateCannotObtainAttribute(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE); } }
private static Map<String, Object> replaceAttributeTypes(Map<String, Object> atts) { Map<String, Object> result = new HashMap<String, Object>(atts); Object val = result.get(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE); if (val instanceof String) { result.put(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE, Long.parseLong((String) val)); } val = result.get(ContentNamespace.CAPABILITY_URL_ATTRIBUTE); if (val instanceof String) { result.put(ContentNamespace.CAPABILITY_URL_ATTRIBUTE, toURL((String) val)); } return result; }