Java Code Examples for org.w3c.dom.Document#getDocumentURI()

The following examples show how to use org.w3c.dom.Document#getDocumentURI() . 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: DynamicRemoteSetExportFormat.java    From IrScrutinizer with GNU General Public License v3.0 6 votes vote down vote up
private static Map<String, IExporterFactory> parseExportFormatsFile(GuiUtils guiUtils, File file) throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(false);
    factory.setNamespaceAware(true);
    factory.setXIncludeAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(file);

    Map<String, IExporterFactory> result = new HashMap<>(32);
    NodeList nl = doc.getElementsByTagNameNS(exportFormatNamespace, "exportformat");
    String documentURI = doc.getDocumentURI();
    for (int i = 0; i < nl.getLength(); i++) {
        final Element el = (Element) nl.item(i);
        final ICommandExporter ef = (el.getAttribute("multiSignal").equals("true"))
                ? new DynamicRemoteSetExportFormat(el, documentURI)
                : new DynamicCommandExportFormat(el, documentURI);

        putWithCheck(guiUtils, result, ef.getFormatName(), () -> ef);
    }
    return result;
}
 
Example 2
Source File: WSDLRefValidator.java    From cxf with Apache License 2.0 6 votes vote down vote up
private FailureLocation getFailureLocation(List<Document> docs, XNode fNode) {
    if (fNode == null) {
        return null;
    }

    XPathUtils xpather = new XPathUtils(fNode.getNSMap());
    for (Document doc : docs) {
        Node node = (Node) xpather.getValue(fNode.toString(), doc, XPathConstants.NODE);
        if (null != node) {
            try {
                return new FailureLocation((Location)node.getUserData("location"),
                                           doc.getDocumentURI());
            } catch (Exception ex) {
                //ignore, probably not DOM level 3
            }
        }
    }
    return null;
}
 
Example 3
Source File: StaxUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static boolean addLocation(Document doc, Node node,
                                   Location loc,
                                   boolean recordLoc) {
    if (recordLoc && loc != null && (loc.getColumnNumber() != 0 || loc.getLineNumber() != 0)) {
        try {
            final int charOffset = loc.getCharacterOffset();
            final int colNum = loc.getColumnNumber();
            final int linNum = loc.getLineNumber();
            final String pubId = loc.getPublicId() == null ? doc.getDocumentURI() : loc.getPublicId();
            final String sysId = loc.getSystemId() == null ? doc.getDocumentURI() : loc.getSystemId();
            Location loc2 = new Location() {
                public int getCharacterOffset() {
                    return charOffset;
                }
                public int getColumnNumber() {
                    return colNum;
                }
                public int getLineNumber() {
                    return linNum;
                }
                public String getPublicId() {
                    return pubId;
                }
                public String getSystemId() {
                    return sysId;
                }
            };
            node.setUserData("location", loc2, LocationUserDataHandler.INSTANCE);
        } catch (Throwable ex) {
            //possibly not DOM level 3, won't be able to record this then
            return false;
        }
    }
    return recordLoc;
}
 
Example 4
Source File: TestDocumentImplClone.java    From marklogic-contentpump with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetOwnerDocumentBaseURI() throws IOException {
    List<ExpandedTree> trees = Utils.decodeTreeData(
        new File(testData + System.getProperty("file.separator")
        		+ forest, stand), false);
    assertEquals(num, trees.size());

    StringBuffer expected = new StringBuffer();
    StringBuffer actual = new StringBuffer();
    for (int i = 0; i < trees.size(); i++) {
        ExpandedTree t = trees.get(i);
    	String uri = t.getDocumentURI();
    	
    	Document doc = Utils.readXMLasDOMDocument(new File(testData, uri));
    	if (doc == null) continue;
    	
        expected.append(doc.getNodeName());
        expected.append("#OWNDERDOCROOT##").
        		 append(doc.getOwnerDocument() == null).append("#");
        expected.append("#OWNDERDOCCHILD##").
        		 append(doc.getFirstChild().getOwnerDocument().getNodeName()).append("#");
        
        Document d = (Document) new DocumentImpl(t, 0).cloneNode(true);
        actual.append(d.getNodeName());
        actual.append("#OWNDERDOCROOT##").
	 		   append(d.getOwnerDocument() == null).append("#");
        actual.append("#OWNDERDOCCHILD##").
	 		   append(d.getFirstChild().getOwnerDocument().getNodeName()).append("#");
        
        String expectedUri = doc.getDocumentURI();
        String actualUri = d.getDocumentURI();
        
        if (!expectedUri.contains(actualUri)) {
            expected.append("#BASEURIROOT##").
   		 			 append(expectedUri).append("#");
            actual.append("#BASEURIROOT##").
		 append(actualUri).append("#");
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug(expected.toString());
        LOG.debug(actual.toString());
    }
    assertEquals(expected.toString(), actual.toString());
}