org.w3c.dom.Document#setDocumentURI ( )源码实例Demo

下面列出了org.w3c.dom.Document#setDocumentURI ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: TencentKona-8   文件: DOMForest.java
/**
 * Parses the given document and add it to the DOM forest.
 *
 * @return null if there was a parse error. otherwise non-null.
 */
private @NotNull Document parse(String systemId, InputSource inputSource, boolean root) throws SAXException, IOException{
    Document dom = documentBuilder.newDocument();

    systemId = normalizeSystemId(systemId);

    // put into the map before growing a tree, to
    // prevent recursive reference from causing infinite loop.
    core.put(systemId, dom);

    dom.setDocumentURI(systemId);
    if (root)
        rootDocuments.add(systemId);

    try {
        XMLReader reader = createReader(dom);

        InputStream is = null;
        if(inputSource.getByteStream() == null){
            inputSource = entityResolver.resolveEntity(null, systemId);
        }
        reader.parse(inputSource);
        Element doc = dom.getDocumentElement();
        if (doc == null) {
            return null;
        }
        NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
        for (int i = 0; i < schemas.getLength(); i++) {
            inlinedSchemaElements.add((Element) schemas.item(i));
        }
    } catch (ParserConfigurationException e) {
        errorReceiver.error(e);
        throw new SAXException(e.getMessage());
    }
    resolvedCache.put(systemId, dom.getDocumentURI());
    return dom;
}
 
源代码2 项目: jdk8u60   文件: DOMForest.java
/**
 * Parses the given document and add it to the DOM forest.
 *
 * @return null if there was a parse error. otherwise non-null.
 */
private @NotNull Document parse(String systemId, InputSource inputSource, boolean root) throws SAXException, IOException{
    Document dom = documentBuilder.newDocument();

    systemId = normalizeSystemId(systemId);

    // put into the map before growing a tree, to
    // prevent recursive reference from causing infinite loop.
    core.put(systemId, dom);

    dom.setDocumentURI(systemId);
    if (root)
        rootDocuments.add(systemId);

    try {
        XMLReader reader = createReader(dom);

        InputStream is = null;
        if(inputSource.getByteStream() == null){
            inputSource = entityResolver.resolveEntity(null, systemId);
        }
        reader.parse(inputSource);
        Element doc = dom.getDocumentElement();
        if (doc == null) {
            return null;
        }
        NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
        for (int i = 0; i < schemas.getLength(); i++) {
            inlinedSchemaElements.add((Element) schemas.item(i));
        }
    } catch (ParserConfigurationException e) {
        errorReceiver.error(e);
        throw new SAXException(e.getMessage());
    }
    resolvedCache.put(systemId, dom.getDocumentURI());
    return dom;
}
 
源代码3 项目: openjdk-jdk8u   文件: DOMForest.java
/**
 * Parses the given document and add it to the DOM forest.
 *
 * @return null if there was a parse error. otherwise non-null.
 */
private @NotNull Document parse(String systemId, InputSource inputSource, boolean root) throws SAXException, IOException{
    Document dom = documentBuilder.newDocument();

    systemId = normalizeSystemId(systemId);

    // put into the map before growing a tree, to
    // prevent recursive reference from causing infinite loop.
    core.put(systemId, dom);

    dom.setDocumentURI(systemId);
    if (root)
        rootDocuments.add(systemId);

    try {
        XMLReader reader = createReader(dom);

        InputStream is = null;
        if(inputSource.getByteStream() == null){
            inputSource = entityResolver.resolveEntity(null, systemId);
        }
        reader.parse(inputSource);
        Element doc = dom.getDocumentElement();
        if (doc == null) {
            return null;
        }
        NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
        for (int i = 0; i < schemas.getLength(); i++) {
            inlinedSchemaElements.add((Element) schemas.item(i));
        }
    } catch (ParserConfigurationException e) {
        errorReceiver.error(e);
        throw new SAXException(e.getMessage());
    }
    resolvedCache.put(systemId, dom.getDocumentURI());
    return dom;
}
 
源代码4 项目: openjdk-jdk8u-backup   文件: DOMForest.java
/**
 * Parses the given document and add it to the DOM forest.
 *
 * @return null if there was a parse error. otherwise non-null.
 */
private @NotNull Document parse(String systemId, InputSource inputSource, boolean root) throws SAXException, IOException{
    Document dom = documentBuilder.newDocument();

    systemId = normalizeSystemId(systemId);

    // put into the map before growing a tree, to
    // prevent recursive reference from causing infinite loop.
    core.put(systemId, dom);

    dom.setDocumentURI(systemId);
    if (root)
        rootDocuments.add(systemId);

    try {
        XMLReader reader = createReader(dom);

        InputStream is = null;
        if(inputSource.getByteStream() == null){
            inputSource = entityResolver.resolveEntity(null, systemId);
        }
        reader.parse(inputSource);
        Element doc = dom.getDocumentElement();
        if (doc == null) {
            return null;
        }
        NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
        for (int i = 0; i < schemas.getLength(); i++) {
            inlinedSchemaElements.add((Element) schemas.item(i));
        }
    } catch (ParserConfigurationException e) {
        errorReceiver.error(e);
        throw new SAXException(e.getMessage());
    }
    resolvedCache.put(systemId, dom.getDocumentURI());
    return dom;
}
 
