

/**
 * Title:        CV XML Servlet Test Project
 * Description:  Test project to learn Oracle's XML parsing technology & JDBC for Flightpath->BizTalk->CV interface.
 * Copyright:    Copyright (c) 2001
 * Company:      CSSI
 * @author Julian Sasse
 * @version 1.0
 */
//import oracle.xml.parser.v2.*;
import org.xml.sax.*;
import org.apache.xerces.parsers.*;
import org.apache.xerces.framework.*;
import org.apache.xerces.validators.common.*;
import java.net.*;
import java.io.*;
import org.w3c.dom.*;
import java.util.*;

public class ParseTest extends DOMParser{

  public ParseTest() {}
  public String parseXML(InputStream ins){
  try{
//    DOMParser dp  = new DOMParser();
//      URL       url = createURL (xmlURI);


      // Set Schema Validation to true
      //dp.setValidationMode(false);
      //dp.setSchemaValidationMode(true);
      //dp.setPreserveWhitespace (true);

      //dp.setErrorStream (System.out);
      /*try
      {
         System.out.println("Parsing "+xmlURI);
         dp.parse (url);

         System.out.println("The input file <"+xmlURI+"> parsed without errors");
         return null;
      }*/
        InputSource is = new InputSource(ins);
        setValidation(true);
        setValidationSchema(true);
        //writeError("four");
      try{
    //    dp.parse(createURL("c:/broadwing/xml/cv_enterprise.xml"));
           parse(is);
           return null;
      }
      /*catch(Exception e){//writeError("exception is " + e.getMessage());
        return e.getMessage();
      }*/


      /*catch (Exception pe)
      {
              System.out.println("Parser Exception: " + pe.getMessage());
      }*/
      catch (Exception e)
      {
        System.out.println("NonParserException: " + e.getMessage());
        return e.getMessage();

      }
    }catch(Exception ee){System.out.println("exception somewhere"); return ee.getMessage();}
  }



   public URL createURL(String fileName)
   {
      URL url = null;
      try
      {
         url = new URL(fileName);
      }
      catch (MalformedURLException ex)
      {
         File f = new File(fileName);
         try
         {
            String path = f.getAbsolutePath();
            // This is a bunch of weird code that is required to
            // make a valid URL on the Windows platform, due
            // to inconsistencies in what getAbsolutePath returns.
            String fs = System.getProperty("file.separator");
            if (fs.length() == 1)
            {
               char sep = fs.charAt(0);
               if (sep != '/')
                  path = path.replace(sep, '/');
               if (path.charAt(0) != '/')
                  path = '/' + path;
            }
            path = "file://" + path;
            url = new URL(path);
         }
         /*catch (MalformedURLException e)
         {
            System.out.println("Cannot create url for: " + fileName);
            System.exit(0);
         }*/
         catch(Exception ee){System.out.println(ee.getMessage());}
      }
      return url;
   }


    public static InputStream getInputStream(String filename){
      try{
        FileInputStream fis = new FileInputStream(filename);
        return fis;
      }
      catch(Exception e){

        System.out.println("error is  "+ e.getMessage());
        return null;
        }
      }

   public static void main(String[] args){
    ParseTest pt = new ParseTest();

    String s = pt.parseXML(getInputStream("C:/xml/cv_enterprise.xml"));
    //System.out.println("returned string is " + s);
    }
}