jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1832797 - /jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java
Date Mon, 04 Jun 2018 07:15:43 GMT
Author: pmouawad
Date: Mon Jun  4 07:15:43 2018
New Revision: 1832797

URL: http://svn.apache.org/viewvc?rev=1832797&view=rev
Log:
Bug 60991 - XPath Extractor : Implement XPath 2.0

Fix some SONAR warnings
Bugzilla Id: 60991

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java

Modified: jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java?rev=1832797&r1=1832796&r2=1832797&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java Mon Jun  4 07:15:43 2018
@@ -477,7 +477,7 @@ public class XPathUtil {
                     if(selector != null) {
                         try {
                             selector.getUnderlyingXPathContext().setContextItem(null);
-                        } catch (Exception e) {
+                        } catch (Exception e) { // NOSONAR Ignored on purpose
                             // NOOP
                         }
                     }
@@ -518,18 +518,23 @@ public class XPathUtil {
         return res;
     }
 
+    /**
+     * Compute namespaces for XML
+     * @param xml XML content
+     * @return List of Namespaces
+     * @throws XMLStreamException
+     * @throws FactoryConfigurationError
+     */
     public static List<String[]> getNamespaces(String xml)
             throws XMLStreamException, FactoryConfigurationError{
         List<String[]> res= new ArrayList<>();
         XMLStreamReader reader;
-        if(!xml.equals("")) {
+        if(StringUtils.isNoneEmpty(xml)) {
             reader = XMLInputFactory.newFactory().createXMLStreamReader(new StringReader(xml));
             while (reader.hasNext()) {
                 int event = reader.next();
-                if (XMLStreamConstants.START_ELEMENT == event) {
-                    addToList(reader, res);
-                } else if(XMLStreamConstants.NAMESPACE == event) {
-                    // This almost never happens
+                if (XMLStreamConstants.START_ELEMENT == event ||
+                        XMLStreamConstants.NAMESPACE == event) {
                     addToList(reader, res);
                 }
             }
@@ -542,7 +547,6 @@ public class XPathUtil {
         int namespaceCount = reader.getNamespaceCount(); 
         if (namespaceCount > 0) {
             for (int nsIndex = 0; nsIndex < namespaceCount; nsIndex++) {
-                String[] tmp = {"",""};
                 String nsPrefix = reader.getNamespacePrefix(nsIndex);
                 for(int i = 0;i<res.size();i++) {
                     String prefix = res.get(i)[0];
@@ -553,9 +557,7 @@ public class XPathUtil {
                 }
                 if(!isInList) {
                     String nsId = reader.getNamespaceURI(nsIndex);
-                    tmp[0] = nsPrefix;
-                    tmp[1] = nsId;
-                    res.add(tmp);
+                    res.add(new String[] {nsPrefix, nsId});
                 }
                 isInList=false;
             }



Mime
View raw message