www.pudn.com > DomView.zip > DomViewUtils.java


/******************************************************************** 
Domview 1.0 displays contents of an XML DOM object 
Copyright (C) 1999  The Bean Factory, LLC. 
 
This program is free software; you can redistribute it and/or 
modify it under the terms of the GNU General Public License 
as published by the Free Software Foundation; either version 2 
of the License, or (at your option) any later version. 
 
This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
GNU General Public License for more details. 
 
You should have received a copy of the GNU General Public License 
along with this program; if not, write to the Free Software 
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
 
Author: Sun Koh, The Bean Factory, LLC. 
*******************************************************************/ 
import java.io.*;                   
import com.sun.xml.tree.*; 
import com.ibm.xml.parsers.*; 
import org.w3c.dom.*; 
//import org.openxml.*; 
//import org.openxml.io.*; 
import org.openxml.parser.*; 
//import org.openxml.DOMFactory.*; 
/******************************************************************** 
 DomViewUtils is a static class that return a Document object model 
 given a location of an XML file 
 
 
 @version      : 1.0 
 @author       : Sun Koh 
 
********************************************************************/ 
public class DomViewUtils 
extends java.lang.Object 
implements java.io.Serializable { 
               
 
    protected static Document doc; 
 
// 
// Methods 
// 
    /** 
     Given an XML file location return a Document object 
      
     @param location    a file location 
     @return doc    a Document object 
     */ 
    public static Document getSunDocument(String location){ 
 
 
        try { 
            //convert comming file location into input stream 
            InputStream is = new FileInputStream(location); 
 
            //create xml document 
            doc = XmlDocument.createXmlDocument(is, true); 
 
                           
        } 
        catch ( Exception e ) { 
            System.out.println( e ); 
        } 
 
        return doc; 
 
    }//end method 
 
    /** 
     Given an XML file location return a Document object 
      
     @param location    a file location 
     @return doc    a Document object 
     */ 
    public static Document getIBMDocument(String location){ 
 
 
        try { 
 
            //InputStream is = new FileInputStream(location); 
            com.ibm.xml.parsers.DOMParser parser = new com.ibm.xml.parsers.DOMParser(); 
 
            parser.parse(location); 
 
            // The next line is only for DOM Parsers 
            doc = parser.getDocument(); 
               
        } 
        catch ( Exception e ) { 
            System.out.println( e ); 
        } 
 
        return doc; 
 
    }//end method 
 
     /** 
     Given an XML file location return a Document object 
      
     @param location    a file location 
     @return doc    a Document object 
     */ 
    public static Document getOpenXmlDocument(String location){ 
 
 
        try { 
 
            InputStream is = new FileInputStream( location ); 
            Reader      read = new BufferedReader( new InputStreamReader( is ) ); 
            org.openxml.parser.XMLParser parser = new XMLParser( read, location ); 
 
            doc = parser.parseDocument(); 
               
        } 
        catch ( Exception e ) { 
            System.out.println( e ); 
        } 
 
        return doc; 
 
    }//end method 
 
 
 
}//end of DomViewUtils class