From 6f2b4760a460ad3eeedbd5b475d7ecbfdc77179c Mon Sep 17 00:00:00 2001 From: rudolf Date: Mon, 26 Apr 2004 12:47:06 +0000 Subject: =?UTF-8?q?Debug=20logging=20des=20Dokuments=20im=20Falle=20einer?= =?UTF-8?q?=20SAXException=20wurde=20hinzugef=C3=BCgt=20(RSCH)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@106 d688527b-c9ab-4aba-bd8d-4036d912da1d --- .../src/at/gv/egovernment/moa/util/DOMUtils.java | 82 ++++++++++++++-------- 1 file changed, 52 insertions(+), 30 deletions(-) (limited to 'common/src/at/gv/egovernment/moa/util') diff --git a/common/src/at/gv/egovernment/moa/util/DOMUtils.java b/common/src/at/gv/egovernment/moa/util/DOMUtils.java index 8e6394445..f44804927 100644 --- a/common/src/at/gv/egovernment/moa/util/DOMUtils.java +++ b/common/src/at/gv/egovernment/moa/util/DOMUtils.java @@ -41,6 +41,8 @@ import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import at.gv.egovernment.moa.logging.Logger; + /** * Various utility functions for handling XML DOM trees. * @@ -154,10 +156,22 @@ public class DOMUtils { String externalNoNamespaceSchemaLocation, EntityResolver entityResolver, ErrorHandler errorHandler) - throws SAXException, IOException, ParserConfigurationException { + throws SAXException, IOException, ParserConfigurationException { DOMParser parser; + + + //if Debug is enabled make a copy of inputStream to enable debug output in case of SAXException + byte buffer [] = null; + ByteArrayInputStream baStream = null; + if(true == Logger.isDebugEnabled()) { + int len = inputStream.available(); + buffer = new byte[len]; + inputStream.read(buffer); + baStream = new ByteArrayInputStream(buffer); + } + // create the DOM parser if (symbolTable != null) { parser = new DOMParser(symbolTable, grammarPool); @@ -166,36 +180,44 @@ public class DOMUtils { } // set parser features and properties - parser.setFeature(NAMESPACES_FEATURE, true); - parser.setFeature(VALIDATION_FEATURE, validating); - parser.setFeature(SCHEMA_VALIDATION_FEATURE, validating); - parser.setFeature(NORMALIZED_VALUE_FEATURE, false); - parser.setFeature(INCLUDE_IGNORABLE_WHITESPACE_FEATURE, true); - parser.setFeature(CREATE_ENTITY_REF_NODES_FEATURE, false); - - if (validating) { - if (externalSchemaLocations != null) { - parser.setProperty( - EXTERNAL_SCHEMA_LOCATION_PROPERTY, - externalSchemaLocations); - } - if (externalNoNamespaceSchemaLocation != null) { - parser.setProperty( - EXTERNAL_NO_NAMESPACE_SCHEMA_LOCATION_PROPERTY, - externalNoNamespaceSchemaLocation); - } - } - - // set entity resolver and error handler - if (entityResolver != null) { - parser.setEntityResolver(entityResolver); + try { + parser.setFeature(NAMESPACES_FEATURE, true); + parser.setFeature(VALIDATION_FEATURE, validating); + parser.setFeature(SCHEMA_VALIDATION_FEATURE, validating); + parser.setFeature(NORMALIZED_VALUE_FEATURE, false); + parser.setFeature(INCLUDE_IGNORABLE_WHITESPACE_FEATURE, true); + parser.setFeature(CREATE_ENTITY_REF_NODES_FEATURE, false); + + if (validating) { + if (externalSchemaLocations != null) { + parser.setProperty( + EXTERNAL_SCHEMA_LOCATION_PROPERTY, + externalSchemaLocations); + } + if (externalNoNamespaceSchemaLocation != null) { + parser.setProperty( + EXTERNAL_NO_NAMESPACE_SCHEMA_LOCATION_PROPERTY, + externalNoNamespaceSchemaLocation); + } + } + + // set entity resolver and error handler + if (entityResolver != null) { + parser.setEntityResolver(entityResolver); + } + if (errorHandler != null) { + parser.setErrorHandler(errorHandler); + } + + // parse the document and return it + parser.parse(new InputSource(baStream)); + } catch(SAXException e) { + if(true == Logger.isDebugEnabled() && null != buffer) { + String xmlContent = new String(buffer); + Logger.debug("SAXException in:\n" + xmlContent); + throw(e); + } } - if (errorHandler != null) { - parser.setErrorHandler(errorHandler); - } - - // parse the document and return it - parser.parse(new InputSource(inputStream)); return parser.getDocument(); } -- cgit v1.2.3