# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: C:\nam\gavotte\xml\xam # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: src/org/netbeans/modules/xml/xam/dom/DocumentModelAccess.java *** C:\nam\gavotte\xml\xam\src\org\netbeans\modules\xml\xam\dom\DocumentModelAccess.java Base (1.1.2.9.6.1) --- C:\nam\gavotte\xml\xam\src\org\netbeans\modules\xml\xam\dom\DocumentModelAccess.java Locally Modified (Based On 1.1.2.9.6.1) *************** *** 22,27 **** --- 22,28 ---- import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.IOException; + import java.util.Collection; import java.util.List; import java.util.Map; import javax.xml.namespace.QName; *************** *** 62,67 **** --- 63,72 ---- public abstract void removeChild(Node node, Node child, NodeUpdater updater); + public void removeChildren(Node node, Collection children, NodeUpdater updater) { + throw new UnsupportedOperationException(); + } + public abstract void replaceChild(Node node, Node child, Node newChild, NodeUpdater updater); public abstract void setText(Element element, String val, NodeUpdater updater); Index: src/org/netbeans/modules/xml/xam/dom/AbstractDocumentComponent.java *** C:\nam\gavotte\xml\xam\src\org\netbeans\modules\xml\xam\dom\AbstractDocumentComponent.java Base (1.1.2.29.6.3) --- C:\nam\gavotte\xml\xam\src\org\netbeans\modules\xml\xam\dom\AbstractDocumentComponent.java Locally Modified (Based On 1.1.2.29.6.3) *************** *** 22,27 **** --- 22,28 ---- import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; *************** *** 39,44 **** --- 40,46 ---- import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.NodeList; + import org.w3c.dom.Text; /** * *************** *** 833,840 **** --- 835,961 ---- firePropertyChange(propertyName, oldVal, text); fireValueChanged(); } + + /** + * Returns leading text for the child component of the given index. + * @param child the child to get associated text from + * @return value of the leading text node, or null the indexed component peer does not have leading text nodes. + */ + protected String getLeadingText(C child) { + return getText(child, true); } + /** + * Set leading text for the child component which position is the given index. + * @param child the child to set associated text + * @param text value of the leading text node, or null to remove the leading text node. + */ + protected void setLeadingText(String propName, String text, C child) { + setText(propName, text, child, true); + } + + /** + * Returns trailing text for the child component of the given index. + * @param child the child to get associated text from + * @return value of the leading text node, or null the indexed component peer does not have trailing text nodes. + */ + protected String getTrailingText(C child) { + return getText(child, false); + } + + /** + * Set trailing text for the child component which position is the given index. + * @param child the child to get associated text from + * @param text value of the trailing text node, or null to remove the trailing text node. + */ + protected void setTrailingText(String propName, String text, C child) { + setText(propName, text, child, false); + } + + private String getText(C child, boolean leading) { + int domIndex = getNodeIndexOf(getPeer(), child.getPeer()); + StringBuilder value = new StringBuilder(); + NodeList nl = getPeer().getChildNodes(); + + for (int i = (leading ? domIndex-1 : domIndex+1); + i > -1 && domIndex < nl.getLength(); i = leading ? --i : ++i) + { + Node n = nl.item(i); + if (n instanceof Element) { + if (i == domIndex-1 || i == domIndex+1) { + value = null; + } + break; + } + + if (n instanceof Text && n.getNodeType() != Node.COMMENT_NODE) { + value.append(n.getNodeValue()); + } + } + return value.toString(); + } + + private void setText(String propName, String value, C child, final boolean leading) { + verifyWrite(); + StringBuilder oldValue = new StringBuilder(); + ArrayList toRemove = new ArrayList(); + NodeList nl = getPeer().getChildNodes(); + int domIndex = getNodeIndexOf(getPeer(), child.getPeer()); + if (domIndex < 0) { + throw new IllegalArgumentException("Child peer node is not part of children nodes"); + } + + Element ref = leading ? child.getPeer() : null; + for (int i = leading ? domIndex-1 : domIndex+1; + i > -1 && i < nl.getLength(); i = leading ? --i : ++i) + { + Node n = nl.item(i); + if (n != null && n.getNodeType() == Node.ELEMENT_NODE) { + if (leading) { + ref = child.getPeer(); + } else { + ref = (Element) n; + } + break; + } + if (n instanceof Text && n.getNodeType() != Node.COMMENT_NODE) { + toRemove.add(n); + oldValue.append(((Text)n).getNodeValue()); + } + } + + getModel().getAccess().removeChildren(getPeer(), toRemove, this); + if (value != null) { + Text newNode = getModel().getDocument().createTextNode(value); + if (ref != null) { + getModel().getAccess().insertBefore(getPeer(), newNode, ref, this); + } else { + getModel().getAccess().appendChild(getPeer(), newNode, this); + } + } + + firePropertyChange(propName, oldValue.toString(), value); + fireValueChanged(); + } + + protected int getNodeIndexOf(Node parent, Node child) { + if (child == null) { + return -1; + } + int nodeIndex = -1; + for (int i = 0; i < parent.getChildNodes().getLength(); i++) { + Node n = parent.getChildNodes().item(i); + nodeIndex++; + if (getAccess().areSameNodes(n, child)) { + return nodeIndex; + } + } + return -1; + } + + } +