X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxml%2FDomUtils.java;h=a0a118c1062cd82e8fd0aac29bb84fb01a371fb3;hb=df850821cf26ca07ef2474d4d2cabb61e9104291;hp=44a9f8ee8268a4cb946d7bc6adb7478e21a84f34;hpb=ed3ce3eb0c855255c91e974f07aef94f38009d70;p=utils diff --git a/support/general/src/main/java/org/wamblee/xml/DomUtils.java b/support/general/src/main/java/org/wamblee/xml/DomUtils.java index 44a9f8ee..a0a118c1 100644 --- a/support/general/src/main/java/org/wamblee/xml/DomUtils.java +++ b/support/general/src/main/java/org/wamblee/xml/DomUtils.java @@ -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. *