diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/Evaluator.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/Evaluator.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/Evaluator.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/Evaluator.java @@ -87,6 +87,7 @@ import org.openide.util.RequestProcessor; import org.openide.util.Utilities; import org.openide.util.WeakListeners; +import org.openide.xml.XMLUtil; import org.w3c.dom.Element; /** @@ -601,18 +602,18 @@ */ private String computeModuleClasspath(ModuleList ml) { Element data = project.getPrimaryConfigurationData(); - Element moduleDependencies = Util.findElement(data, + Element moduleDependencies = XMLUtil.findElement(data, "module-dependencies", NbModuleProject.NAMESPACE_SHARED); // NOI18N assert moduleDependencies != null : "Malformed metadata in " + project; StringBuffer cp = new StringBuffer(); - for (Element dep : Util.findSubElements(moduleDependencies)) { - if (Util.findElement(dep, "compile-dependency", // NOI18N + for (Element dep : XMLUtil.findSubElements(moduleDependencies)) { + if (XMLUtil.findElement(dep, "compile-dependency", // NOI18N NbModuleProject.NAMESPACE_SHARED) == null) { continue; } - Element cnbEl = Util.findElement(dep, "code-name-base", // NOI18N + Element cnbEl = XMLUtil.findElement(dep, "code-name-base", // NOI18N NbModuleProject.NAMESPACE_SHARED); - String cnb = Util.findText(cnbEl); + String cnb = XMLUtil.findText(cnbEl); ModuleEntry module = ml.getEntry(cnb); if (module == null) { Util.err.log(ErrorManager.WARNING, "Warning - could not find dependent module " + cnb + " for " + FileUtil.getFileDisplayName(project.getProjectDirectory())); diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/NbModuleProject.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/NbModuleProject.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/NbModuleProject.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/NbModuleProject.java @@ -131,6 +131,7 @@ import org.openide.util.Exceptions; import org.openide.util.lookup.AbstractLookup; import org.openide.util.lookup.InstanceContent; +import org.openide.xml.XMLUtil; /** * A NetBeans module project. @@ -221,8 +222,8 @@ .displayName(NbBundle.getMessage(NbModuleProject.class, "LBL_javahelp_packages")).add(); } for (Map.Entry entry : getExtraCompilationUnits().entrySet()) { - Element pkgrootEl = Util.findElement(entry.getValue(), "package-root", NbModuleProject.NAMESPACE_SHARED); // NOI18N - String pkgrootS = Util.findText(pkgrootEl); + Element pkgrootEl = XMLUtil.findElement(entry.getValue(), "package-root", NbModuleProject.NAMESPACE_SHARED); // NOI18N + String pkgrootS = XMLUtil.findText(pkgrootEl); sourcesHelper.sourceRoot(pkgrootS).type(JavaProjectConstants.SOURCES_TYPE_JAVA) .displayName(/* XXX should schema incl. display name? */entry.getKey().getNameExt()).add(); } @@ -340,7 +341,7 @@ AuxiliaryConfiguration ac = helper.createAuxiliaryConfiguration(); Element data = ac.getConfigurationFragment(NbModuleProject.NAME_SHARED, NbModuleProject.NAMESPACE_SHARED_2, true); if (data != null) { - return Util.translateXML(data, NbModuleProject.NAMESPACE_SHARED); + return XMLUtil.translateXML(data, NbModuleProject.NAMESPACE_SHARED); } else { return helper.getPrimaryConfigurationData(true); } @@ -357,7 +358,7 @@ public Void run() { AuxiliaryConfiguration ac = helper.createAuxiliaryConfiguration(); if (ac.getConfigurationFragment(NbModuleProject.NAME_SHARED, NbModuleProject.NAMESPACE_SHARED_2, true) != null) { - ac.putConfigurationFragment(Util.translateXML(data, NbModuleProject.NAMESPACE_SHARED_2), true); + ac.putConfigurationFragment(XMLUtil.translateXML(data, NbModuleProject.NAMESPACE_SHARED_2), true); } else { helper.putPrimaryConfigurationData(data, true); } @@ -373,9 +374,9 @@ private NbModuleProvider.NbModuleType getModuleType() { Element data = getPrimaryConfigurationData(); - if (Util.findElement(data, "suite-component", NbModuleProject.NAMESPACE_SHARED) != null) { // NOI18N + if (XMLUtil.findElement(data, "suite-component", NbModuleProject.NAMESPACE_SHARED) != null) { // NOI18N return NbModuleProvider.SUITE_COMPONENT; - } else if (Util.findElement(data, "standalone", NbModuleProject.NAMESPACE_SHARED) != null) { // NOI18N + } else if (XMLUtil.findElement(data, "standalone", NbModuleProject.NAMESPACE_SHARED) != null) { // NOI18N return NbModuleProvider.STANDALONE; } else { return NbModuleProvider.NETBEANS_ORG; @@ -471,9 +472,9 @@ public String getCodeNameBase() { Element config = getPrimaryConfigurationData(); - Element cnb = Util.findElement(config, "code-name-base", NbModuleProject.NAMESPACE_SHARED); // NOI18N + Element cnb = XMLUtil.findElement(config, "code-name-base", NbModuleProject.NAMESPACE_SHARED); // NOI18N if (cnb != null) { - return Util.findText(cnb); + return XMLUtil.findText(cnb); } else { return null; } @@ -623,12 +624,12 @@ return true; } Element config = getPrimaryConfigurationData(); - Element pubPkgs = Util.findElement(config, "public-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N + Element pubPkgs = XMLUtil.findElement(config, "public-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N if (pubPkgs == null) { // Try too. - pubPkgs = Util.findElement(config, "friend-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N + pubPkgs = XMLUtil.findElement(config, "friend-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N } - return pubPkgs != null && !Util.findSubElements(pubPkgs).isEmpty(); + return pubPkgs != null && !XMLUtil.findSubElements(pubPkgs).isEmpty(); } public List supportedTestTypes() { @@ -655,10 +656,10 @@ public Map getExtraCompilationUnits() { if (extraCompilationUnits == null) { extraCompilationUnits = new HashMap(); - for (Element ecu : Util.findSubElements(getPrimaryConfigurationData())) { + for (Element ecu : XMLUtil.findSubElements(getPrimaryConfigurationData())) { if (ecu.getLocalName().equals("extra-compilation-unit")) { // NOI18N - Element pkgrootEl = Util.findElement(ecu, "package-root", NbModuleProject.NAMESPACE_SHARED); // NOI18N - String pkgrootS = Util.findText(pkgrootEl); + Element pkgrootEl = XMLUtil.findElement(ecu, "package-root", NbModuleProject.NAMESPACE_SHARED); // NOI18N + String pkgrootS = XMLUtil.findText(pkgrootEl); String pkgrootEval = evaluator().evaluate(pkgrootS); FileObject pkgroot = getHelper().resolveFileObject(pkgrootEval); if (pkgroot == null) { diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ProjectXMLManager.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ProjectXMLManager.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ProjectXMLManager.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ProjectXMLManager.java @@ -218,9 +218,9 @@ } else { ml = ModuleList.getModuleList(prjDirF); } - for (Element depEl : Util.findSubElements(moduleDependencies)) { + for (Element depEl : XMLUtil.findSubElements(moduleDependencies)) { Element cnbEl = findElement(depEl, ProjectXMLManager.CODE_NAME_BASE); - String _cnb = Util.findText(cnbEl); + String _cnb = XMLUtil.findText(cnbEl); ModuleDependency depToAdd = getModuleDependency(_cnb, ml, depEl); if (depToAdd == null) { continue; @@ -255,13 +255,13 @@ Element relVerEl = findElement(runDepEl, ProjectXMLManager.RELEASE_VERSION); String relVer = null; if (relVerEl != null) { - relVer = Util.findText(relVerEl); + relVer = XMLUtil.findText(relVerEl); } Element specVerEl = findElement(runDepEl, ProjectXMLManager.SPECIFICATION_VERSION); String specVer = null; if (specVerEl != null) { - specVer = Util.findText(specVerEl); + specVer = XMLUtil.findText(specVerEl); } Element compDepEl = findElement(depEl, ProjectXMLManager.COMPILE_DEPENDENCY); @@ -287,9 +287,9 @@ } else { ml = ModuleList.getModuleList(prjDirF); } - for (Element dep : Util.findSubElements(moduleDependencies)) { + for (Element dep : XMLUtil.findSubElements(moduleDependencies)) { Element cnbEl = findElement(dep, ProjectXMLManager.CODE_NAME_BASE); - String depCnb = Util.findText(cnbEl); + String depCnb = XMLUtil.findText(cnbEl); if (depCnb.equals(cnb)) { return getModuleDependency(cnb, ml, dep); } @@ -301,9 +301,9 @@ public void removeDependency(String cnbToRemove) { Element _confData = getConfData(); Element moduleDependencies = findModuleDependencies(_confData); - for (Element dep : Util.findSubElements(moduleDependencies)) { + for (Element dep : XMLUtil.findSubElements(moduleDependencies)) { Element cnbEl = findElement(dep, ProjectXMLManager.CODE_NAME_BASE); - String _cnb = Util.findText(cnbEl); + String _cnb = XMLUtil.findText(cnbEl); if (cnbToRemove.equals(_cnb)) { moduleDependencies.removeChild(dep); } @@ -330,9 +330,9 @@ public void removeDependenciesByCNB(Collection cnbsToDelete) { Element _confData = getConfData(); Element moduleDependencies = findModuleDependencies(_confData); - for (Element dep : Util.findSubElements(moduleDependencies)) { + for (Element dep : XMLUtil.findSubElements(moduleDependencies)) { Element cnbEl = findElement(dep, ProjectXMLManager.CODE_NAME_BASE); - String _cnb = Util.findText(cnbEl); + String _cnb = XMLUtil.findText(cnbEl); if (cnbsToDelete.remove(_cnb)) { moduleDependencies.removeChild(dep); } @@ -350,11 +350,11 @@ public void editDependency(ModuleDependency origDep, ModuleDependency newDep) { Element _confData = getConfData(); Element moduleDependencies = findModuleDependencies(_confData); - List currentDeps = Util.findSubElements(moduleDependencies); + List currentDeps = XMLUtil.findSubElements(moduleDependencies); for (Iterator it = currentDeps.iterator(); it.hasNext();) { Element dep = it.next(); Element cnbEl = findElement(dep, ProjectXMLManager.CODE_NAME_BASE); - String _cnb = Util.findText(cnbEl); + String _cnb = XMLUtil.findText(cnbEl); if (_cnb.equals(origDep.getModuleEntry().getCodeNameBase())) { moduleDependencies.removeChild(dep); Element nextDep = it.hasNext() ? it.next() : null; @@ -474,21 +474,21 @@ Element _confData = getConfData(); Element testModuleDependenciesEl = findTestDependenciesElement(_confData); Element testTypeRemoveEl = null; - for (Element type : Util.findSubElements(testModuleDependenciesEl)) { + for (Element type : XMLUtil.findSubElements(testModuleDependenciesEl)) { Element nameEl = findElement(type, TEST_TYPE_NAME); - String nameOfType = Util.findText(nameEl); + String nameOfType = XMLUtil.findText(nameEl); if (testType.equals(nameOfType)) { testTypeRemoveEl = type; } } //found such a test type if (testTypeRemoveEl != null) { - for (Element el : Util.findSubElements(testTypeRemoveEl)) { + for (Element el : XMLUtil.findSubElements(testTypeRemoveEl)) { Element cnbEl = findElement(el, TEST_DEPENDENCY_CNB); if (cnbEl == null) { continue; //name node, continue } - String _cnb = Util.findText(cnbEl); + String _cnb = XMLUtil.findText(cnbEl); if (cnbToRemove.equals(_cnb)) { // found test dependency with desired CNB testTypeRemoveEl.removeChild(el); @@ -542,7 +542,7 @@ } Element testTypeEl = null; //iterate through test types to determine if testType exist - for (Element tt : Util.findSubElements(testModuleDependenciesEl)) { + for (Element tt : XMLUtil.findSubElements(testModuleDependenciesEl)) { Node nameNode = findElement(tt, "name"); // NOI18N assert nameNode != null : "should be some child with name"; //Node nameNode = tt.getFirstChild(); @@ -638,24 +638,24 @@ Map> testDeps = new HashMap>(); if (testDepsEl != null) { - for (Element typeEl : Util.findSubElements(testDepsEl)) { + for (Element typeEl : XMLUtil.findSubElements(testDepsEl)) { Element testTypeEl = findElement(typeEl, TEST_TYPE_NAME); String testType = null; if (testTypeEl != null) { - testType = Util.findText(testTypeEl); + testType = XMLUtil.findText(testTypeEl); } if (testType == null) { testType = TestModuleDependency.UNIT; // default variant } Set directTestDeps = new TreeSet(); - for (Element depEl : Util.findSubElements(typeEl)) { + for (Element depEl : XMLUtil.findSubElements(typeEl)) { if (depEl.getTagName().equals(TEST_DEPENDENCY)) { // parse test dep Element cnbEl = findElement(depEl, TEST_DEPENDENCY_CNB); boolean test = findElement(depEl, TEST_DEPENDENCY_TEST) != null; String _cnb = null; if (cnbEl != null) { - _cnb = Util.findText(cnbEl); + _cnb = XMLUtil.findText(cnbEl); } boolean recursive = findElement(depEl, TEST_DEPENDENCY_RECURSIVE) != null; boolean compile = findElement(depEl, TEST_DEPENDENCY_COMPILE) != null; @@ -806,12 +806,12 @@ return Collections.unmodifiableMap(cpExtensions); } Map cps = new HashMap(); - for (Element cpExtEl : Util.findSubElements(getConfData())) { + for (Element cpExtEl : XMLUtil.findSubElements(getConfData())) { if (CLASS_PATH_EXTENSION.equals(cpExtEl.getTagName())) { Element binOrigEl = findElement(cpExtEl, BINARY_ORIGIN); Element runtimePathEl = findElement(cpExtEl, CLASS_PATH_RUNTIME_PATH); if (binOrigEl != null && runtimePathEl != null) { - cps.put(Util.findText(runtimePathEl), Util.findText(binOrigEl)); + cps.put(XMLUtil.findText(runtimePathEl), XMLUtil.findText(binOrigEl)); } } } @@ -822,7 +822,7 @@ public String getCodeNameBase() { if (cnb == null) { Element cnbEl = findElement(getConfData(), ProjectXMLManager.CODE_NAME_BASE); - cnb = Util.findText(cnbEl); + cnb = XMLUtil.findText(cnbEl); } return cnb; } @@ -875,7 +875,7 @@ } private static Element findElement(Element parentEl, String elementName) { - return Util.findElement(parentEl, elementName, NbModuleProject.NAMESPACE_SHARED); + return XMLUtil.findElement(parentEl, elementName, NbModuleProject.NAMESPACE_SHARED); } /** Package-private for unit tests only. */ @@ -922,11 +922,11 @@ */ private static Set findAllPackages(Element parent) { Set packages = new HashSet(); - for (Element pkgEl : Util.findSubElements(parent)) { + for (Element pkgEl : XMLUtil.findSubElements(parent)) { if (PACKAGE.equals(pkgEl.getTagName())) { - packages.add(new ManifestManager.PackageExport(Util.findText(pkgEl), false)); + packages.add(new ManifestManager.PackageExport(XMLUtil.findText(pkgEl), false)); } else if (SUBPACKAGES.equals(pkgEl.getTagName())) { - packages.add(new ManifestManager.PackageExport(Util.findText(pkgEl), true)); + packages.add(new ManifestManager.PackageExport(XMLUtil.findText(pkgEl), true)); } } return packages; @@ -958,9 +958,9 @@ Element friendsEl = findFriendsElement(confData); if (friendsEl != null) { Set friends = new TreeSet(); - for (Element friendEl : Util.findSubElements(friendsEl)) { + for (Element friendEl : XMLUtil.findSubElements(friendsEl)) { if (FRIEND.equals(friendEl.getTagName())) { - friends.add(Util.findText(friendEl)); + friends.add(XMLUtil.findText(friendEl)); } } return friends.toArray(new String[friends.size()]); diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/Util.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/Util.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/Util.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/Util.java @@ -122,108 +122,6 @@ private static final String SFS_VALID_PATH_RE = "(\\p{Alnum}|\\/|_)+"; // NOI18N - // COPIED FROM org.netbeans.modules.project.ant: - // (except for namespace == null support in findElement) - // (and support for comments in findSubElements) - - /** - * 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 (or null) - * @return the first child element with that name, or null if none - */ - public static Element findElement(Element parent, String name, String namespace) { - NodeList l = parent.getChildNodes(); - for (int i = 0; i < l.getLength(); i++) { - if (l.item(i).getNodeType() == Node.ELEMENT_NODE) { - Element el = (Element)l.item(i); - if ((namespace == null && name.equals(el.getTagName())) || - (namespace != null && name.equals(el.getLocalName()) && - namespace.equals(el.getNamespaceURI()))) { - return el; - } - } - } - return null; - } - - /** - * 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 or comments 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) { - // OK, ignore - } else { - throw new IllegalArgumentException("unexpected non-element child of " + parent + ": " + n); // NOI18N - } - } - return elements; - } - - /** - * Convert an XML fragment from one namespace to another. - */ - public static Element translateXML(Element from, String namespace) { - Element to = from.getOwnerDocument().createElementNS(namespace, from.getLocalName()); - NodeList nl = from.getChildNodes(); - int length = nl.getLength(); - for (int i = 0; i < length; i++) { - Node node = nl.item(i); - Node newNode; - if (node.getNodeType() == Node.ELEMENT_NODE) { - newNode = translateXML((Element) node, namespace); - } else { - newNode = node.cloneNode(true); - } - to.appendChild(newNode); - } - NamedNodeMap m = from.getAttributes(); - for (int i = 0; i < m.getLength(); i++) { - Node attr = m.item(i); - to.setAttribute(attr.getNodeName(), attr.getNodeValue()); - } - return to; - } - /** * Pass to {@link XPath#setNamespaceContext} to bind {@code nbm:} to the /3 namespace. */ diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/AccessibilityQueryImpl.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/AccessibilityQueryImpl.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/AccessibilityQueryImpl.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/AccessibilityQueryImpl.java @@ -48,6 +48,7 @@ import org.openide.ErrorManager; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.xml.XMLUtil; import org.w3c.dom.Element; /** @@ -69,17 +70,17 @@ if (path != null) { String name = path.replace('/', '.'); Element config = project.getPrimaryConfigurationData(); - Element pubPkgs = Util.findElement(config, "public-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N + Element pubPkgs = XMLUtil.findElement(config, "public-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N if (pubPkgs == null) { // Try too. - pubPkgs = Util.findElement(config, "friend-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N + pubPkgs = XMLUtil.findElement(config, "friend-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N } if (pubPkgs != null) { - Iterator it = Util.findSubElements(pubPkgs).iterator(); + Iterator it = XMLUtil.findSubElements(pubPkgs).iterator(); while (it.hasNext()) { Element pubPkg = (Element) it.next(); boolean sub = "subpackages".equals(pubPkg.getLocalName()); // NOI18N - String pubPkgS = Util.findText(pubPkg); + String pubPkgS = XMLUtil.findText(pubPkg); if (name.equals(pubPkgS) || (sub && name.startsWith(pubPkgS + '.'))) { return true; } diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/ClassPathProviderImpl.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/ClassPathProviderImpl.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/ClassPathProviderImpl.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/ClassPathProviderImpl.java @@ -63,7 +63,6 @@ import org.netbeans.spi.java.classpath.ClassPathProvider; import org.netbeans.spi.java.classpath.support.ClassPathSupport; import org.netbeans.modules.apisupport.project.NbModuleProject; -import org.netbeans.modules.apisupport.project.Util; import org.netbeans.spi.java.classpath.PathResourceImplementation; import org.netbeans.spi.java.project.classpath.support.ProjectClassPathSupport; import org.netbeans.spi.project.support.ant.AntProjectEvent; @@ -74,6 +73,7 @@ import org.openide.filesystems.FileStateInvalidException; import org.openide.filesystems.FileUtil; import org.openide.util.WeakListeners; +import org.openide.xml.XMLUtil; import org.w3c.dom.Element; public final class ClassPathProviderImpl implements ClassPathProvider { @@ -296,9 +296,9 @@ for (Map.Entry entry : project.getExtraCompilationUnits().entrySet()) { final FileObject pkgroot = entry.getKey(); Element pkgrootEl = entry.getValue(); - Element classpathEl = Util.findElement(pkgrootEl, "classpath", NbModuleProject.NAMESPACE_SHARED); // NOI18N + Element classpathEl = XMLUtil.findElement(pkgrootEl, "classpath", NbModuleProject.NAMESPACE_SHARED); // NOI18N assert classpathEl != null : "no in " + pkgrootEl; - final String classpathS = Util.findText(classpathEl); + final String classpathS = XMLUtil.findText(classpathEl); if (classpathS == null) { extraCompilationUnitsCompile.put(pkgroot, ClassPathSupport.createClassPath(new URL[0])); extraCompilationUnitsExecute.put(pkgroot, ClassPathSupport.createClassPath(new URL[0])); @@ -333,9 +333,9 @@ } public void configurationXmlChanged(AntProjectEvent ev) { Element pkgrootEl = project.getExtraCompilationUnits().get(pkgroot); - Element classpathEl = Util.findElement(pkgrootEl, "classpath", NbModuleProject.NAMESPACE_SHARED); // NOI18N + Element classpathEl = XMLUtil.findElement(pkgrootEl, "classpath", NbModuleProject.NAMESPACE_SHARED); // NOI18N assert classpathEl != null : "no in " + pkgrootEl; - cpS = Util.findText(classpathEl); + cpS = XMLUtil.findText(classpathEl); pcs.firePropertyChange(PROP_RESOURCES, null, null); } public void propertiesChanged(AntProjectEvent ev) {} @@ -344,11 +344,11 @@ extraCompilationUnitsCompile.put(pkgroot, ClassPathFactory.createClassPath(ecuCompile)); // Add dirs and JARs for ClassPath.EXECUTE. List extraEntries = new ArrayList(); - for (Element kid : Util.findSubElements(pkgrootEl)) { + for (Element kid : XMLUtil.findSubElements(pkgrootEl)) { if (!kid.getLocalName().equals("built-to")) { // NOI18N continue; } - String rawtext = Util.findText(kid); + String rawtext = XMLUtil.findText(kid); assert rawtext != null : "Null content for in " + project; String text = project.evaluator().evaluate(rawtext); if (text == null) { diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/GlobalSourceForBinaryImpl.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/GlobalSourceForBinaryImpl.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/GlobalSourceForBinaryImpl.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/GlobalSourceForBinaryImpl.java @@ -409,13 +409,13 @@ is.close(); } Element docel = doc.getDocumentElement(); - Element type = Util.findElement(docel, "type", "http://www.netbeans.org/ns/project/1"); // NOI18N + Element type = XMLUtil.findElement(docel, "type", "http://www.netbeans.org/ns/project/1"); // NOI18N String cnb = null; - if (Util.findText(type).equals("org.netbeans.modules.apisupport.project")) { // NOI18N - Element cfg = Util.findElement(docel, "configuration", "http://www.netbeans.org/ns/project/1"); // NOI18N - Element data = Util.findElement(cfg, "data", null); // NOI18N + if (XMLUtil.findText(type).equals("org.netbeans.modules.apisupport.project")) { // NOI18N + Element cfg = XMLUtil.findElement(docel, "configuration", "http://www.netbeans.org/ns/project/1"); // NOI18N + Element data = XMLUtil.findElement(cfg, "data", null); // NOI18N if (data != null) { - cnb = Util.findText(Util.findElement(data, "code-name-base", null)); // NOI18N + cnb = XMLUtil.findText(XMLUtil.findElement(data, "code-name-base", null)); // NOI18N } } return cnb; diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/SourceForBinaryImpl.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/SourceForBinaryImpl.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/SourceForBinaryImpl.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/SourceForBinaryImpl.java @@ -50,11 +50,11 @@ import javax.swing.event.ChangeListener; import org.netbeans.api.java.queries.SourceForBinaryQuery; import org.netbeans.modules.apisupport.project.NbModuleProject; -import org.netbeans.modules.apisupport.project.Util; import org.netbeans.modules.apisupport.project.universe.TestEntry; import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.xml.XMLUtil; import org.w3c.dom.Element; /** @@ -136,11 +136,11 @@ if (res == null) { // Check extra compilation units. ECUS: for (Map.Entry entry : project.getExtraCompilationUnits().entrySet()) { - for (Element kid : Util.findSubElements(entry.getValue())) { + for (Element kid : XMLUtil.findSubElements(entry.getValue())) { if (!kid.getLocalName().equals("built-to")) { // NOI18N continue; } - String rawtext = Util.findText(kid); + String rawtext = XMLUtil.findText(kid); assert rawtext != null : "Null content for in " + project; String text = project.evaluator().evaluate(rawtext); if (text == null) { diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/SubprojectProviderImpl.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/SubprojectProviderImpl.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/SubprojectProviderImpl.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/SubprojectProviderImpl.java @@ -64,6 +64,7 @@ import org.openide.ErrorManager; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.xml.XMLUtil; import org.w3c.dom.Element; /** @@ -90,19 +91,19 @@ return Collections.emptySet(); } Element data = project.getPrimaryConfigurationData(); - Element moduleDependencies = Util.findElement(data, + Element moduleDependencies = XMLUtil.findElement(data, "module-dependencies", NbModuleProject.NAMESPACE_SHARED); // NOI18N assert moduleDependencies != null : "Malformed metadata in " + project; - for (Element dep : Util.findSubElements(moduleDependencies)) { + for (Element dep : XMLUtil.findSubElements(moduleDependencies)) { /* Probably better to open runtime deps too. TBD. if (Util.findElement(dep, "build-prerequisite", // NOI18N NbModuleProject.NAMESPACE_SHARED) == null) { continue; } */ - Element cnbEl = Util.findElement(dep, "code-name-base", // NOI18N + Element cnbEl = XMLUtil.findElement(dep, "code-name-base", // NOI18N NbModuleProject.NAMESPACE_SHARED); - String cnb = Util.findText(cnbEl); + String cnb = XMLUtil.findText(cnbEl); ModuleEntry module = ml.getEntry(cnb); if (module == null) { Util.err.log(ErrorManager.WARNING, "Warning - could not find dependent module " + cnb + " for " + project); @@ -130,15 +131,15 @@ } } // #63824: consider also artifacts found in ${cp.extra} and/or s - for (Element cpext : Util.findSubElements(data)) { + for (Element cpext : XMLUtil.findSubElements(data)) { if (!cpext.getTagName().equals("class-path-extension")) { // NOI18N continue; } - Element binorig = Util.findElement(cpext, "binary-origin", NbModuleProject.NAMESPACE_SHARED); // NOI18N + Element binorig = XMLUtil.findElement(cpext, "binary-origin", NbModuleProject.NAMESPACE_SHARED); // NOI18N if (binorig == null) { continue; } - String text = Util.findText(binorig); + String text = XMLUtil.findText(binorig); String eval = project.evaluator().evaluate(text); if (eval == null) { continue; diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/suite/SuiteProject.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/suite/SuiteProject.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/suite/SuiteProject.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/suite/SuiteProject.java @@ -89,6 +89,7 @@ import org.openide.util.Lookup; import org.openide.util.Mutex; import org.openide.util.lookup.Lookups; +import org.openide.xml.XMLUtil; import org.w3c.dom.Element; /** @@ -242,8 +243,8 @@ } private String getSimpleName() { - Element nameEl = Util.findElement(helper.getPrimaryConfigurationData(true), "name", SuiteProjectType.NAMESPACE_SHARED); // NOI18N - String text = (nameEl != null) ? Util.findText(nameEl) : null; + Element nameEl = XMLUtil.findElement(helper.getPrimaryConfigurationData(true), "name", SuiteProjectType.NAMESPACE_SHARED); // NOI18N + String text = (nameEl != null) ? XMLUtil.findText(nameEl) : null; return (text != null) ? text : "???"; // NOI18N } diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/customizer/BasicBrandingModel.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/customizer/BasicBrandingModel.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/customizer/BasicBrandingModel.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/customizer/BasicBrandingModel.java @@ -55,7 +55,6 @@ import org.netbeans.api.annotations.common.CheckForNull; import org.netbeans.api.annotations.common.NullAllowed; import org.netbeans.api.project.Project; -import org.netbeans.modules.apisupport.project.Util; import org.netbeans.modules.apisupport.project.suite.BrandingSupport; import org.netbeans.modules.apisupport.project.suite.BrandingSupport.BrandedFile; import org.netbeans.modules.apisupport.project.suite.BrandingSupport.BundleKey; @@ -65,6 +64,7 @@ import org.openide.filesystems.FileUtil; import org.openide.util.ChangeSupport; import org.openide.util.NbBundle; +import org.openide.xml.XMLUtil; import org.w3c.dom.Element; /** @@ -385,8 +385,8 @@ res = getProjectDirectoryFile().getName(); return res; } - Element nameEl = Util.findElement(suiteProps.getProject().getHelper().getPrimaryConfigurationData(true), "name", SuiteProjectType.NAMESPACE_SHARED); // NOI18N - String text = (nameEl != null) ? Util.findText(nameEl) : null; + Element nameEl = XMLUtil.findElement(suiteProps.getProject().getHelper().getPrimaryConfigurationData(true), "name", SuiteProjectType.NAMESPACE_SHARED); // NOI18N + String text = (nameEl != null) ? XMLUtil.findText(nameEl) : null; return (text != null) ? text : "???"; // NOI18N } diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/customizer/SuiteCustomizerLibraries.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/customizer/SuiteCustomizerLibraries.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/customizer/SuiteCustomizerLibraries.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/customizer/SuiteCustomizerLibraries.java @@ -1467,23 +1467,23 @@ dependencies = new HashSet(); // Cannot use ProjectXMLManager since we need to report also deps on nonexistent modules. Element dataE = project.getPrimaryConfigurationData(); - Element depsE = Util.findElement(dataE, "module-dependencies", NbModuleProject.NAMESPACE_SHARED); // NOI18N + Element depsE = XMLUtil.findElement(dataE, "module-dependencies", NbModuleProject.NAMESPACE_SHARED); // NOI18N assert depsE != null : "Malformed metadata in " + project; - for (Element dep : Util.findSubElements(depsE)) { - Element run = Util.findElement(dep, "run-dependency", NbModuleProject.NAMESPACE_SHARED); // NOI18N + for (Element dep : XMLUtil.findSubElements(depsE)) { + Element run = XMLUtil.findElement(dep, "run-dependency", NbModuleProject.NAMESPACE_SHARED); // NOI18N if (run == null) { continue; } - String text = Util.findText(Util.findElement(dep, "code-name-base", NbModuleProject.NAMESPACE_SHARED)); // NOI18N - Element relverE = Util.findElement(run, "release-version", NbModuleProject.NAMESPACE_SHARED); // NOI18N + String text = XMLUtil.findText(XMLUtil.findElement(dep, "code-name-base", NbModuleProject.NAMESPACE_SHARED)); // NOI18N + Element relverE = XMLUtil.findElement(run, "release-version", NbModuleProject.NAMESPACE_SHARED); // NOI18N if (relverE != null) { - text += '/' + Util.findText(relverE); + text += '/' + XMLUtil.findText(relverE); } - Element specverE = Util.findElement(run, "specification-version", NbModuleProject.NAMESPACE_SHARED); // NOI18N + Element specverE = XMLUtil.findElement(run, "specification-version", NbModuleProject.NAMESPACE_SHARED); // NOI18N if (specverE != null) { - text += " > " + Util.findText(specverE); + text += " > " + XMLUtil.findText(specverE); } else { - Element implver = Util.findElement(run, "implementation-version", NbModuleProject.NAMESPACE_SHARED); // NOI18N + Element implver = XMLUtil.findElement(run, "implementation-version", NbModuleProject.NAMESPACE_SHARED); // NOI18N if (implver != null) { // Will special-case '*' as an impl version to mean "match anything". text += " = *"; // NOI18N diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/universe/AbstractEntryWithSources.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/universe/AbstractEntryWithSources.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/universe/AbstractEntryWithSources.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/universe/AbstractEntryWithSources.java @@ -54,6 +54,7 @@ import org.openide.ErrorManager; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.xml.XMLUtil; import org.w3c.dom.Element; abstract class AbstractEntryWithSources extends AbstractEntry { @@ -136,17 +137,17 @@ return new String[0]; } Element data = project.getPrimaryConfigurationData(); - Element moduleDependencies = Util.findElement(data, + Element moduleDependencies = XMLUtil.findElement(data, "module-dependencies", NbModuleProject.NAMESPACE_SHARED); // NOI18N assert moduleDependencies != null : "Malformed metadata in " + project; - for (Element dep : Util.findSubElements(moduleDependencies)) { - if (Util.findElement(dep, "run-dependency", // NOI18N + for (Element dep : XMLUtil.findSubElements(moduleDependencies)) { + if (XMLUtil.findElement(dep, "run-dependency", // NOI18N NbModuleProject.NAMESPACE_SHARED) == null) { continue; } - Element cnbEl = Util.findElement(dep, "code-name-base", // NOI18N + Element cnbEl = XMLUtil.findElement(dep, "code-name-base", // NOI18N NbModuleProject.NAMESPACE_SHARED); - String cnb = Util.findText(cnbEl); + String cnb = XMLUtil.findText(cnbEl); deps.add(cnb); } return deps.toArray(new String[deps.size()]); diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/universe/ModuleList.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/universe/ModuleList.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/universe/ModuleList.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/universe/ModuleList.java @@ -206,8 +206,8 @@ if (data == null) { throw new IOException("Not an NBM project in " + basedir); // NOI18N } - boolean suiteComponent = Util.findElement(data, "suite-component", NbModuleProject.NAMESPACE_SHARED) != null; // NOI18N - boolean standalone = Util.findElement(data, "standalone", NbModuleProject.NAMESPACE_SHARED) != null; // NOI18N + boolean suiteComponent = XMLUtil.findElement(data, "suite-component", NbModuleProject.NAMESPACE_SHARED) != null; // NOI18N + boolean standalone = XMLUtil.findElement(data, "standalone", NbModuleProject.NAMESPACE_SHARED) != null; // NOI18N assert !(suiteComponent && standalone) : basedir; if (suiteComponent) { PropertyEvaluator eval = parseProperties(basedir, null, NbModuleType.SUITE_COMPONENT, "irrelevant"); // NOI18N @@ -598,23 +598,23 @@ } assert root != null ^ type != NbModuleType.NETBEANS_ORG; assert path != null ^ type != NbModuleType.NETBEANS_ORG; - String cnb = Util.findText(Util.findElement(data, "code-name-base", NbModuleProject.NAMESPACE_SHARED)); // NOI18N + String cnb = XMLUtil.findText(XMLUtil.findElement(data, "code-name-base", NbModuleProject.NAMESPACE_SHARED)); // NOI18N PropertyEvaluator eval = parseProperties(basedir, root, type, cnb); String module = eval.getProperty("module.jar"); // NOI18N // Cf. ParseProjectXml.computeClasspath: StringBuffer cpextra = new StringBuffer(); - for (Element ext : Util.findSubElements(data)) { + for (Element ext : XMLUtil.findSubElements(data)) { if (!ext.getLocalName().equals("class-path-extension")) { // NOI18N continue; } - Element binaryOrigin = Util.findElement(ext, "binary-origin", NbModuleProject.NAMESPACE_SHARED); // NOI18N + Element binaryOrigin = XMLUtil.findElement(ext, "binary-origin", NbModuleProject.NAMESPACE_SHARED); // NOI18N String text; if (binaryOrigin != null) { - text = Util.findText(binaryOrigin); + text = XMLUtil.findText(binaryOrigin); } else { - Element runtimeRelativePath = Util.findElement(ext, "runtime-relative-path", NbModuleProject.NAMESPACE_SHARED); // NOI18N + Element runtimeRelativePath = XMLUtil.findElement(ext, "runtime-relative-path", NbModuleProject.NAMESPACE_SHARED); // NOI18N assert runtimeRelativePath != null : "Malformed in " + basedir; - String reltext = Util.findText(runtimeRelativePath); + String reltext = XMLUtil.findText(runtimeRelativePath); // XXX assumes that module.jar is not overridden independently of module.jar.dir: text = "${cluster}/${module.jar.dir}/" + reltext; // NOI18N } @@ -1034,9 +1034,9 @@ } catch (SAXException e) { throw (IOException) new IOException(e.toString()).initCause(e); } - for (Element moduleVersion : Util.findSubElements(doc.getDocumentElement())) { + for (Element moduleVersion : XMLUtil.findSubElements(doc.getDocumentElement())) { if (moduleVersion.getTagName().equals("module_version") && moduleVersion.getAttribute("last").equals("true")) { // NOI18N - for (Element fileEl : Util.findSubElements(moduleVersion)) { + for (Element fileEl : XMLUtil.findSubElements(moduleVersion)) { if (fileEl.getTagName().equals("file")) { // NOI18N String name = fileEl.getAttribute("name"); // NOI18N File f = new File(cluster, name.replace('/', File.separatorChar)); @@ -1074,18 +1074,18 @@ throw (IOException) new IOException(projectXml + ": " + e.toString()).initCause(e); // NOI18N } Element docel = doc.getDocumentElement(); - Element type = Util.findElement(docel, "type", "http://www.netbeans.org/ns/project/1"); // NOI18N - if (!Util.findText(type).equals("org.netbeans.modules.apisupport.project")) { // NOI18N + Element type = XMLUtil.findElement(docel, "type", "http://www.netbeans.org/ns/project/1"); // NOI18N + if (!XMLUtil.findText(type).equals("org.netbeans.modules.apisupport.project")) { // NOI18N return null; } - Element cfg = Util.findElement(docel, "configuration", "http://www.netbeans.org/ns/project/1"); // NOI18N - Element data = Util.findElement(cfg, "data", NbModuleProject.NAMESPACE_SHARED); // NOI18N + Element cfg = XMLUtil.findElement(docel, "configuration", "http://www.netbeans.org/ns/project/1"); // NOI18N + Element data = XMLUtil.findElement(cfg, "data", NbModuleProject.NAMESPACE_SHARED); // NOI18N if (data != null) { return data; } else { - data = Util.findElement(cfg, "data", NbModuleProject.NAMESPACE_SHARED_2); // NOI18N + data = XMLUtil.findElement(cfg, "data", NbModuleProject.NAMESPACE_SHARED_2); // NOI18N if (data != null) { - return Util.translateXML(data, NbModuleProject.NAMESPACE_SHARED); + return XMLUtil.translateXML(data, NbModuleProject.NAMESPACE_SHARED); } else { return null; } diff --git a/apisupport.project/test/unit/src/org/netbeans/modules/apisupport/project/ProjectXMLManagerTest.java b/apisupport.project/test/unit/src/org/netbeans/modules/apisupport/project/ProjectXMLManagerTest.java --- a/apisupport.project/test/unit/src/org/netbeans/modules/apisupport/project/ProjectXMLManagerTest.java +++ b/apisupport.project/test/unit/src/org/netbeans/modules/apisupport/project/ProjectXMLManagerTest.java @@ -303,8 +303,8 @@ Document doc = XMLUtil.parse(new InputSource(projectXML.toURI().toString()), false, true, null, null); Element project = doc.getDocumentElement(); - Element config = Util.findElement(project, "configuration", null); // NOI18N - data = Util.findElement(config, "data", NbModuleProject.NAMESPACE_SHARED); + Element config = XMLUtil.findElement(project, "configuration", null); // NOI18N + data = XMLUtil.findElement(config, "data", NbModuleProject.NAMESPACE_SHARED); } catch (IOException e) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); } catch (SAXException e) {