/** * Converts a CMIS extension element to a DOM node. */ private static Node convertCmisExtensionElementToNode(CmisExtensionElement source, Element parent, Document doc) { if (source == null) { return null; } Element element = doc.createElementNS( (source.getNamespace() == null ? DEFAULT_EXTENSION_NS : source.getNamespace()), source.getName()); if (source.getValue() != null) { element.appendChild(doc.createTextNode(source.getValue())); } else { for (CmisExtensionElement child : source.getChildren()) { element.appendChild(convertCmisExtensionElementToNode(child, element, doc)); } } // set attributes if (source.getAttributes() != null) { for (Map.Entry<String, String> e : source.getAttributes().entrySet()) { element.setAttributeNS((source.getNamespace() == null ? DEFAULT_EXTENSION_NS : source.getNamespace()), e.getKey(), e.getValue()); } } return element; }
/** * Copy constructor. */ public CmisExtensionElementImpl(CmisExtensionElement element) { if (element == null) { throw new IllegalArgumentException("Element must set!"); } if (element.getName() == null) { throw new IllegalArgumentException("Name must set!"); } this.name = element.getName(); this.namespace = element.getNamespace(); this.value = element.getValue(); this.children = element.getChildren(); }
/** * Finds the Alfresco extensions within the given extensions. */ public static List<CmisExtensionElement> findAlfrescoExtensions(List<CmisExtensionElement> extensions) { if (extensions == null || extensions.isEmpty()) { return null; } for (CmisExtensionElement ext : extensions) { if (ALFRESCO_NAMESPACE.equals(ext.getNamespace())) { return ext.getChildren(); } } return null; }
/** * Returns the aspect types from the Alfresco extensions. */ public static Collection<ObjectType> getAspectTypes(Session session, List<CmisExtensionElement> alfrescoExtensions) { Collection<ObjectType> aspectTypes = new ArrayList<ObjectType>(); for (CmisExtensionElement extension : alfrescoExtensions) { if (extension.getName().equals(APPLIED_ASPECTS)) { ObjectType aspectType = session.getTypeDefinition(extension.getValue()); aspectTypes.add(aspectType); } } return aspectTypes; }
private static void addExtensionToTarget(final CmisExtensionElement ext, final JSONObject target) { if (ext == null) { return; } Object value = null; if (isNotEmpty(ext.getChildren())) { value = convertExtensionList(ext.getChildren()); } else { value = ext.getValue(); } if (!target.containsKey(ext.getName())) { target.put(ext.getName(), value); } else { Object extValue = target.get(ext.getName()); JSONArray array; if (extValue instanceof JSONArray) { array = (JSONArray) extValue; } else { array = new JSONArray(); array.add(extValue); } array.add(value); target.put(ext.getName(), array); } }
List<CmisExtensionElement> extensions = propertyExtensionList.iterator().next().getChildren(); for (CmisExtensionElement extension : extensions) if ("properties".equals(extension.getName())) List<CmisExtensionElement> propExtensions = extension.getChildren(); assertTrue("cmisObject should contain aspect properties", propExtensions.size() > 0); for (CmisExtensionElement prop : propExtensions) Map<String, String> cmisAspectProperty = prop.getAttributes(); Set<String> cmisAspectPropertyNames = cmisAspectProperty.keySet(); assertTrue("propertyDefinitionId attribute should be present", cmisAspectPropertyNames.contains("propertyDefinitionId"));
if (ALFRESCO_EXTENSION_NAMESPACE.equals(extension.getNamespace()) && SET_ASPECTS.equals(extension.getName()))
for (CmisExtensionElement cmisEE : object.getProperties().getExtensions().get(0).getChildren()) documentAspects.add(cmisEE.getValue()); for (CmisExtensionElement cmisEE : latestVersion.getProperties().getExtensions().get(0).getChildren()) latestVersionAspects.add(cmisEE.getValue());
private static void addExtensionToTarget(final CmisExtensionElement ext, final JSONObject target) { if (ext == null) { return; } Object value = null; if (isNotEmpty(ext.getChildren())) { value = convertExtensionList(ext.getChildren()); } else { value = ext.getValue(); } if (!target.containsKey(ext.getName())) { target.put(ext.getName(), value); } else { Object extValue = target.get(ext.getName()); JSONArray array; if (extValue instanceof JSONArray) { array = (JSONArray) extValue; } else { array = new JSONArray(); array.add(extValue); } array.add(value); target.put(ext.getName(), array); } }
if (ALFRESCO_EXTENSION_NAMESPACE.equals(extension.getNamespace()) && SET_ASPECTS.equals(extension.getName()))
/** * Copy constructor. */ public CmisExtensionElementImpl(CmisExtensionElement element) { if (element == null) { throw new IllegalArgumentException("Element must set!"); } if (element.getName() == null) { throw new IllegalArgumentException("Name must set!"); } this.name = element.getName(); this.namespace = element.getNamespace(); this.value = element.getValue(); this.children = element.getChildren(); }
/** * Makes a deep copy of an extension element. */ private CmisExtensionElement copy(CmisExtensionElement element) { if (element == null) { return null; } Map<String, String> attrs = (element.getAttributes() != null ? new HashMap<String, String>( element.getAttributes()) : null); List<CmisExtensionElement> children = element.getChildren(); if (isNotEmpty(children)) { List<CmisExtensionElement> copyChildren = new ArrayList<CmisExtensionElement>(children.size()); for (CmisExtensionElement child : children) { copyChildren.add(copy(child)); } return new CmisExtensionElementImpl(element.getNamespace(), element.getName(), attrs, copyChildren); } else { return new CmisExtensionElementImpl(element.getNamespace(), element.getName(), attrs, element.getValue()); } }
(source.getNamespace() == null ? DEFAULT_EXTENSION_NS : source.getNamespace()), source.getName()); doc.appendChild(root); if (source.getValue() != null) { root.appendChild(doc.createTextNode(source.getValue())); } else { for (CmisExtensionElement child : source.getChildren()) { root.appendChild(convertCmisExtensionElementToNode(child, root, doc)); if (source.getAttributes() != null) { for (Map.Entry<String, String> e : source.getAttributes().entrySet()) { root.setAttributeNS((source.getNamespace() == null ? DEFAULT_EXTENSION_NS : source.getNamespace()), e.getKey(), e.getValue());
private static void writeExtensionElement(XMLStreamWriter writer, CmisExtensionElement source, List<String> ns) throws XMLStreamException { if (source == null || source.getName() == null) { return; if (source.getNamespace() != null) { String prefix = writer.getPrefix(source.getNamespace()); if (prefix == null) { int p = ns.indexOf(source.getNamespace()); ns.add(source.getNamespace()); addedNamespace = true; } else { writer.writeStartElement(prefix, source.getName(), source.getNamespace()); writer.writeNamespace(prefix, source.getNamespace()); writer.writeStartElement(source.getName()); if (source.getAttributes() != null) { for (Map.Entry<String, String> attr : source.getAttributes().entrySet()) { writer.writeAttribute(attr.getKey(), attr.getValue()); if (source.getValue() != null) { writer.writeCharacters(source.getValue()); } else { if (source.getChildren() != null) { for (CmisExtensionElement child : source.getChildren()) { writeExtensionElement(writer, child, ns);
private static void writeExtensionElement(XmlSerializer writer, CmisExtensionElement source, LinkedList<String> ns) throws IOException { if (source == null || source.getName() == null) { return; if (source.getNamespace() != null) { namespace = source.getNamespace(); writer.startTag(source.getNamespace(), source.getName()); writer.startTag(null, source.getName()); if (source.getAttributes() != null) { for (Map.Entry<String, String> attr : source.getAttributes().entrySet()) { writer.attribute(null, attr.getKey(), attr.getValue()); if (source.getValue() != null) { writer.text(source.getValue()); } else { if (source.getChildren() != null) { for (CmisExtensionElement child : source.getChildren()) { writeExtensionElement(writer, child, ns); writer.endTag(namespace, source.getName());
if (!extension.getName().equals("properties")) for (CmisExtensionElement property : extension.getChildren()) String id = property.getAttributes().get("propertyDefinitionId"); try for (CmisExtensionElement propertyValues : property.getChildren()) values.add(Boolean.parseBoolean(propertyValues.getValue())); break; case DATETIME: values.add(df.newXMLGregorianCalendar(propertyValues.getValue()).toGregorianCalendar()); break; case DECIMAL: values.add(new BigDecimal(propertyValues.getValue())); break; case INTEGER: values.add(new BigInteger(propertyValues.getValue())); break; default: values.add(propertyValues.getValue());
if (aspectExtension.getChildren() == null) for (CmisExtensionElement extension : aspectExtension.getChildren()) if (!ALFRESCO_EXTENSION_NAMESPACE.equals(extension.getNamespace())) if (ASPECTS_TO_ADD.equals(extension.getName()) && (extension.getValue() != null)) aspectsToAdd.add(extension.getValue()); else if (ASPECTS_TO_REMOVE.equals(extension.getName()) && (extension.getValue() != null)) aspectsToRemove.add(extension.getValue()); else if (PROPERTIES.equals(extension.getName()) && (extension.getChildren() != null)) for (CmisExtensionElement property : extension.getChildren()) if (!property.getName().startsWith("property")) String propertyId = (property.getAttributes() == null ? null : property.getAttributes().get( "propertyDefinitionId")); if ((propertyId == null) || (property.getChildren() == null)) if (property.getName().equals("propertyBoolean")) else if (property.getName().equals("propertyInteger")) else if (property.getName().equals("propertyDateTime"))
if (aspectExtension.getChildren() == null) for (CmisExtensionElement extension : aspectExtension.getChildren()) if (!ALFRESCO_EXTENSION_NAMESPACE.equals(extension.getNamespace())) if (ASPECTS_TO_ADD.equals(extension.getName()) && (extension.getValue() != null)) aspectsToAdd.add(extension.getValue()); else if (ASPECTS_TO_REMOVE.equals(extension.getName()) && (extension.getValue() != null)) aspectsToRemove.add(extension.getValue()); else if (PROPERTIES.equals(extension.getName()) && (extension.getChildren() != null)) for (CmisExtensionElement property : extension.getChildren()) if (!property.getName().startsWith("property")) String propertyId = (property.getAttributes() == null ? null : property.getAttributes().get( "propertyDefinitionId")); if ((propertyId == null) || (property.getChildren() == null)) if (property.getName().equals("propertyBoolean")) else if (property.getName().equals("propertyInteger")) else if (property.getName().equals("propertyDateTime"))
List<CmisExtensionElement> extensions = objectData.getProperties().getExtensions().iterator().next().getChildren(); if (CMISConnector.PROPERTIES.equals(extension.getName())) List<CmisExtensionElement> propExtensions = extension.getChildren(); assertTrue("cmisObject should contain aspect properties", propExtensions.size() > 0); for (CmisExtensionElement prop : propExtensions) Map<String, String> cmisAspectProperty = prop.getAttributes(); Set<String> cmisAspectPropertyNames = cmisAspectProperty.keySet(); assertTrue("propertyDefinitionId attribute should be present", cmisAspectPropertyNames.contains("propertyDefinitionId")); else if (CMISConnector.APPLIED_ASPECTS.equals(extension.getName())) appliedAspects.add(extension.getValue());