Преглед на файлове

XMLQuery nie rzuca wyjątków

Ranides Atterwim преди 13 години
родител
ревизия
74c543cf33
променени са 2 файла, в които са добавени 29 реда и са изтрити 2 реда
  1. 1 1
      pom.xml
  2. 28 1
      src/main/java/net/ranides/assira/xml/XMLQuery.java

+ 1 - 1
pom.xml

@@ -4,7 +4,7 @@
 
     <groupId>net.ranides</groupId>
     <artifactId>assira</artifactId>
-    <version>0.60.5</version>
+    <version>0.60.6</version>
     <packaging>jar</packaging>
 
     <name>assira</name>

+ 28 - 1
src/main/java/net/ranides/assira/xml/XMLQuery.java

@@ -53,11 +53,20 @@ final public class XMLQuery {
 
 
     public static String attr(Node node, String attribName) throws XMLQueryException {
+        if(node == null) {
+            return null;
+        }
         Node attrNode = node.getAttributes().getNamedItem(attribName);
-        return attrNode == null ? null : attrNode.getNodeValue();
+        if(attrNode == null) {
+            return null;
+        }
+        return attrNode.getNodeValue();
     }
     
     public static boolean has(Node node, String attribName) {
+        if(node == null) {
+            return false;
+        }
         return null != node.getAttributes().getNamedItem(attribName);
     }
 
@@ -91,6 +100,9 @@ final public class XMLQuery {
 
     public static List<Node> filter(Node node, String tagname) {
         List<Node> result = new LinkedList<Node>();
+        if(node == null) {
+            return result;
+        }
         for(Node value : NodeCollection.nodes(node) )  {
             if( (Node.ELEMENT_NODE==value.getNodeType()) && tagname.equals(value.getNodeName()) ) {
                 result.add(value);
@@ -100,6 +112,9 @@ final public class XMLQuery {
     }
     
     public static Node node(Node node, String tagname) {
+        if(node == null) {
+            return null;
+        }
         for(Node value : NodeCollection.nodes(node) )  {
             if( (Node.ELEMENT_NODE==value.getNodeType()) && tagname.equals(value.getNodeName()) ) {
                 return value;
@@ -110,6 +125,9 @@ final public class XMLQuery {
 
     public static List<Node> filter(Node node, NodeType type) {
         List<Node> result = new LinkedList<Node>();
+        if(node == null) {
+            return result;
+        }
         for(Node value : NodeCollection.nodes(node) )  {
             if( type.match(value.getNodeType()) ) {
                 result.add(value);
@@ -119,6 +137,9 @@ final public class XMLQuery {
     }
 
     public static int count(Node node, String tagname) {
+        if(node == null) {
+            return 0;
+        }
         int count = 0;
         for(Node value : NodeCollection.nodes(node) )  {
             if( (Node.ELEMENT_NODE==value.getNodeType()) && tagname.equals(value.getNodeName()) ) {
@@ -129,6 +150,9 @@ final public class XMLQuery {
     }
 
     public static int count(Node node, NodeType type) {
+        if(node == null) {
+            return 0;
+        }
         int count = 0;
         for(Node value : NodeCollection.nodes(node) )  {
             if( type.match(value) ) { count ++; }
@@ -141,6 +165,9 @@ final public class XMLQuery {
     }
     
     public static boolean exists(Node node, String tagname) {
+        if(node == null) {
+            return false;
+        }
         for(Node value : NodeCollection.nodes(node) )  {
             if( (Node.ELEMENT_NODE==value.getNodeType()) && tagname.equals(value.getNodeName()) ) {
                 return true;