KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > util > DOMInputSource


1 /*
2  * Copyright 2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package com.sun.org.apache.xerces.internal.util;
18
19 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
20 import org.w3c.dom.Node JavaDoc;
21
22 /**
23  * <p>An <code>XMLInputSource</code> analogue to <code>javax.xml.transform.dom.DOMSource</code>.</p>
24  *
25  * @version $Id: DOMInputSource.java,v 1.1.4.1 2005/09/05 07:45:34 neerajbj Exp $
26  */

27 public final class DOMInputSource extends XMLInputSource {
28     
29     private Node JavaDoc fNode;
30     
31     public DOMInputSource() {
32         this(null);
33     }
34     
35     public DOMInputSource(Node JavaDoc node) {
36         super(null, getSystemIdFromNode(node), null);
37         fNode = node;
38     }
39     
40     public DOMInputSource(Node JavaDoc node, String JavaDoc systemId) {
41         super(null, systemId, null);
42         fNode = node;
43     }
44     
45     public Node JavaDoc getNode() {
46         return fNode;
47     }
48     
49     public void setNode(Node JavaDoc node) {
50         fNode = node;
51     }
52     
53     private static String JavaDoc getSystemIdFromNode(Node JavaDoc node) {
54         if (node != null) {
55             try {
56                 return node.getBaseURI();
57             }
58             // If the DOM implementation is DOM Level 2
59
// then a NoSuchMethodError will be thrown.
60
// Just ignore it.
61
catch (NoSuchMethodError JavaDoc e) {
62                 return null;
63             }
64             // There was a failure for some other reason
65
// Ignore it as well.
66
catch (Exception JavaDoc e) {
67                 return null;
68             }
69         }
70         return null;
71     }
72     
73 } // DOMInputSource
74
Popular Tags