Code example for URI

Methods: toString, toURL

0
        document = prevDoc;
        serializer.createContainerElements = createContainerElements;
    } 
 
    private org.exist.memtree.DocumentImpl parseExternal(URI externalUri) throws IOException, ResourceError, PermissionDeniedException, ParserConfigurationException, SAXException {
        URLConnection con = externalUri.toURL().openConnection();
        if(con instanceof HttpURLConnection)
        { 
            HttpURLConnection httpConnection = (HttpURLConnection)con;
            if(httpConnection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND)
            { 
                // Special case: '404' 
                throw new ResourceError("XInclude: no document found at URI: " + externalUri.toString());
            } 
            else if(httpConnection.getResponseCode() != HttpURLConnection.HTTP_OK)
            { 
                //TODO : return another type 
                throw new PermissionDeniedException("Server returned code " + httpConnection.getResponseCode());
            } 
        } 
 
        // we use eXist's in-memory DOM implementation 
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        InputSource src = new InputSource(con.getInputStream());
        SAXParser parser = factory.newSAXParser();
        XMLReader reader = parser.getXMLReader();
        SAXAdapter adapter = new SAXAdapter();
        reader.setContentHandler(adapter);
        reader.parse(src);
        org.exist.memtree.DocumentImpl doc =
                (org.exist.memtree.DocumentImpl)adapter.getDocument();
        doc.setDocumentURI(externalUri.toString());
        return doc;
    } 
 
    /** 
	 * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)