tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@locus.apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util/xml XmlMapper.java
Date Tue, 25 Apr 2000 19:01:08 GMT
craigmcc    00/04/25 12:01:08

  Modified:    src/share/org/apache/tomcat/util/xml XmlMapper.java
  Log:
  Create a variant of the readXml() method that takes an InputStream, rather
  than a File, as the source of the XML data file.  The common code should
  probably be factored out and shared, but that can be done when we migrate to
  a JAXP-based parser selection mechanism.
  
  Revision  Changes    Path
  1.14      +50 -0     jakarta-tomcat/src/share/org/apache/tomcat/util/xml/XmlMapper.java
  
  Index: XmlMapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/xml/XmlMapper.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- XmlMapper.java	2000/04/14 05:20:06	1.13
  +++ XmlMapper.java	2000/04/25 19:01:08	1.14
  @@ -222,6 +222,56 @@
   	}
       }
   
  +    /** read an XML input stream, construct and return the object hierarchy
  +     */
  +    public Object readXml(InputStream xmlFile, Object root)
  +	throws Exception
  +    {
  +	if(root!=null) {
  +	    Stack st=this.getObjectStack();
  +	    this.root=root;
  +	    st.push( root );
  +	}
  +	InputSource input;
  +	Parser parser=null;
  +	try {
  +	    if(System.getProperty("org.xml.sax.parser") != null )
  +		parser=ParserFactory.makeParser();
  +	    else
  +		parser=ParserFactory.makeParser("com.sun.xml.parser.Parser");
  +
  +	    input = new InputSource( new InputStreamReader(xmlFile));
  +
  +	    parser.setDocumentHandler( this);
  +	    parser.setEntityResolver( this);
  +	    parser.setDTDHandler( this);
  +	    parser.parse( input );
  +	    return root;
  +	    // assume the stack is in the right position.
  +	    // or throw an exception is more than one element is on the stack
  +	} catch( IllegalAccessException ex1 ) {
  +	    ex1.printStackTrace();
  +	    throw new Exception( "Error creating sax parser" );
  +	} catch(ClassNotFoundException  ex2 ) {
  +	    ex2.printStackTrace();
  +	    throw new Exception( "Error creating sax parser" );
  +	} catch( InstantiationException ex3)  {
  +	    ex3.printStackTrace();
  +	    throw new Exception( "Error creating sax parser" );
  +   	} catch (IOException ioe) {
  +	    String msg = "Can't open config file: " + xmlFile +
  +		" due to: " + ioe;
  +	    throw new Exception(msg);
  +	} catch (SAXException se) {
  +	    System.out.println("ERROR reading " + xmlFile);
  +	    System.out.println("At " + se.getMessage());
  +	    //	    se.printStackTrace();
  +	    System.out.println();
  +	    Exception ex1=se.getException();
  +	    throw ex1;
  +	}
  +    }
  +
       class Rule {
   	XmlMatch match;
   	XmlAction action;
  
  
  

Mime
View raw message