Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2008-09-25 16:32:57 -0400
committerpelder2008-09-25 16:32:57 -0400
commit73db5eda884c2a254e59056635aa8333925a1cb3 (patch)
tree4869633ebcb5d5fb46b85fb73a140a42102d51dc
parentb1c3cc26bf87606220a2076183c4cbd0bb37e82e (diff)
downloadorg.eclipse.jet-73db5eda884c2a254e59056635aa8333925a1cb3.tar.gz
org.eclipse.jet-73db5eda884c2a254e59056635aa8333925a1cb3.tar.xz
org.eclipse.jet-73db5eda884c2a254e59056635aa8333925a1cb3.zip
[248652] c:copyElement to cannot rename copied XML DOM elements
[248653] c:copyElement incorrectly copies entire XML documents
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/DOMInspector.java44
1 files changed, 38 insertions, 6 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/DOMInspector.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/DOMInspector.java
index 8c305d1..9608f32 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/DOMInspector.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/DOMInspector.java
@@ -273,7 +273,11 @@ public class DOMInspector implements INodeInspector, IElementInspector
String nsURI = nameTestExpandedName.getNamespaceURI();
if (nsURI == null)
{
- return node.getAttributes().getNamedItem(nameTestExpandedName.getLocalPart());
+ Node namedItem = node.getAttributes().getNamedItem(nameTestExpandedName.getLocalPart());
+ if(namedItem == null) {
+ namedItem = node.getAttributes().getNamedItem(nameTestExpandedName.getLocalPart());
+ }
+ return namedItem;
}
else
{
@@ -336,18 +340,39 @@ public class DOMInspector implements INodeInspector, IElementInspector
Element parentElement = (Element)tgtParent;
Element newElement = null;
+ final Document ownerDocument = parentElement.getOwnerDocument();
if (srcElement instanceof Element)
{
Element source = (Element)srcElement;
- if (!name.equals(source.getNodeName()))
+ if (!name.equals(source.getLocalName()))
{
- throw new CopyElementException(JET2Messages.DOMInspector_InconsistentElementName);
+ newElement = ownerDocument.createElement(name);
+ NodeList childNodes = source.getChildNodes();
+ for(int i = 0; i < childNodes.getLength(); i++) {
+ newElement.appendChild(ownerDocument.importNode(childNodes.item(i), true));
+ }
+ NamedNodeMap attributes = source.getAttributes();
+ for(int i = 0; i < attributes.getLength(); i++) {
+ newElement.setAttributeNodeNS((Attr)ownerDocument.importNode(attributes.item(i), false));
+ }
+ parentElement.appendChild(newElement);
+
+// throw new CopyElementException(JET2Messages.DOMInspector_InconsistentElementName);
+ } else {
+ newElement = (Element)ownerDocument.importNode(source, recursive);
+ parentElement.appendChild(newElement);
}
- newElement = (Element)parentElement.getOwnerDocument().importNode(source, recursive);
- parentElement.appendChild(newElement);
}
+ else if(srcElement instanceof Document) {
+ newElement = ownerDocument.createElement(name);
+ final NodeList childNodes = ((Document)srcElement).getChildNodes();
+ for(int i = 0; i < childNodes.getLength(); i++) {
+ newElement.appendChild(ownerDocument.importNode(childNodes.item(i), true));
+ }
+ parentElement.appendChild(newElement);
+ }
else
{
throw new CopyElementException(JET2Messages.DOMInspector_NotDOMObject);
@@ -381,7 +406,14 @@ public class DOMInspector implements INodeInspector, IElementInspector
public boolean testExpandedName(Object node, ExpandedName testName)
{
- return testName.equals(expandedNameOf(node));
+ boolean match = testName.equals(expandedNameOf(node));
+ if(!match) {
+ String localName = ((Node)node).getLocalName();
+ if(localName != null) {
+ match = testName.equals(new ExpandedName(localName));
+ }
+ }
+ return match;
}
}

Back to the top