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

package org.apache.xerces.util;

import org.apache.xerces.xni.parser.XMLInputSource;
import org.w3c.dom.Node;

/**
 * <p>An <code>XMLInputSource</code> analogue to <code>javax.xml.transform.dom.DOMSource</code>.</p>
 * 
 * @version $Id$
 */
public class DOMInputSource extends XMLInputSource {

	private Node fNode;
    
    public DOMInputSource() {
        this(null);
    }
	
	public DOMInputSource(Node node) {
		super(null, getSystemIdFromNode(node), null);
		fNode = node;
	}
	
	public DOMInputSource(Node node, String systemId) {
		super(null, systemId, null);
		fNode = node;
	}
	
	public Node getNode() {
		return fNode;
	}
	
	public void setNode(Node node) {
		fNode = node;
	}
    
    private static String getSystemIdFromNode(Node node) {
        if (node != null) {
            try {
                return node.getBaseURI();
            }
            // If the DOM implementation is DOM Level 2 
            // then a NoSuchMethodError will be thrown.
            // Just ignore it.
            catch (NoSuchMethodError e) {
                return null;
            }
            // There was a failure for some other reason
            // Ignore it as well.
            catch (Exception e) {
                return null;
            }
        }
        return null;
    }
    
} // DOMInputSource

@@ -907,18 +907,25 @@
 ource %7B%0A
-%0A%09
+    %0A    
 private 
@@ -997,19 +997,25 @@
 ;%0A    %7D%0A
-%09%0A%09
+    %0A    
 public D
@@ -1037,26 +1037,32 @@
 ode node) %7B%0A
-%09%09
+        
 super(null, 
@@ -1087,34 +1087,40 @@
 e(node), null);%0A
-%09%09
+        
 fNode = node;%0A%09%7D
@@ -1113,30 +1113,39 @@
 ode = node;%0A
-%09%7D%0A%09%0A%09
+    %7D%0A    %0A    
 public DOMIn
@@ -1184,18 +1184,24 @@
 emId) %7B%0A
-%09%09
+        
 super(nu
@@ -1221,18 +1221,24 @@
  null);%0A
-%09%09
+        
 fNode = 
@@ -1239,30 +1239,39 @@
 ode = node;%0A
-%09%7D%0A%09%0A%09
+    %7D%0A    %0A    
 public Node 
@@ -1282,18 +1282,24 @@
 ode() %7B%0A
-%09%09
+        
 return f
@@ -1308,14 +1308,23 @@
 de;%0A
-%09%7D%0A%09%0A%09
+    %7D%0A    %0A    
 publ
@@ -1356,10 +1356,16 @@
 ) %7B%0A
-%09%09
+        
 fNod
@@ -1378,9 +1378,12 @@
 de;%0A
-%09
+    
 %7D%0A  

Correct indentation.