源代码5 项目: openjdk-jdk9   文件: DOMForest.java
/**
 * Parses the given document and add it to the DOM forest.
 *
 * @return null if there was a parse error. otherwise non-null.
 */
private @NotNull Document parse(String systemId, InputSource inputSource, boolean root) throws SAXException, IOException{
    Document dom = documentBuilder.newDocument();

    systemId = normalizeSystemId(systemId);

    // put into the map before growing a tree, to
    // prevent recursive reference from causing infinite loop.
    core.put(systemId, dom);

    dom.setDocumentURI(systemId);
    if (root)
        rootDocuments.add(systemId);

    try {
        XMLReader reader = createReader(dom);

        InputStream is = null;
        if(inputSource.getByteStream() == null){
            inputSource = entityResolver.resolveEntity(null, systemId);
        }
        reader.parse(inputSource);
        Element doc = dom.getDocumentElement();
        if (doc == null) {
            return null;
        }
        NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
        for (int i = 0; i < schemas.getLength(); i++) {
            inlinedSchemaElements.add((Element) schemas.item(i));
        }
    } catch (ParserConfigurationException e) {
        errorReceiver.error(e);
        throw new SAXException(e.getMessage());
    }
    resolvedCache.put(systemId, dom.getDocumentURI());
    return dom;
}
 
源代码6 项目: hottub   文件: DOMForest.java
/**
 * Parses the given document and add it to the DOM forest.
 *
 * @return null if there was a parse error. otherwise non-null.
 */
private @NotNull Document parse(String systemId, InputSource inputSource, boolean root) throws SAXException, IOException{
    Document dom = documentBuilder.newDocument();

    systemId = normalizeSystemId(systemId);

    // put into the map before growing a tree, to
    // prevent recursive reference from causing infinite loop.
    core.put(systemId, dom);

    dom.setDocumentURI(systemId);
    if (root)
        rootDocuments.add(systemId);

    try {
        XMLReader reader = createReader(dom);

        InputStream is = null;
        if(inputSource.getByteStream() == null){
            inputSource = entityResolver.resolveEntity(null, systemId);
        }
        reader.parse(inputSource);
        Element doc = dom.getDocumentElement();
        if (doc == null) {
            return null;
        }
        NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
        for (int i = 0; i < schemas.getLength(); i++) {
            inlinedSchemaElements.add((Element) schemas.item(i));
        }
    } catch (ParserConfigurationException e) {
        errorReceiver.error(e);
        throw new SAXException(e.getMessage());
    }
    resolvedCache.put(systemId, dom.getDocumentURI());
    return dom;
}
 
源代码7 项目: openjdk-8-source   文件: DOMForest.java
/**
 * Parses the given document and add it to the DOM forest.
 *
 * @return null if there was a parse error. otherwise non-null.
 */
private @NotNull Document parse(String systemId, InputSource inputSource, boolean root) throws SAXException, IOException{
    Document dom = documentBuilder.newDocument();

    systemId = normalizeSystemId(systemId);

    // put into the map before growing a tree, to
    // prevent recursive reference from causing infinite loop.
    core.put(systemId, dom);

    dom.setDocumentURI(systemId);
    if (root)
        rootDocuments.add(systemId);

    try {
        XMLReader reader = createReader(dom);

        InputStream is = null;
        if(inputSource.getByteStream() == null){
            inputSource = entityResolver.resolveEntity(null, systemId);
        }
        reader.parse(inputSource);
        Element doc = dom.getDocumentElement();
        if (doc == null) {
            return null;
        }
        NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
        for (int i = 0; i < schemas.getLength(); i++) {
            inlinedSchemaElements.add((Element) schemas.item(i));
        }
    } catch (ParserConfigurationException e) {
        errorReceiver.error(e);
        throw new SAXException(e.getMessage());
    }
    resolvedCache.put(systemId, dom.getDocumentURI());
    return dom;
}
 
源代码8 项目: openjdk-8   文件: DOMForest.java
/**
 * Parses the given document and add it to the DOM forest.
 *
 * @return null if there was a parse error. otherwise non-null.
 */
