protected void setupProperties ( XMLInputFactory factory ) { factory . setProperty ( XMLInputFactory . IS_NAMESPACE_AWARE , Boolean . TRUE ) ; factory . setProperty ( XMLInputFactory . IS_COALESCING , Boolean . TRUE ) ; factory . setProperty ( XMLInputFactory . SUPPORT_DTD , Boolean . TRUE ) ; try { factory . setProperty ( XMLInputFactory . IS_VALIDATING , Boolean . FALSE ) ; } catch ( IllegalArgumentException e ) { ; // we can live with that } try { factory . setProperty ( XMLInputFactory . IS_SUPPORTING_EXTERNAL_ENTITIES , Boolean . TRUE ) ; } catch ( IllegalArgumentException e ) { ; // we can live with that } factory . setXMLResolver ( new XMLResolver ( ) { @ Override public InputStream resolveEntity ( String publicID , String systemID , String baseURI , String namespace ) { return new InputStream ( ) { @ Override public int read ( ) { return - 1 ; } } ; } } ) ; String factoryName = factory . getClass ( ) . getName ( ) ; if ( factoryName . equals ( "com.ctc.wstx.stax.WstxInputFactory" ) ) { try { // it's safer to disable woodstox lazy parsing, in particular with DTDs // see http://woodstox.codehaus.org/ConfiguringStreamReaders // see com.ctc.wstx.api.WstxInputProperties String P_LAZY_PARSING = "com.ctc.wstx.lazyParsing" ; factory . setProperty ( P_LAZY_PARSING , Boolean . FALSE ) ; } catch ( IllegalArgumentException e ) { ; // shouldn't happen, but we can live with that } try { // enable/disable DTD caching (wstx default is to enable it) String P_CACHE_DTDS = "com.ctc.wstx.cacheDTDs" ; factory . setProperty ( P_CACHE_DTDS , Boolean . valueOf ( CACHE_DTDS ) ) ; } catch ( IllegalArgumentException e ) { ; // shouldn't happen, but we can live with that } // } else if (factory.isPropertySupported("report-cdata-event")) {} } else if ( factoryName . equals ( "com.sun.xml.stream.ZephyrParserFactory" ) ) { try { // workaround to tell sjsxp to not ignore CDATA events // see sjsxp-1_0/docs/ReleaseNotes.html String P_REPORT_CDATA = "report-cdata-event" ; // String P_REPORT_CDATA = "http://java.sun.com/xml/stream/properties/report-cdata-event"; factory . setProperty ( P_REPORT_CDATA , Boolean . TRUE ) ; } catch ( IllegalArgumentException e ) { ; // shouldn't happen, but we can live with that } } }
Initializes default parser properties if any .