/*
 * $Id: OracleDriver.java,v 1.1.1.1 2002/09/30 15:08:52 smartine Exp $
 * Copyright (C) 1999-2000 David Brownell
 * 
 * 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
 */

package xml.vendor;

import java.io.IOException;
import java.util.Locale;

import org.xml.sax.*;
import org.xml.sax.ext.DeclHandler;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.ParserAdapter;

import xml.*;

// requires Oracle v2 parser -- see http://www.oracle.com
import oracle.xml.parser.v2.*;


// $Id: OracleDriver.java,v 1.1.1.1 2002/09/30 15:08:52 smartine Exp $

/**
 * This is a wrapper around the <b>oracle.xml.parser.v2.SAXParser</b>
 * SAX1 parser, implementing <b>SAX2</b> interfaces.
 * The standardized SAX2 facilities exposed by this parser include all
 * SAX1 features, as well as a number of additional features and
 * properties identified by standardized URIs.  Those features (but not
 * the associated URIs) are summarized below.</p>
 *
 * <table border="1" width='100%' cellpadding='3' cellspacing='0'>
 * <tr bgcolor='#ccccff'>
 *	<th><font size='+1'>Name</font></th>
 *	<th><font size='+1'>Notes</font></th></tr>
 *
 * <tr><td colspan=2><center><em>Features ... URL prefix is
 * <b>http://xml.org/sax/features/</b></em></center></td></tr>
 *
 * <tr><td>(URL)/external-general-entities</td>
 *	<td>Value is fixed at <em>true</em></td></tr>
 * <tr><td>(URL)/external-parameter-entities</td>
 *	<td>Value is fixed at <em>true</em></td></tr>
 * <tr><td>(URL)/namespaces</td>
 *	<td>Value defaults to <em>true</em></td></tr>
 * <tr><td>(URL)/namespace-prefixes</td>
 *	<td>Value defaults at <em>false</em></td></tr>
 * <tr><td>(URL)/validation</td>
 *	<td>Defaults to <em>false</em>; may be set to <em>true</em></td></tr>
 * </table>
 *
 * <p> None of the new SAX2 properties is supported. </p>
 *
 * @author David Brownell
 * @version $Date: 2002/09/30 15:08:52 $
 */
public class OracleDriver extends ParserAdapter
    // XXX implements Parser
{
    private SAXParser		parser;

    /**
     * Constructs a parser which by default does not validate.
     */
    public OracleDriver ()
    {
	this (new SAXParser ());
    }

    private OracleDriver (SAXParser p)
    {
	super (p);
	parser = p;
	parser.setValidationMode (false);
    }

    private static final String FEATURES = "http://xml.org/sax/features/";
    // private static final String HANDLERS = "http://xml.org/sax/properties/";

    /**
     * <b>SAX2</b>: Tells whether this parser supports the specified feature.
     * At this time, this directly parallels the underlying parser, except
     * that the use of validation can be enabled or disabled.
     */
    public boolean getFeature (String featureId)
    throws SAXNotRecognizedException, SAXNotSupportedException
    {
	// validate or not, by choice of underlying parser
	if ((FEATURES + "validation").equals (featureId))
	    return parser.getValidationMode ();

	// external entities (both types) are currently always included
	if ((FEATURES + "external-general-entities")
		    .equals (featureId)
		|| (FEATURES + "external-parameter-entities")
		    .equals (featureId))
	    return true;

	// always provides a locator

	return super.getFeature (featureId);
    }

    /**
     * <b>SAX2</b>:  Sets the state of features supported in this parser.
     */
    public void setFeature (String featureId, boolean state)
    throws SAXNotRecognizedException, SAXNotSupportedException
    {
	boolean	current = getFeature (featureId);

	if (state == current)
	    return;

	// features with mutable state:
	if ((FEATURES + "validation").equals (featureId)) {
	    parser.setValidationMode (state);
	    return;
	}

	super.setFeature (featureId, state);
    }
}
