public InputSource resolveEntity ( String publicId , String systemId ) { String resolved = null ; if ( systemId != null && systemMap . containsKey ( systemId ) ) { resolved = ( String ) systemMap . get ( systemId ) ; } else if ( publicId != null && publicMap . containsKey ( publicId ) ) { resolved = ( String ) publicMap . get ( publicId ) ; } if ( resolved != null ) { try { InputSource iSource = new InputSource ( resolved ) ; iSource . setPublicId ( publicId ) ; // Ideally this method would not attempt to open the // InputStream, but there is a bug (in Xerces, at least) // that causes the parser to mistakenly open the wrong // system identifier if the returned InputSource does // not have a byteStream. // // It could be argued that we still shouldn't do this here, // but since the purpose of calling the entityResolver is // almost certainly to open the input stream, it seems to // do little harm. // URL url = new URL ( resolved ) ; InputStream iStream = url . openStream ( ) ; iSource . setByteStream ( iStream ) ; return iSource ; } catch ( Exception e ) { // FIXME: silently fail? return null ; } } return null ; }
SAX resolveEntity API .