Example usage for org.w3c.dom Document getBaseURI

List of usage examples for org.w3c.dom Document getBaseURI

Introduction

In this page you can find the example usage for org.w3c.dom Document getBaseURI.

Prototype

public String getBaseURI();

Source Link

Document

The absolute base URI of this node or null if the implementation wasn't able to obtain an absolute URI.

Usage

From source file:Main.java

/**
 * @param dom/*from   w w  w.j ava 2 s  .  c o m*/
 * @param outFile
 */
public static void writeDomToFile(Document dom, File outFile) {
    try {
        Transformer transformer = transFactory.newTransformer();
        DOMSource source = new DOMSource(dom);
        StreamResult result;

        result = new StreamResult(
                new OutputStreamWriter(new FileOutputStream(outFile), System.getProperty("file.encoding")));
        transformer.transform(source, result);
    } catch (Exception e) {
        throw new RuntimeException(
                "Could not write dom tree '" + dom.getBaseURI() + "' to file '" + outFile.getName() + "'!", e);
    }
}

From source file:Main.java

/**
 * @param dom//from w  w  w  .  j av  a2 s. c o  m
 * @param outFile
 */
public static void writeDomToFile(Document dom, File outFile) {
    try {
        TransformerFactory transFact = TransformerFactory.newInstance();
        Transformer transformer = transFact.newTransformer();
        DOMSource source = new DOMSource(dom);
        StreamResult result;

        result = new StreamResult(
                new OutputStreamWriter(new FileOutputStream(outFile), System.getProperty("file.encoding")));
        transformer.transform(source, result);
    } catch (Exception e) {
        throw new RuntimeException(
                "Could not write dom tree '" + dom.getBaseURI() + "' to file '" + outFile.getName() + "'!", e);
    }
}

From source file:Main.java

public static Document transform(Document dom, Document xslt) {
    try {/*from   w  ww  .  ja v  a2 s  . c  om*/
        DOMSource xsltSource = new DOMSource(xslt);
        Transformer transformer = transFactory.newTransformer(xsltSource);
        DOMSource source = new DOMSource(dom);
        Document out = newDocument();
        DOMResult result = new DOMResult(out);
        transformer.transform(source, result);
        return out;
    } catch (Exception e) {
        throw new RuntimeException("Could not write dom tree '" + dom.getBaseURI() + "'!", e);
    }
}

From source file:Main.java

public static void writeDomToFile(Document dom, File outFile, Properties outputProperties) {
    //        try {
    //            StringWriter ret = new StringWriter();
    //            TransformerFactory transFact = TransformerFactory.newInstance();
    ////                transFact.setAttribute("indent-number", 2);
    //            Transformer transformer = transFact.newTransformer();
    //            if (outputProperties != null) transformer.setOutputProperties(outputProperties);
    //            DOMSource source = new DOMSource(dom);
    //            StreamResult result = new StreamResult(ret);

    try {/*from w  w w  .j a v  a2 s  .  c  o  m*/
        TransformerFactory transFact = TransformerFactory.newInstance();
        Transformer transformer = transFact.newTransformer();
        if (outputProperties != null)
            transformer.setOutputProperties(outputProperties);
        DOMSource source = new DOMSource(dom);
        StreamResult result;

        result = new StreamResult(
                new OutputStreamWriter(new FileOutputStream(outFile), System.getProperty("file.encoding")));
        transformer.transform(source, result);
    } catch (Exception e) {
        throw new RuntimeException(
                "Could not write dom tree '" + dom.getBaseURI() + "' to file '" + outFile.getName() + "'!", e);
    }
}

From source file:org.pentaho.di.trans.steps.webservices.wsdl.Wsdl.java

private Definition readWsdl(WSDLReader wsdlReader, String uri, String username, String password)
        throws WSDLException, KettleException, AuthenticationException {

    try {// w  ww.ja va2  s.  co m
        HTTPProtocol http = new HTTPProtocol();
        Document doc = XMLHandler.loadXMLString(http.get(wsdlURI.toString(), username, password), true, false);
        if (doc != null) {
            return (wsdlReader.readWSDL(doc.getBaseURI(), doc));
        } else {
            throw new KettleException("Unable to get document.");
        }
    } catch (MalformedURLException mue) {
        throw new KettleException(mue);
    } catch (AuthenticationException ae) {
        // re-throw this. If not IOException seems to catch it
        throw ae;
    } catch (IOException ioe) {
        throw new KettleException(ioe);
    }
}

From source file:org.callimachusproject.xproc.DecodeTextStep.java

public void run() throws SaxonApiException {
    try {/*  w w w.  j a v  a  2  s . com*/
        while (source.moreDocuments()) {
            String text = decodeText(source.read());

            Document doc = DocumentFactory.newInstance().newDocument();
            doc.setDocumentURI(doc.getBaseURI());
            Element data = doc.createElementNS(XPROC_STEP, DATA);
            data.setAttribute("content-type", contentType);
            data.appendChild(doc.createTextNode(text));
            doc.appendChild(data);
            result.write(runtime.getProcessor().newDocumentBuilder().wrap(doc));
        }
    } catch (ParserConfigurationException e) {
        throw XProcException.dynamicError(30, step.getNode(), e, e.getMessage());
    } catch (UnsupportedEncodingException uee) {
        throw XProcException.stepError(10, uee);
    } catch (DecoderException e) {
        throw XProcException.dynamicError(30, step.getNode(), e, e.getMessage());
    }
}

From source file:softNet.SoftNet.java

public SoftNet(Document doc, String[] nodeFilter, String[] edgeFilter) {
    /**/* w  w w  .j a  v a 2  s .c om*/
     * This constructor reads from GDN XML file and creates SoftNet structure
     * 
     * SoftNet is a structure similar to GND
     * It contains less information than GDN file
     * 
            
     * 
     * @param doc
     *            - GDN XML file this method reads from
     */

    this.name = doc.getBaseURI();
    net = new DirectedSparseGraph<SNNode, SNLink>();
    nodeMap = new HashMap<String, SNNode>();

    System.out.println("usao sam u metod za softnet");

    getEdges(doc, edgeFilter);
    getNodes(doc, nodeFilter);

}