Code example for Source

Methods: getSystemId

0
     * @return  a DOMSource representing the XML document held by <tt>xsrc</tt> 
     *          The DOMSource's node will be either a VOElement or a VODocument 
     */ 
    public DOMSource transformToDOM( Source xsrc, boolean validate )
            throws SAXException, IOException { 
        String systemId = xsrc.getSystemId();
 
        /* If it's a DOM source already, no parse is necessary. */ 
        if ( xsrc instanceof DOMSource ) {
            Node node = ((DOMSource) xsrc).getNode();
 
            /* If it already has a VODocument DOM in it, return it unchanged. */ 
            if ( node instanceof VODocument ||
                 node.getOwnerDocument() instanceof VODocument ) {
                return (DOMSource) xsrc;
            } 
 
            /* Otherwise create a new VODocument DOM around it and return. */ 
            else { 
                Document baseDoc = node instanceof Document
                                 ? (Document) node
                                 : node.getOwnerDocument();
                VODocument vodoc = new VODocument( baseDoc, systemId,
                                                   isStrict() ); 
                vodoc.setStoragePolicy( getStoragePolicy() );
                return new DOMSource( vodoc.getDelegator( node ), systemId );
            } 
        } 
 
        /* Otherwise we're going to need to do a custom parse of it. */ 
        InputSource insource;
        XMLReader parser = null;
 
        /* If it's a SAX source, mine it for its input source and parsing 
         * engine. */ 
        if ( xsrc instanceof SAXSource ) {
            SAXSource saxsrc = (SAXSource) xsrc;
            insource = saxsrc.getInputSource();
            insource.setSystemId( systemId );
            parser = saxsrc.getXMLReader();
        } 
 
        /* If it's a StreamSource, turn it into an input source and create 
         * a default parsing engine. */ 
        else if ( xsrc instanceof StreamSource ) {
            StreamSource strmsrc = (StreamSource) xsrc;
            if ( strmsrc.getInputStream() != null ) {
                insource = new InputSource( strmsrc.getInputStream() );
                insource.setSystemId( systemId );
            } 
            else if ( strmsrc.getReader() != null ) {
                insource = new InputSource( strmsrc.getReader() );
                insource.setSystemId( systemId );
            } 
            else { 
                insource = new InputSource( strmsrc.getSystemId() );
            } 
        } 
 
        /* I don't think there's any other kind of source, but if there is 
         * one we'll have to transform it to DOM using brute force. */ 
        else { 
            try { 
                Node node = new SourceReader().getDOM( xsrc );
                return transformToDOM( new DOMSource( node, systemId ), 
                                       validate );
            } 
            catch ( TransformerException e ) {
                throw (SAXException) new SAXException( e.getMessage(), e )