diff --git a/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/UpdateProjectImpl.java b/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/UpdateProjectImpl.java --- a/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/UpdateProjectImpl.java +++ b/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/UpdateProjectImpl.java @@ -60,6 +60,7 @@ import org.netbeans.spi.project.support.ant.EditableProperties; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.xml.XMLUtil; import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; @@ -159,7 +160,7 @@ if(oldRoot != null) { Document doc = oldRoot.getOwnerDocument(); Element newRoot = doc.createElementNS(EarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N - copyDocument(doc, oldRoot, newRoot); + XMLUtil.copyDocument(doc, oldRoot, newRoot, EarProjectType.PROJECT_CONFIGURATION_NAMESPACE); //update to // NodeList contList = newRoot.getElementsByTagNameNS(ns, "web-module-libraries"); @@ -173,7 +174,7 @@ Element library = (Element) libList.item(i); Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0); //remove ${ and } from the beginning and end - String webFileText = findText(webFile); + String webFileText = XMLUtil.findText(webFile); webFileText = webFileText.substring(2, webFileText.length() - 1); if (webFileText.startsWith("libs.")) { String libName = webFileText.substring(5, webFileText.indexOf(".classpath")); //NOI18N @@ -209,57 +210,6 @@ return cachedElement; } - private static void copyDocument (Document doc, Element from, Element to) { - NodeList nl = from.getChildNodes(); - int length = nl.getLength(); - for (int i=0; i< length; i++) { - Node node = nl.item (i); - Node newNode = null; - switch (node.getNodeType()) { - case Node.ELEMENT_NODE: - Element oldElement = (Element) node; - newNode = doc.createElementNS(EarProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName()); - NamedNodeMap m = oldElement.getAttributes(); - Element newElement = (Element) newNode; - for (int index = 0; index < m.getLength(); index++) { - Node attr = m.item(index); - newElement.setAttribute(attr.getNodeName(), attr.getNodeValue()); - } - copyDocument(doc,oldElement,(Element)newNode); - break; - case Node.TEXT_NODE: - Text oldText = (Text) node; - newNode = doc.createTextNode(oldText.getData()); - break; - case Node.COMMENT_NODE: - Comment oldComment = (Comment) node; - newNode = doc.createComment(oldComment.getData()); - break; - } - if (newNode != null) { - to.appendChild (newNode); - } - } - } - - /** - * Extract nested text from a node. - * Currently does not handle coalescing text nodes, CDATA sections, etc. - * @param parent a parent node - * @return the nested text, or null if none was found - */ - private static String findText(Node parent) { - NodeList l = parent.getChildNodes(); - for (int i = 0; i < l.getLength(); i++) { - if (l.item(i).getNodeType() == Node.TEXT_NODE) { - Text text = (Text)l.item(i); - return text.getNodeValue(); - } - } - return null; - } - - public EditableProperties getUpdatedProjectProperties() { return helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); } diff --git a/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/classpath/ClassPathSupportCallbackImpl.java b/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/classpath/ClassPathSupportCallbackImpl.java --- a/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/classpath/ClassPathSupportCallbackImpl.java +++ b/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/classpath/ClassPathSupportCallbackImpl.java @@ -41,20 +41,18 @@ package org.netbeans.modules.j2ee.earproject.classpath; -import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.netbeans.modules.java.api.common.classpath.ClassPathSupport.Item; -import org.netbeans.modules.j2ee.common.project.ui.J2EEProjectProperties; import org.netbeans.modules.j2ee.earproject.EarProjectType; import org.netbeans.modules.java.api.common.util.CommonProjectUtils; import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.openide.xml.XMLUtil; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import org.w3c.dom.Text; /** * Defines the various class paths for a web project. @@ -135,8 +133,8 @@ Element library = (Element) ch.item(i); Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0); NodeList pathInEarElements = library.getElementsByTagNameNS(ns, TAG_PATH_IN_EAR); - earIncludesMap.put(findText(webFile), pathInEarElements.getLength() > 0 ? - findText(pathInEarElements.item(0)) : null); + earIncludesMap.put(XMLUtil.findText(webFile), pathInEarElements.getLength() > 0 ? + XMLUtil.findText(pathInEarElements.item(0)) : null); } } } @@ -144,15 +142,5 @@ return earIncludesMap; } - private static String findText(Node parent) { - NodeList l = parent.getChildNodes(); - for (int i = 0; i < l.getLength(); i++) { - if (l.item(i).getNodeType() == Node.TEXT_NODE) { - Text text = (Text)l.item(i); - return text.getNodeValue(); - } - } - return null; - } }