public static String read ( Container container , String ddPath ) { if ( container == null || ddPath == null ) { return "" ; } Entry entry = container . getEntry ( ddPath ) ; if ( entry == null ) { throw new IllegalStateException ( ddPath ) ; } InputStream input ; try { input = entry . adapt ( InputStream . class ) ; } catch ( UnableToAdaptException e ) { throw new IllegalStateException ( e ) ; } try { SAXParserFactory parserFactory = SAXParserFactory . newInstance ( ) ; SAXParser parser = parserFactory . newSAXParser ( ) ; XMLReader xmlReader = parser . getXMLReader ( ) ; xmlReader . setEntityResolver ( new EntityResolver ( ) { @ Override public InputSource resolveEntity ( String arg0 , String arg1 ) throws SAXException , IOException { return new InputSource ( new ByteArrayInputStream ( new byte [ 0 ] ) ) ; } } ) ; Source saxSource = new SAXSource ( xmlReader , new InputSource ( input ) ) ; TransformerFactory transformerFactory = TransformerFactory . newInstance ( ) ; Transformer transformer = transformerFactory . newTransformer ( ) ; StringWriter writer = new StringWriter ( ) ; Result result = new StreamResult ( writer ) ; transformer . transform ( saxSource , result ) ; return writer . toString ( ) ; } catch ( ParserConfigurationException e ) { throw new IllegalStateException ( e ) ; } catch ( SAXException e ) { throw new IllegalStateException ( e ) ; } catch ( TransformerConfigurationException e ) { throw new IllegalStateException ( e ) ; } catch ( TransformerException e ) { throw new IllegalStateException ( e ) ; } finally { try { input . close ( ) ; } catch ( IOException e ) { } } }
Read a deployment descriptor into a string .