01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.xerces.util;
19:
20: import org.apache.xerces.xni.parser.XMLInputSource;
21: import org.w3c.dom.Node;
22:
23: /**
24: * <p>An <code>XMLInputSource</code> analogue to <code>javax.xml.transform.dom.DOMSource</code>.</p>
25: *
26: * @version $Id: DOMInputSource.java 447241 2006-09-18 05:12:57Z mrglavas $
27: */
28: public final class DOMInputSource extends XMLInputSource {
29:
30: private Node fNode;
31:
32: public DOMInputSource() {
33: this (null);
34: }
35:
36: public DOMInputSource(Node node) {
37: super (null, getSystemIdFromNode(node), null);
38: fNode = node;
39: }
40:
41: public DOMInputSource(Node node, String systemId) {
42: super (null, systemId, null);
43: fNode = node;
44: }
45:
46: public Node getNode() {
47: return fNode;
48: }
49:
50: public void setNode(Node node) {
51: fNode = node;
52: }
53:
54: private static String getSystemIdFromNode(Node node) {
55: if (node != null) {
56: try {
57: return node.getBaseURI();
58: }
59: // If the DOM implementation is DOM Level 2
60: // then a NoSuchMethodError will be thrown.
61: // Just ignore it.
62: catch (NoSuchMethodError e) {
63: return null;
64: }
65: // There was a failure for some other reason
66: // Ignore it as well.
67: catch (Exception e) {
68: return null;
69: }
70: }
71: return null;
72: }
73:
74: } // DOMInputSource
|