}
}
private void copyNode(ExtendedXMLStreamReader reader, Receiver receiver, int status,
boolean onFirstNode, String changeMessage) throws SAXException, XMLStreamException, IOException {
AttrList attrs;
switch (status) {
case XMLStreamReader.START_ELEMENT:
attrs = new AttrList();
if (annotate) {
if (onFirstNode)
attrs.addAttribute(ATTR_CHANGE, changeMessage);
else {
NodeId nodeId = (NodeId) reader.getProperty(EmbeddedXMLStreamReader.PROPERTY_NODE_ID);
NodeSet children = changeSet.selectParentChild(new NodeProxy(diffDoc, nodeId), NodeSet.ANCESTOR);
if (children != null && !children.isEmpty())
attrs.addAttribute(ATTR_CHANGE, "changed");
}
if (elementStack.size() == 0)
receiver.startPrefixMapping(StandardDiff.PREFIX, StandardDiff.NAMESPACE);
}
for (int i = 0; i < reader.getAttributeCount(); i++) {
// check if an attribute has to be inserted before the current attribute
NodeId nodeId = reader.getAttributeId(i);
// check if an attribute has to be inserted before the current attribute
ElementImpl insertedNode = insertedNodes.get(nodeId);
if (insertedNode != null) {
StoredNode child = (StoredNode) insertedNode.getFirstChild();
while (child != null) {
if (StandardDiff.NAMESPACE.equals(child.getNamespaceURI()) && "attribute".equals(child.getLocalName())) {
NamedNodeMap map = child.getAttributes();
for (int j = 0; j < map.getLength(); j++) {
AttrImpl attr = (AttrImpl) map.item(j);
if (!attr.getName().startsWith("xmlns"))
attrs.addAttribute(attr.getQName(), attr.getValue(),
attr.getType(), attr.getNodeId());
}
}
child = (StoredNode) child.getNextSibling();
}
}
if (deletedNodes.get(nodeId) == null) {
QName attrQn = new QName(reader.getAttributeLocalName(i), reader.getAttributeNamespace(i),
reader.getAttributePrefix(i));
attrs.addAttribute(
attrQn,
reader.getAttributeValue(i),
getAttributeType(reader.getAttributeType(i))
);
}
}
QName qn = new QName(reader.getLocalName(), reader.getNamespaceURI(), reader.getPrefix());
receiver.startElement(qn, attrs);
if (elementStack != null)
elementStack.push(qn);
break;
case XMLStreamReader.END_ELEMENT:
receiver.endElement(new QName(reader.getLocalName(), reader.getNamespaceURI(), reader.getPrefix()));
if (elementStack != null) {
if (elementStack.isEmpty())
receiver.endPrefixMapping(StandardDiff.PREFIX);
elementStack.pop();
}
break;
case XMLStreamReader.CHARACTERS:
if (onFirstNode && annotate) {
attrs = new AttrList();
attrs.addAttribute(ATTR_CHANGE, changeMessage);
receiver.startElement(ELEMENT_WRAPPER, attrs);
}
receiver.characters(reader.getText());
if (onFirstNode && annotate)
receiver.endElement(ELEMENT_WRAPPER);