Author: scheu Date: Wed Jun 17 16:43:23 2009 New Revision: 785712 URL: http://svn.apache.org/viewvc?rev=785712&view=rev Log: Contributor: Rich Scheuerle Summary: Added some additional logic to tolerate missing DTD text if XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES is specified.
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java?rev=785712&r1=785711&r2=785712&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java Wed Jun 17 16:43:23 2009 @@ -35,6 +35,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; @@ -498,9 +499,42 @@ if (!parser.hasText()) { return null; } - lastNode = omfactory.createOMDocType(document, parser.getText()); + String dtdText = getDTDText(); + lastNode = omfactory.createOMDocType(document, dtdText); return lastNode; } + + /** + * The getText() method for a DOCTYPE returns the + * subset of the DOCTYPE (not the direct infoset). + * This may force the parser to get information from + * the network. + * @return doctype subset + * @throws OMException + */ + private String getDTDText() throws OMException { + String text = null; + try { + text = parser.getText(); + } catch (RuntimeException e) { + // Woodstox (and perhaps other parsers) + // attempts to load the external subset even if + // external enties is false. So ignore this error + // if external entity support is explicitly disabled. + Boolean b = (Boolean) parser.getProperty( + XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES); + if (b == null || b == Boolean.TRUE) { + throw e; + } + if (log.isDebugEnabled()) { + log.debug("An exception occurred while calling getText() for a DOCTYPE. " + + "The exception is ignored because external " + + "entites support is disabled. " + + "The ignored exception is " + e); + } + } + return text; + } /** * Method createPI.