1 package org.xmldb.xupdate.lexus.commands; 2 3 55 56 import org.w3c.dom.Attr ; 57 import org.w3c.dom.NamedNodeMap ; 58 import org.w3c.dom.Node ; 59 import org.w3c.dom.NodeList ; 60 61 67 public class InsertAfterCommand extends InsertCommand { 68 69 72 public InsertAfterCommand(Node contextNode) throws Exception { 73 super(contextNode); 74 } 75 76 77 80 public Node execute() throws Exception { 81 if (result == null) { 82 return contextNode; 83 } 84 85 String query = (String ) attributes.get("select"); 86 selectNodes(query); 87 88 NamedNodeMap attributes = result.getAttributes(); 89 NodeList children = result.getChildNodes(); 90 91 int selectionLength = selectionNodeList.getLength(); 92 for (int i = 0; i < selectionLength; i++) { 93 Node current = selectionNodeList.item(i); 94 Node parent; 95 switch (current.getNodeType()) { 96 case Node.ATTRIBUTE_NODE: 97 parent = ((Attr ) current).getOwnerElement(); 98 break; 99 default: 100 parent = current.getParentNode(); 101 } 102 103 insertAttributes(attributes, parent); 104 105 current = current.getNextSibling(); 106 int childrenLength = children.getLength(); 107 for (int j = 0; j < childrenLength; j++) { 108 if (current != null) { 109 parent.insertBefore(children.item(j).cloneNode(true), current); 110 } else { 111 parent.appendChild(children.item(j).cloneNode(true)); 112 } 113 } 114 115 } 116 document.getDocumentElement().removeChild(result); 117 118 return contextNode; 119 } 120 } 121 122 | Popular Tags |