1 /*
2  * reserved comment block
3  * DO NOT REMOVE OR ALTER!
4  */
5 /*
6  * Copyright 2005 The Apache Software Foundation.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 package com.sun.org.apache.xerces.internal.util;
22 
23 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
24 import org.w3c.dom.Node;
25 
26 /**
27  * <p>An <code>XMLInputSource</code> analogue to <code>javax.xml.transform.dom.DOMSource</code>.</p>
28  *
29  */
30 public final class DOMInputSource extends XMLInputSource {
31 
32     private Node fNode;
33 
DOMInputSource()34     public DOMInputSource() {
35         this(null);
36     }
37 
DOMInputSource(Node node)38     public DOMInputSource(Node node) {
39         super(null, getSystemIdFromNode(node), null);
40         fNode = node;
41     }
42 
DOMInputSource(Node node, String systemId)43     public DOMInputSource(Node node, String systemId) {
44         super(null, systemId, null);
45         fNode = node;
46     }
47 
getNode()48     public Node getNode() {
49         return fNode;
50     }
51 
setNode(Node node)52     public void setNode(Node node) {
53         fNode = node;
54     }
55 
getSystemIdFromNode(Node node)56     private static String getSystemIdFromNode(Node node) {
57         if (node != null) {
58             try {
59                 return node.getBaseURI();
60             }
61             // If the DOM implementation is DOM Level 2
62             // then a NoSuchMethodError will be thrown.
63             // Just ignore it.
64             catch (NoSuchMethodError e) {
65                 return null;
66             }
67             // There was a failure for some other reason
68             // Ignore it as well.
69             catch (Exception e) {
70                 return null;
71             }
72         }
73         return null;
74     }
75 
76 } // DOMInputSource
77