pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1647420 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/XMLUtil.java
Date Mon, 22 Dec 2014 21:52:29 GMT
Author: msahyoun
Date: Mon Dec 22 21:52:29 2014
New Revision: 1647420

URL: http://svn.apache.org/r1647420
Log:
PDFBOX-2576 provide cause of exception; StringBuilder for concatenation

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/XMLUtil.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/XMLUtil.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/XMLUtil.java?rev=1647420&r1=1647419&r2=1647420&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/XMLUtil.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/XMLUtil.java Mon Dec 22
21:52:29 2014
@@ -21,12 +21,15 @@ import java.io.IOException;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.parsers.ParserConfigurationException;
 
 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;
+import org.xml.sax.SAXException;
 
 /**
  * This class with handle some simple XML operations.
@@ -58,10 +61,17 @@ final class XMLUtil
             DocumentBuilder builder = builderFactory.newDocumentBuilder();
             return builder.parse( is );
         }
-        catch( Exception e )
+        catch (FactoryConfigurationError  e)
         {
-            IOException thrown = new IOException( e.getMessage() );
-            throw thrown;
+            throw new IOException( e.getMessage(), e );
+        }
+        catch (ParserConfigurationException e)
+        {
+            throw new IOException( e.getMessage(), e );
+        }
+        catch (SAXException e)
+        {
+            throw new IOException( e.getMessage(), e );
         }
     }
 
@@ -73,16 +83,17 @@ final class XMLUtil
      */
     public static String getNodeValue( Element node )
     {
-        String retval = "";
+        StringBuilder sb = new StringBuilder();
         NodeList children = node.getChildNodes();
-        for( int i=0; i<children.getLength(); i++ )
+        int numNodes = children.getLength();
+        for( int i=0; i<numNodes; i++ )
         {
             Node next = children.item( i );
             if( next instanceof Text )
             {
-                retval += next.getNodeValue();
+                sb.append(next.getNodeValue());
             }
         }
-        return retval;
+        return sb.toString();
     }
 }



Mime
View raw message