Java Code Examples for org.w3c.dom.Document#setDocumentURI()
The following examples show how to use
org.w3c.dom.Document#setDocumentURI() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DOMForest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 2
Source File: DOMForest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 3
Source File: DOMForest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 4
Source File: DOMForest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 5
Source File: DOMForest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 6
Source File: DOMForest.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 7
Source File: DOMForest.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 8
Source File: DOMForest.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 9
Source File: XmlUtils.java From ngAndroid with Apache License 2.0 | 5 votes |
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(); } }
Example 10
Source File: W3CDom.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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); }
Example 11
Source File: W3CDom.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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); }
Example 12
Source File: W3CDom.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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); }
Example 13
Source File: StaxUtils.java From cxf with Apache License 2.0 | 5 votes |
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; }
Example 14
Source File: StaxUtils.java From cxf with Apache License 2.0 | 5 votes |
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; }
Example 15
Source File: StaxUtils.java From cxf with Apache License 2.0 | 5 votes |
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; }
Example 16
Source File: XMLValidatingParserTest.java From teamengine with Apache License 2.0 | 5 votes |
/** * 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; }