private @NotNull Document parse(String systemId, InputSource inputSource, boolean root) throws SAXException, IOException{
    Document dom = documentBuilder.newDocument();

    systemId = normalizeSystemId(systemId);

    // put into the map before growing a tree, to
    // prevent recursive reference from causing infinite loop.
    core.put(systemId, dom);

    dom.setDocumentURI(systemId);
    if (root)
        rootDocuments.add(systemId);

    try {
        XMLReader reader = createReader(dom);

        InputStream is = null;
        if(inputSource.getByteStream() == null){
            inputSource = entityResolver.resolveEntity(null, systemId);
        }
        reader.parse(inputSource);
        Element doc = dom.getDocumentElement();
        if (doc == null) {
            return null;
        }
        NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
        for (int i = 0; i < schemas.getLength(); i++) {
            inlinedSchemaElements.add((Element) schemas.item(i));
        }
    } catch (ParserConfigurationException e) {
        errorReceiver.error(e);
        throw new SAXException(e.getMessage());
    }
    resolvedCache.put(systemId, dom.getDocumentURI());
    return dom;
}
 
源代码9 项目: ngAndroid   文件: XmlUtils.java
public Option<Document> getDocumentFromFile(File file){
    try {
        Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file);
        document.setDocumentURI(file.getAbsolutePath());
        return Option.of(document);
    } catch (Exception e) {
        messageUtils.error(Option.<Element>absent(), e.getMessage());
        return Option.absent();
    }
}
 
源代码10 项目: astor   文件: W3CDom.java
/**
 * Converts a jsoup document into the provided W3C Document. If required, you can set options on the output document
 * before converting.
 * @param in jsoup doc
 * @param out w3c doc
 * @see org.jsoup.helper.W3CDom#fromJsoup(org.jsoup.nodes.Document)
 */
public void convert(org.jsoup.nodes.Document in, Document out) {
    if (!StringUtil.isBlank(in.location()))
        out.setDocumentURI(in.location());

    org.jsoup.nodes.Element rootEl = in.child(0); // skip the #root node
    NodeTraversor traversor = new NodeTraversor(new W3CBuilder(out));
    traversor.traverse(rootEl);
}
 
源代码11 项目: astor   文件: W3CDom.java
/**
 * Converts a jsoup document into the provided W3C Document. If required, you can set options on the output document
 * before converting.
 * @param in jsoup doc
 * @param out w3c doc
 * @see org.jsoup.helper.W3CDom#fromJsoup(org.jsoup.nodes.Document)
 */
public void convert(org.jsoup.nodes.Document in, Document out) {
    if (!StringUtil.isBlank(in.location()))
        out.setDocumentURI(in.location());

    org.jsoup.nodes.Element rootEl = in.child(0); // skip the #root node
    NodeTraversor.traverse(new W3CBuilder(out), rootEl);
}
 
源代码12 项目: astor   文件: W3CDom.java
/**
 * Converts a jsoup document into the provided W3C Document. If required, you can set options on the output document
 * before converting.
 * @param in jsoup doc
 * @param out w3c doc
 * @see org.jsoup.helper.W3CDom#fromJsoup(org.jsoup.nodes.Document)
 */
public void convert(org.jsoup.nodes.Document in, Document out) {
    if (!StringUtil.isBlank(in.location()))
        out.setDocumentURI(in.location());

    org.jsoup.nodes.Element rootEl = in.child(0); // skip the #root node
    NodeTraversor.traverse(new W3CBuilder(out), rootEl);
}
 
源代码13 项目: cxf   文件: StaxUtils.java
public static Document copy(Document doc)
    throws XMLStreamException, ParserConfigurationException {

    XMLStreamReader reader = createXMLStreamReader(doc);
    W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
    copy(reader, writer);
    Document d = writer.getDocument();
    try {
        d.setDocumentURI(doc.getDocumentURI());
    } catch (Exception ex) {
        //ignore - probably not DOM level 3
    }
    return d;
}
 
源代码14 项目: cxf   文件: StaxUtils.java
public static Document read(XMLStreamReader reader, boolean recordLoc) throws XMLStreamException {
    Document doc = DOMUtils.createDocument();
    if (reader.getLocation().getSystemId() != null) {
        try {
            doc.setDocumentURI(reader.getLocation().getSystemId());
        } catch (Exception e) {
            //ignore - probably not DOM level 3
        }
    }
    readDocElements(doc, doc, reader, true, recordLoc);
    return doc;
}
 
源代码15 项目: cxf   文件: StaxUtils.java
public static Document read(DocumentBuilder builder, XMLStreamReader reader, boolean repairing)
    throws XMLStreamException {

    Document doc = builder == null ? DOMUtils.createDocument() : builder.newDocument();
    if (reader.getLocation().getSystemId() != null) {
        try {
            doc.setDocumentURI(reader.getLocation().getSystemId());
        } catch (Exception e) {
            //ignore - probably not DOM level 3
        }
    }
    readDocElements(doc, reader, repairing);
    return doc;
}
 
源代码16 项目: teamengine   文件: XMLValidatingParserTest.java
/**
 * Parses an XML Document from a classpath resource.
 * 
 * @param resourcePath relative to the current class
 * @return never null
 */
private Document parseResourceDocument(final String resourcePath)
		throws SAXException, IOException {
	final URL url = getClass().getResource(resourcePath);
	final Document doc = docBuilder.parse(url.toString());
	doc.setDocumentURI(url.toString());
	return doc;
}