package org.intermine.util;

/*
 * Copyright (C) 2002-2010 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.io.IOException;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 * Basic SAX Parser
 *
 * @author Mark Woodbridge
 */
public class SAXParser
{
    /**
     * Parse the an xml file
     * @param is the inputsource to parse
     * @param handler the SAX event handler to use
     * @throws SAXException if an error occurs during parsing
     * @throws IOException if an error occurs reading from the InputSource
     * @throws ParserConfigurationException if there is an error in the config
     */
    public static void parse(InputSource is, DefaultHandler handler)
        throws SAXException, IOException, ParserConfigurationException {
        parse(is, handler, true);
    }

    /**
     * Parse the an xml file
     * @param is the inputsource to parse
     * @param handler the SAX event handler to use
     * @param validate if true, validate before parsing
     * @throws SAXException if an error occurs during parsing
     * @throws IOException if an error occurs reading from the InputSource
     * @throws ParserConfigurationException if there is an error in the config
     */
    public static void parse(InputSource is, DefaultHandler handler, boolean validate)
        throws SAXException, IOException, ParserConfigurationException {
        try {
            SAXParserFactory factory = SAXParserFactory.newInstance();
            factory.setValidating(validate);
            factory.newSAXParser().parse(is, handler);
        } catch (ParserConfigurationException e) {
            ParserConfigurationException e2 = new ParserConfigurationException("The underlying "
                    + "parser does not support the requested features");
            e2.initCause(e);
            throw e2;
        } catch (SAXException e) {
            SAXException e2 = new SAXException("Error parsing XML document");
            e2.initCause(e);
            throw e2;
        }
    }
}

@@ -352,50 +352,8 @@
 on;%0A
-import javax.xml.parsers.SAXParserFactory;
 %0Aimp
@@ -396,32 +396,108 @@
 ationException;%0A
+import javax.xml.parsers.SAXParserFactory;%0A%0Aimport org.apache.log4j.Logger;%0A
 import org.xml.s
@@ -672,16 +672,85 @@
 arser%0A%7B%0A
+%0A    private static Logger LOG = Logger.getLogger(SAXParser.class);%0A%0A
     /**%0A
@@ -1264,19 +1264,20 @@
 andler, 
-tru
+fals
 e);%0A    
@@ -2345,115 +2345,8 @@
 ) %7B%0A
-            SAXException e2 = new SAXException(%22Error parsing XML document%22);%0A            e2.initCause(e);%0A
     
@@ -2352,33 +2352,32 @@
          throw e
-2
 ;%0A        %7D%0A    

throw sax exception, don't hide it. Refs #2215