@SuppressWarnings("unchecked")
Map<String, String> attributes = (Map<String, String>)contentVersion.get("contentVersionAttributes");
if(attributes != null && attributes.size() > 0)
{
DOMBuilder domBuilder = new DOMBuilder();
Element attributesRoot = null;
Document document = null;
if (keepExistingAttributes && !isNewlyCreatedVersion)
{
String existingXML = contentVersionVO.getVersionValue();
document = domBuilder.getDocument(existingXML);
attributesRoot = (Element)document.getRootElement().element("attributes");
}
else
{
document = domBuilder.createDocument();
Element rootElement = domBuilder.addElement(document, "root");
domBuilder.addAttribute(rootElement, "xmlns", "x-schema:Schema.xml");
attributesRoot = domBuilder.addElement(rootElement, "attributes");
}
if(logger.isDebugEnabled())
logger.info("attributesRoot:" + attributesRoot);
Iterator<String> attributesIterator = attributes.keySet().iterator();
while(attributesIterator.hasNext())
{
String attributeName = attributesIterator.next();
String attributeValue = attributes.get(attributeName);
attributeValue = cleanAttributeValue(attributeValue, allowHTMLContent, allowExternalLinks, allowDollarSigns, allowAnchorSigns);
if(keepExistingAttributes)
{
Element attribute = attributesRoot.element(attributeName);
if (attribute == null)
{
attribute = domBuilder.addElement(attributesRoot, attributeName);
}
attribute.clearContent();
domBuilder.addCDATAElement(attribute, attributeValue);
}
else
{
Element attribute = domBuilder.addElement(attributesRoot, attributeName);
domBuilder.addCDATAElement(attribute, attributeValue);
}
}
contentVersionVO.setVersionValue(document.asXML());
}