diff --git a/web.project/src/org/netbeans/modules/web/project/UpdateProjectImpl.java b/web.project/src/org/netbeans/modules/web/project/UpdateProjectImpl.java --- a/web.project/src/org/netbeans/modules/web/project/UpdateProjectImpl.java +++ b/web.project/src/org/netbeans/modules/web/project/UpdateProjectImpl.java @@ -69,13 +69,11 @@ import org.openide.filesystems.URLMapper; import org.openide.util.Mutex; import org.openide.util.NbBundle; -import org.w3c.dom.Comment; +import org.openide.xml.XMLUtil; import org.w3c.dom.Document; import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import org.w3c.dom.Text; /** * @@ -295,7 +293,7 @@ if (oldRoot != null) { Document doc = oldRoot.getOwnerDocument(); Element newRoot = doc.createElementNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N - copyDocument (doc, oldRoot, newRoot); + XMLUtil.copyDocument (doc, oldRoot, newRoot, WebProjectType.PROJECT_CONFIGURATION_NAMESPACE); if (version == 1) { //1->2 upgrade Element sourceRoots = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N @@ -317,7 +315,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); // warIncludesMap.put(webFileText, pathInWarElements.getLength() > 0 ? findText((Element) pathInWarElements.item(0)) : Item.PATH_IN_WAR_NONE); if (webFileText.startsWith ("lib.")) { @@ -375,56 +373,6 @@ } } - /** - * 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; - } - - 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(WebProjectType.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); - } - } - } - private static Element updateMinAntVersion (final Element root, final Document doc) { NodeList list = root.getElementsByTagNameNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,TAG_MINIMUM_ANT_VERSION); if (list.getLength() == 1) { diff --git a/web.project/src/org/netbeans/modules/web/project/classpath/ClassPathSupportCallbackImpl.java b/web.project/src/org/netbeans/modules/web/project/classpath/ClassPathSupportCallbackImpl.java --- a/web.project/src/org/netbeans/modules/web/project/classpath/ClassPathSupportCallbackImpl.java +++ b/web.project/src/org/netbeans/modules/web/project/classpath/ClassPathSupportCallbackImpl.java @@ -45,16 +45,15 @@ import java.util.List; import java.util.Map; import org.netbeans.modules.j2ee.common.Util; -import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; import org.netbeans.modules.java.api.common.classpath.ClassPathSupport.Item; import org.netbeans.modules.java.api.common.util.CommonProjectUtils; import org.netbeans.modules.web.project.WebProjectType; 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. @@ -120,20 +119,20 @@ Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0); NodeList pathInWarElements = library.getElementsByTagNameNS(ns, TAG_PATH_IN_WAR); //remove ${ and } from the beginning and end - String webFileText = findText(webFile); + String webFileText = XMLUtil.findText(webFile); webFileText = webFileText.substring(2, webFileText.length() - 1); //#86522 if (webModuleLibraries.equals(TAG_WEB_MODULE__ADDITIONAL_LIBRARIES)) { String pathInWar = PATH_IN_WAR_NONE; if (pathInWarElements.getLength() > 0) { - pathInWar = findText((Element) pathInWarElements.item(0)); + pathInWar = XMLUtil.findText((Element) pathInWarElements.item(0)); if (pathInWar == null) pathInWar = ""; } warIncludesMap.put(webFileText, pathInWar); } else { - warIncludesMap.put(webFileText, pathInWarElements.getLength() > 0 ? findText((Element) pathInWarElements.item(0)) : PATH_IN_WAR_NONE); + warIncludesMap.put(webFileText, pathInWarElements.getLength() > 0 ? XMLUtil.findText((Element) pathInWarElements.item(0)) : PATH_IN_WAR_NONE); } if (dirs != null) { warIncludesMap.put(webFileText+"."+Util.DESTINATION_DIRECTORY, dirs); @@ -148,40 +147,6 @@ } /** - * Extracts the first nested text from an element. - * Currently does not handle coalescing text nodes, CDATA sections, etc. - * @param parent a parent element - * @return the nested text, or null if none was found - */ - private static String findText( Element 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; - } - - /** - * 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; - } - - /** * Updates the project helper with the list of classpath items which are to be * included in deployment. */