String newElementNamespacePrefix = (elementNamespacePrefix != null? elementNamespacePrefix : qName.getPrefix());
qName = new QName(newElementNamespace, newElementName, newElementNamespacePrefix);
}
SAXElement newElement = new SAXElement(qName, element.getAttributes(), element.getParent());
newElement.setWriter(element.getWriter(this), this);
if(!attributes.isEmpty()) {
Map<String, Object> beans = Filter.getCurrentExecutionContext().getBeanContext().getBeanMap();
Set<Map.Entry<QName, FreeMarkerTemplate>> attributeSet = attributes.entrySet();
for(Map.Entry<QName, FreeMarkerTemplate> attributeConfig : attributeSet) {
QName attribName = attributeConfig.getKey();
FreeMarkerTemplate valueTemplate = attributeConfig.getValue();
String namespaceURI = attribName.getNamespaceURI();
if(namespaceURI != null) {
String prefix = attribName.getPrefix();
if(prefix != null && prefix.length() > 0) {
newElement.setAttributeNS(namespaceURI, prefix + ":" + attribName.getLocalPart(), valueTemplate.apply(beans));
} else {
newElement.setAttributeNS(namespaceURI, attribName.getLocalPart(), valueTemplate.apply(beans));
}
} else {
newElement.setAttribute(attribName.getLocalPart(), valueTemplate.apply(beans));
}
}
}
return newElement;