- throw new XMLException(e.getMessage(), e);
- } catch (LSException e) {
- throw new XMLException(e.getMessage(), e);
- } finally {
- try {
- aIs.close();
- } catch (Exception e) {
- LOG.log(Level.WARNING, "Error closing XML file", e);
- }
- }
- }
-
- /**
- * Reads and validates a document against a schema.
- *
- * @param aIs
- * Input stream.
- * @param aSchema
- * Schema.
- *
- * @return Parsed and validated document.
- *
- */
- public static Document readAndValidate(InputStream aIs, InputStream aSchema)
- throws XMLException {
- try {
- Document doc = read(aIs);
- final Schema schema = SchemaFactory.newInstance(
- XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(
- new StreamSource(aSchema));
- Validator validator = schema.newValidator();
- validator.validate(new DOMSource(doc));
-
- return doc;
- } catch (SAXException e) {
- throw new XMLException(e.getMessage(), e);
- } catch (IOException e) {
- throw new XMLException(e.getMessage(), e);
- } finally {
- try {
- aSchema.close();
- } catch (Exception e) {
- LOG.log(Level.WARNING, "Error closing schema", e);
- }
-
- try {
- aIs.close();
- } catch (Exception e) {
- LOG.log(Level.WARNING, "Error closing XML file", e);
- }
- }
- }
-
- /**
- * Serializes an XML document to a stream.
- *
- * @param aDocument
- * Document to serialize.
- * @param aOs
- * Output stream.
- *
- */
- public static void serialize(Document aDocument, OutputStream aOs)
- throws IOException {
- try {
- TransformerFactory factory = TransformerFactory.newInstance();
- Transformer identityTransform = factory.newTransformer();
- DOMSource source = new DOMSource(aDocument);
- StreamResult result = new StreamResult(aOs);
- identityTransform.transform(source, result);
- } catch (TransformerException e) {
- throw new IOException(e.getMessage(), e);
+ throw new RuntimeException(message, e);
+ } catch (InstantiationException e) {
+ throw new RuntimeException(message, e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(message, e);