You are viewing a plain text version of this content. The canonical link for it is here.
Posted to crimson-cvs@xml.apache.org by ed...@apache.org on 2001/01/25 00:50:56 UTC

cvs commit: xml-crimson/src/org/apache/crimson/jaxp SAXParserFactoryImpl.java SAXParserImpl.java

edwingo     01/01/24 15:50:56

  Modified:    src/org/apache/crimson/jaxp SAXParserFactoryImpl.java
                        SAXParserImpl.java
  Log:
  4380317 SAXParserFactory.getFeature() always throws an exception
  
  Revision  Changes    Path
  1.2       +51 -5     xml-crimson/src/org/apache/crimson/jaxp/SAXParserFactoryImpl.java
  
  Index: SAXParserFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-crimson/src/org/apache/crimson/jaxp/SAXParserFactoryImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SAXParserFactoryImpl.java	2000/11/23 01:53:33	1.1
  +++ SAXParserFactoryImpl.java	2001/01/24 23:50:54	1.2
  @@ -1,5 +1,5 @@
   /*
  - * $Id: SAXParserFactoryImpl.java,v 1.1 2000/11/23 01:53:33 edwingo Exp $
  + * $Id: SAXParserFactoryImpl.java,v 1.2 2001/01/24 23:50:54 edwingo Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -65,10 +65,13 @@
   import org.xml.sax.SAXException;
   import org.xml.sax.SAXNotRecognizedException;
   import org.xml.sax.SAXNotSupportedException;
  +import org.xml.sax.XMLReader;
   
  +import java.util.Hashtable;
  +
   /**
    * @author Rajiv Mordani
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   
   /**
  @@ -77,12 +80,29 @@
    * default implementation for the platform.
    */
   public class SAXParserFactoryImpl extends SAXParserFactory {
  +    private Hashtable features;
   
       public SAXParserFactoryImpl() {
      	 
       }
   
       /**
  +     * Create a new SAXParser and set SAX features but throwing subclasses
  +     * of SAXException
  +     */
  +    private SAXParser newSAXParser0()
  +        throws SAXNotSupportedException, SAXNotRecognizedException
  +    {
  +        // XXX Does not handle possible conflicts between SAX feature names
  +        // and JAXP specific feature names,
  +        // eg. SAXParserFactory.isValidating() and
  +        // http://xml.org/sax/features/validation
  +        SAXParserImpl saxParserImpl = new SAXParserImpl(this);
  +        saxParserImpl.setFeatures(features);
  +        return saxParserImpl;
  +    }
  +
  +    /**
        * Creates a new instance of <code>SAXParser</code> using the currently
        * configured factory parameters.
        * @return javax.xml.parsers.SAXParser
  @@ -90,7 +110,14 @@
       public SAXParser newSAXParser()
           throws SAXException, ParserConfigurationException
       {
  -    	SAXParserImpl saxParserImpl = new SAXParserImpl(this);
  +        SAXParser saxParserImpl;
  +        try {
  +            saxParserImpl = newSAXParser0();
  +        } catch (SAXException se) {
  +            // Handles both SAXNotSupportedException,
  +            // SAXNotRecognizedException
  +            throw new ParserConfigurationException(se.getMessage());
  +        }
   	return saxParserImpl;
       }
   
  @@ -102,7 +129,15 @@
           throws ParserConfigurationException, SAXNotRecognizedException, 
   		SAXNotSupportedException
       {
  -        throw new SAXNotRecognizedException("Feature: " + name);
  +        // XXX This is ugly.  We have to collect the features and then
  +        // later create an XMLReader to verify the features.
  +        if (features == null) {
  +            features = new Hashtable();
  +        }
  +        features.put(name, new Boolean(value));
  +
  +        // Test the feature by possibly throwing SAX exceptions
  +        newSAXParser0();
       }
   
       /**
  @@ -113,6 +148,17 @@
           throws ParserConfigurationException, SAXNotRecognizedException,
   		SAXNotSupportedException
       {
  -        throw new SAXNotRecognizedException("Feature: " + name);
  +        // Create an XMLReader and get feature value.
  +        XMLReader xmlReader;
  +        try {
  +            xmlReader = newSAXParser0().getXMLReader();
  +        } catch (SAXNotSupportedException e) {
  +            throw e;
  +        } catch (SAXNotRecognizedException e) {
  +            throw e;
  +        } catch (SAXException se) {
  +            throw new ParserConfigurationException(se.getMessage());
  +        }            
  +        return xmlReader.getFeature(name);
       }
   }
  
  
  
  1.2       +34 -18    xml-crimson/src/org/apache/crimson/jaxp/SAXParserImpl.java
  
  Index: SAXParserImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-crimson/src/org/apache/crimson/jaxp/SAXParserImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SAXParserImpl.java	2000/11/23 01:53:33	1.1
  +++ SAXParserImpl.java	2001/01/24 23:50:54	1.2
  @@ -1,5 +1,5 @@
   /*
  - * $Id: SAXParserImpl.java,v 1.1 2000/11/23 01:53:33 edwingo Exp $
  + * $Id: SAXParserImpl.java,v 1.2 2001/01/24 23:50:54 edwingo Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -74,9 +74,11 @@
   
   import org.apache.crimson.parser.XMLReaderImpl;
   
  +import java.util.*;
  +
   /**
    * @author Rajiv Mordani
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   
   /**
  @@ -92,27 +94,22 @@
       private boolean namespaceAware = false;
       
       SAXParserImpl(SAXParserFactory spf)
  -        throws SAXException, ParserConfigurationException 
  +        throws SAXNotSupportedException, SAXNotRecognizedException
       {
           this.spf = spf;
   
           xmlReader = new XMLReaderImpl();
   
  -        try {
  -            // Validation
  -            validating = spf.isValidating();
  -            String validation = "http://xml.org/sax/features/validation";
  -            xmlReader.setFeature(validation, validating);
  -
  -            // If validating, provide a default ErrorHandler that prints
  -            // validation errors with a warning telling the user to set an
  -            // ErrorHandler
  -            if (validating) {
  -                xmlReader.setErrorHandler(new DefaultValidationErrorHandler());
  -            }
  -        } catch (SAXException e) {
  -            // Handles both SAXNotSupportedException, SAXNotRecognizedException
  -            throw new ParserConfigurationException(e.getMessage());
  +        // Validation
  +        validating = spf.isValidating();
  +        String validation = "http://xml.org/sax/features/validation";
  +        xmlReader.setFeature(validation, validating);
  +
  +        // If validating, provide a default ErrorHandler that prints
  +        // validation errors with a warning telling the user to set an
  +        // ErrorHandler
  +        if (validating) {
  +            xmlReader.setErrorHandler(new DefaultValidationErrorHandler());
           }
   
           if (spf.isNamespaceAware()) {
  @@ -120,6 +117,25 @@
   	    // XXX ??? Crimson does support namespaces, isn't it ??
   	    //             throw new ParserConfigurationException(
   	    //                 "Namespace not supported by SAXParser");
  +        }
  +    }
  +
  +    /**
  +     * Set any features of our XMLReader based on any features set on the
  +     * SAXParserFactory.
  +     *
  +     * XXX Does not handle possible conflicts between SAX feature names and
  +     * JAXP specific feature names, eg. SAXParserFactory.isValidating()
  +     */
  +    void setFeatures(Hashtable features)
  +        throws SAXNotSupportedException, SAXNotRecognizedException
  +    {
  +        if (features != null) {
  +            for (Enumeration e = features.keys(); e.hasMoreElements();) {
  +                String feature = (String)e.nextElement();
  +                boolean value = ((Boolean)features.get(feature)).booleanValue();
  +                xmlReader.setFeature(feature, value);
  +            }
           }
       }