in server/core/src/main/java/org/apache/vysper/xmpp/stanza/StanzaBuilder.java [146:186]
public static StanzaBuilder createClone(XMLElement original, boolean deep, List<Attribute> replacingAttributes) {
StanzaBuilder stanzaBuilder = new StanzaBuilder(original.getName(), original.getNamespaceURI(), original
.getNamespacePrefix());
List<Attribute> replacingAttributesCopy = new ArrayList<Attribute>();
if (replacingAttributes != null)
replacingAttributesCopy.addAll(replacingAttributes);
List<Attribute> originalAttributes = original.getAttributes();
for (Attribute originalAttribute : originalAttributes) {
boolean wasReplaced = false;
for (Iterator<Attribute> it = replacingAttributesCopy.iterator(); it.hasNext();) {
Attribute replacingAttribute = it.next();
if (replacingAttribute == null)
continue;
if (replacingAttribute.getName().equals(originalAttribute.getName())) {
stanzaBuilder.addAttribute(replacingAttribute);
it.remove(); // this has been processed
wasReplaced = true;
break;
}
}
if (!wasReplaced)
stanzaBuilder.addAttribute(originalAttribute);
}
// add remaining replacements, which are actually additions
for (Attribute additionalAttribute : replacingAttributesCopy) {
stanzaBuilder.addAttribute(additionalAttribute);
}
// copy over immutable inner elements
if (deep && original.getInnerElements() != null) {
List<XMLElement> innerElements = original.getInnerElements();
for (XMLElement innerElement : innerElements) {
stanzaBuilder.addPreparedElement(innerElement);
}
}
return stanzaBuilder;
}