diff --git a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/DotClassPathParser.java b/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/DotClassPathParser.java --- a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/DotClassPathParser.java +++ b/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/DotClassPathParser.java @@ -77,7 +77,7 @@ if (!"classpath".equals(classpathEl.getLocalName())) { // NOI18N return empty(); } - List classpathEntryEls = Util.findSubElements(classpathEl); + List classpathEntryEls = XMLUtil.findSubElements(classpathEl); if (classpathEntryEls == null) { return empty(); } @@ -113,7 +113,7 @@ } props.put(key, value); } - Element entryAttrs = Util.findElement(classpathEntry, "attributes", null); //NOI18N + Element entryAttrs = XMLUtil.findElement(classpathEntry, "attributes", null); //NOI18N if (entryAttrs != null) { /* @@ -122,7 +122,7 @@ */ - List attrsList = Util.findSubElements(entryAttrs); + List attrsList = XMLUtil.findSubElements(entryAttrs); if (attrsList != null) { for (Element e : attrsList) { props.put(e.getAttribute("name"), e.getAttribute("value")); //NOI18N diff --git a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/ProjectParser.java b/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/ProjectParser.java --- a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/ProjectParser.java +++ b/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/ProjectParser.java @@ -75,9 +75,9 @@ throw new IllegalStateException("given file is not eclipse .project file"); // NOI18N } - Element naturesEl = Util.findElement(projectDescriptionEl, "natures", null); // NOI18N + Element naturesEl = XMLUtil.findElement(projectDescriptionEl, "natures", null); // NOI18N if (naturesEl != null) { - List natureEls = Util.findSubElements(naturesEl); + List natureEls = XMLUtil.findSubElements(naturesEl); if (natureEls != null) { for (Element nature : natureEls) { natures.add(nature.getTextContent()); @@ -85,30 +85,30 @@ } } - Element linksEl = Util.findElement(projectDescriptionEl, "linkedResources", null); // NOI18N + Element linksEl = XMLUtil.findElement(projectDescriptionEl, "linkedResources", null); // NOI18N if (linksEl != null) { - List linkEls = Util.findSubElements(linksEl); + List linkEls = XMLUtil.findSubElements(linksEl); if (linkEls != null) { for (Element link : linkEls) { - Element locationElement = Util.findElement(link, "location", null); // NOI18N + Element locationElement = XMLUtil.findElement(link, "location", null); // NOI18N String loc; if (locationElement == null) { - assert Util.findElement(link, "locationURI", null) != null : Util.findSubElements(link); // NOI18N + assert XMLUtil.findElement(link, "locationURI", null) != null : XMLUtil.findSubElements(link); // NOI18N // XXX external source root can be defined using IDE variable. For some reason (in Eclipse) // these variables are stored/managed separately from variables which can be used // in classpath. For now these variables are not transfer to NetBeans and normalized // path will be returned instead. - loc = resolveLink(Util.findElement(link, "locationURI", null).getTextContent(), variables); // NOI18N + loc = resolveLink(XMLUtil.findElement(link, "locationURI", null).getTextContent(), variables); // NOI18N } else { loc = locationElement.getTextContent(); } - links.add(new Link(Util.findElement(link, "name", null).getTextContent(), // NOI18N - "1".equals(Util.findElement(link, "type", null).getTextContent()), // NOI18N + links.add(new Link(XMLUtil.findElement(link, "name", null).getTextContent(), // NOI18N + "1".equals(XMLUtil.findElement(link, "type", null).getTextContent()), // NOI18N loc)); } } } - return Util.findElement(projectDescriptionEl, "name", null).getTextContent(); //NOI18N + return XMLUtil.findElement(projectDescriptionEl, "name", null).getTextContent(); //NOI18N } public static Facets readProjectFacets(File projectDir, Set natures) throws IOException { @@ -132,7 +132,7 @@ } List facets = new ArrayList(); - List elements = Util.findSubElements(root); + List elements = XMLUtil.findSubElements(root); for (Element element : elements) { if (!"installed".equals(element.getNodeName())) { // NOI18N continue; diff --git a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/UserLibraryParser.java b/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/UserLibraryParser.java --- a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/UserLibraryParser.java +++ b/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/UserLibraryParser.java @@ -73,7 +73,7 @@ if (!"userlibrary".equals(root.getLocalName())) { //NOI18N return false; } - for (Element el : Util.findSubElements(root)) { + for (Element el : XMLUtil.findSubElements(root)) { if (!el.getNodeName().equals("archive")) { //NOI18N continue; } @@ -82,11 +82,11 @@ if (src.length() > 0) { sources.add(src); } - Element el2 = Util.findElement(el, "attributes", null); //NOI18N + Element el2 = XMLUtil.findElement(el, "attributes", null); //NOI18N if (el2 == null) { continue; } - for (Element el3 : Util.findSubElements(el2)) { + for (Element el3 : XMLUtil.findSubElements(el2)) { if (el3.getNodeName().equals("attribute") && "javadoc_location".equals(el3.getAttribute("name"))) { //NOI18N String javadoc = el3.getAttribute("value"); //NOI18N if (javadoc != null) { diff --git a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/Util.java b/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/Util.java --- a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/Util.java +++ b/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/Util.java @@ -68,84 +68,6 @@ private Util() {} /** - * Search for an XML element in the direct children of a parent. - * DOM provides a similar method but it does a recursive search - * which we do not want. It also gives a node list and we want - * only one result. - * @param parent a parent element - * @param name the intended local name - * @param namespace the intended namespace - * @return the one child element with that name, or null if none or more than one - */ - public static Element findElement(Element parent, String name, String namespace) { - Element result = null; - NodeList l = parent.getChildNodes(); - int len = l.getLength(); - for (int i = 0; i < len; i++) { - if (l.item(i).getNodeType() == Node.ELEMENT_NODE) { - Element el = (Element)l.item(i); - if (name.equals(el.getLocalName()) && - ((namespace != null && namespace.equals(el.getNamespaceURI())) || namespace == null)) { - if (result == null) { - result = el; - } else { - return null; - } - } - } - } - return result; - } - - /** - * Extract 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 - */ - public 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; - } - - /** - * Find all direct child elements of an element. - * More useful than {@link Element#getElementsByTagNameNS} because it does - * not recurse into recursive child elements. - * Children which are all-whitespace text nodes are ignored; others cause - * an exception to be thrown. - * @param parent a parent element in a DOM tree - * @return a list of direct child elements (may be empty) - * @throws IllegalArgumentException if there are non-element children besides whitespace - */ - public static List findSubElements(Element parent) throws IllegalArgumentException { - NodeList l = parent.getChildNodes(); - List elements = new ArrayList(l.getLength()); - for (int i = 0; i < l.getLength(); i++) { - Node n = l.item(i); - if (n.getNodeType() == Node.ELEMENT_NODE) { - elements.add((Element)n); - } else if (n.getNodeType() == Node.TEXT_NODE) { - String text = ((Text)n).getNodeValue(); - if (text.trim().length() > 0) { - throw new IllegalArgumentException("non-ws text encountered in " + parent + ": " + text); // NOI18N - } - } else if (n.getNodeType() == Node.COMMENT_NODE) { - // skip - } else { - throw new IllegalArgumentException("unexpected non-element child of " + parent + ": " + n); // NOI18N - } - } - return elements; - } - - /** * Create an XML error handler that rethrows errors and fatal errors and logs warnings. * @return a standard error handler */ diff --git a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/WorkspaceParser.java b/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/WorkspaceParser.java --- a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/WorkspaceParser.java +++ b/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/WorkspaceParser.java @@ -156,10 +156,10 @@ !JSF_LIB_NS.equals(root.getNamespaceURI())) { return; } - for (Element el : Util.findSubElements(root)) { + for (Element el : XMLUtil.findSubElements(root)) { String libraryName = el.getAttribute("Name"); // NOI18N List jars = new ArrayList(); - for (Element file : Util.findSubElements(el)) { + for (Element file : XMLUtil.findSubElements(el)) { String path = file.getAttribute("SourceLocation"); // NOI18N if (!"false".equals(file.getAttribute("RelativeToWorkspace"))) { // NOI18N path = new File(workspace.getDirectory(), path).getPath();