private Document loadDocument ( String file ) { Document doc = null ; URL url = null ; File f = new File ( file ) ; if ( f . exists ( ) ) { try { url = f . toURI ( ) . toURL ( ) ; } catch ( MalformedURLException e ) { throw new ConfigurationException ( "Unable to load " + file , e ) ; } } if ( url == null ) { url = ClassLoader . getSystemResource ( file ) ; } InputStream is = null ; if ( url == null ) { if ( errorIfMissing ) { throw new ConfigurationException ( "Could not open files of the name " + file ) ; } else { LOG . info ( "Unable to locate configuration files of the name " + file + ", skipping" ) ; return doc ; } } try { is = url . openStream ( ) ; InputSource in = new InputSource ( is ) ; in . setSystemId ( url . toString ( ) ) ; doc = DomHelper . parse ( in , dtdMappings ) ; } catch ( Exception e ) { throw new ConfigurationException ( "Unable to load " + file , e ) ; } finally { try { is . close ( ) ; } catch ( IOException e ) { LOG . error ( "Unable to close input stream" , e ) ; } } if ( doc != null ) { LOG . debug ( "Wallmod configuration parsed" ) ; } return doc ; }
Load the XML configuration on memory as a DOM structure with SAX . Additional information about elements location is added . Non valid DTDs or XML structures are detected .