Example usage for org.w3c.dom Element getBaseURI

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

Introduction

In this page you can find the example usage for org.w3c.dom Element 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/*ww  w  . jav a2s.com*/
 * @param outFile
 */
public static void writeDomToFile(Element 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:net.sourceforge.dita4publishers.impl.dita.DitaKeyDefinitionImpl.java

/**
 * @param document//  w  w  w  .j a  v a2  s.c  om
 * @param key 
 * @param keydefElem
 * @throws URISyntaxException 
 * @throws MalformedURLException 
 * @throws DitaApiException 
 */
public DitaKeyDefinitionImpl(Document document, String key, Element keydefElem) throws DitaApiException {
    this.keydefElem = keydefElem;
    String baseUriStr = keydefElem.getBaseURI();
    if (baseUriStr == null)
        throw new DitaApiException("keydef element has a null base URI.");
    try {
        this.baseUri = new URI(baseUriStr);
    } catch (URISyntaxException e) {
        throw new DitaApiException(e);
    }
    this.key = key;
    log.debug("DitaKeyDefinitionImpl(): key=" + key + ", bseUri=" + baseUri);
    if (keydefElem.hasAttribute(DitaUtil.DITA_HREF_ATTNAME)) {
        href = keydefElem.getAttribute(DitaUtil.DITA_HREF_ATTNAME);
        log.debug("DitaKeyDefinitionImpl(): href=\"" + href + "\"");
        try {
            this.absoluteUrl = new URL(baseUri.toURL(), href);
        } catch (MalformedURLException e) {
            throw new DitaApiException(e);
        }
        log.debug("DitaKeyDefinitionImpl(): absoluteUrl=\"" + absoluteUrl + "\"");
    }
    if (keydefElem.hasAttribute(DitaUtil.DITA_KEYREF_ATTNAME)) {
        keyref = keydefElem.getAttribute(DitaUtil.DITA_KEYREF_ATTNAME);
        log.debug("DitaKeyDefinitionImpl(): keyref=\"" + keyref + "\"");
    }
    if (keydefElem.hasAttribute(DitaUtil.DITA_FORMAT_ATTNAME)) {
        String format = keydefElem.getAttribute(DitaUtil.DITA_FORMAT_ATTNAME).toUpperCase();
        log.debug("DitaKeyDefinitionImpl(): format=\"" + format + "\"");
        try {
            this.format = DitaFormat.valueOf(format);
        } catch (Exception e) {
            this.format = DitaFormat.NONDITA;
        }

    }

    propsSpec = DitaUtil.constructPropsSpec(keydefElem);
}

From source file:org.dita2indesign.indesign.builders.InDesignFromDitaMapBuilder.java

/**
 * @param topicrefElem/*from w  w  w.  j  a v a2s . c  o m*/
 * @return
 * @throws Exception 
 */
private File getReferencedTopic(Element topicrefElem) throws Exception {
    if (topicrefCache.containsKey(topicrefElem)) {
        return topicrefCache.get(topicrefElem);
    }
    String hrefValue = topicrefElem.getAttribute("href");
    if (hrefValue == null || "".equals(hrefValue)) {
        throw new Exception("No href= value for topicref element.");
    }
    String baseUri = topicrefElem.getBaseURI();
    URL baseUrl = new URL(baseUri);
    URL url = new URL(baseUrl, hrefValue);
    File topicFile = new File(url.getFile());
    topicrefCache.put(topicrefElem, topicFile);
    return topicFile;
}