ClasspathUriResolver is now also an LSInputResolver so it can be used for both XSLT...
[utils] / support / general / src / main / java / org / wamblee / xml / DomUtils.java
index 44a9f8ee8268a4cb946d7bc6adb7478e21a84f34..a0a118c1062cd82e8fd0aac29bb84fb01a371fb3 100644 (file)
@@ -97,23 +97,13 @@ public final class DomUtils {
      */
     public static Document read(InputStream aIs) throws XMLException {
         try {
-            DOMImplementationRegistry registry = DOMImplementationRegistry
-                .newInstance();
-
-            DOMImplementationLS impl = (DOMImplementationLS) registry
-                .getDOMImplementation("LS");
+            DOMImplementationLS impl = getDomImplementationLS();
 
             LSParser builder = impl.createLSParser(
                 DOMImplementationLS.MODE_SYNCHRONOUS, null);
             LSInput input = impl.createLSInput();
             input.setByteStream(aIs);
             return builder.parse(input);
-        } catch (IllegalAccessException e) {
-            throw new XMLException(e.getMessage(), e);
-        } catch (InstantiationException e) {
-            throw new XMLException(e.getMessage(), e);
-        } catch (ClassNotFoundException e) {
-            throw new XMLException(e.getMessage(), e);
         } catch (LSException e) {
             throw new XMLException(e.getMessage(), e);
         } finally {
@@ -125,6 +115,33 @@ public final class DomUtils {
         }
     }
 
+    /**
+     * Gets a dom level 3 implementation. 
+     * @return Dom implementation.
+     * @throws ClassNotFoundException
+     * @throws InstantiationException
+     * @throws IllegalAccessException
+     */
+    public static DOMImplementationLS getDomImplementationLS() {
+        final String message = "Could not get Dom level 3 implementation";
+        try {
+            DOMImplementationRegistry registry = DOMImplementationRegistry
+                .newInstance();
+
+            DOMImplementationLS impl = (DOMImplementationLS) registry
+                .getDOMImplementation("LS");
+            return impl;
+        } catch (ClassCastException e) {
+            throw new RuntimeException(message, e);
+        } catch (ClassNotFoundException e) {
+            throw new RuntimeException(message, e);
+        } catch (InstantiationException e) {
+            throw new RuntimeException(message, e);
+        } catch (IllegalAccessException e) {
+            throw new RuntimeException(message, e);
+        }
+    }
+
     /**
      * Reads and validates a document against a schema.
      *