You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by an...@apache.org on 2001/08/02 07:47:38 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/parsers AbstractSAXParser.java

andyc       01/08/01 22:47:38

  Modified:    java/src/org/apache/xerces/parsers Tag: xerces_j_2
                        AbstractSAXParser.java
  Log:
  Fixed possible "leak" of XNIException in the setting and query of
  features and properties. Because XNIException is derived from
  RuntimeException, it doesn't have to be explicitly caught which
  means that if not properly protected, these exceptions could
  leak to the outside application using the parser. Since these
  exceptions are meant to signal an internal error, they should
  always be caught and either wrapped or properly handled before
  they leak outside the parser. This patch fixes one such
  possibility.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.17  +218 -218  xml-xerces/java/src/org/apache/xerces/parsers/Attic/AbstractSAXParser.java
  
  Index: AbstractSAXParser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/Attic/AbstractSAXParser.java,v
  retrieving revision 1.1.2.16
  retrieving revision 1.1.2.17
  diff -u -r1.1.2.16 -r1.1.2.17
  --- AbstractSAXParser.java	2001/07/31 09:50:07	1.1.2.16
  +++ AbstractSAXParser.java	2001/08/02 05:47:38	1.1.2.17
  @@ -106,7 +106,7 @@
    * @author Arnaud Le Hors, IBM
    * @author Andy Clark, IBM
    *
  - * @version $Id: AbstractSAXParser.java,v 1.1.2.16 2001/07/31 09:50:07 andyc Exp $ 
  + * @version $Id: AbstractSAXParser.java,v 1.1.2.17 2001/08/02 05:47:38 andyc Exp $ 
    */
   public abstract class AbstractSAXParser
       extends AbstractXMLDocumentParser
  @@ -1176,67 +1176,67 @@
       public void setFeature(String featureId, boolean state)
           throws SAXNotRecognizedException, SAXNotSupportedException {
   
  -        //
  -        // SAX2 Features
  -        //
  -
  -        if (featureId.startsWith(Constants.SAX_FEATURE_PREFIX)) {
  -            String feature = featureId.substring(Constants.SAX_FEATURE_PREFIX.length());
  -
  -            // http://xml.org/sax/features/namespaces
  -            if (feature.equals(Constants.NAMESPACES_FEATURE)) {
  -                fConfiguration.setFeature(featureId, state);
  -                fNamespaces = state;
  -                return;
  -            }
  -            // http://xml.org/sax/features/namespace-prefixes
  -            //   controls the reporting of raw prefixed names and Namespace 
  -            //   declarations (xmlns* attributes): when this feature is false 
  -            //   (the default), raw prefixed names may optionally be reported, 
  -            //   and xmlns* attributes must not be reported.
  -            //
  -            if (feature.equals(Constants.NAMESPACE_PREFIXES_FEATURE)) {
  -                fConfiguration.setFeature(featureId, state);
  -                fNamespacePrefixes = state;
  -                return;
  -            }
  -            // http://xml.org/sax/features/string-interning
  -            //   controls the use of java.lang.String#intern() for strings
  -            //   passed to SAX handlers.
  +        try {
               //
  -            if (feature.equals(Constants.STRING_INTERNING_FEATURE)) {
  -                if (state) {
  -                    // REVISIT: Localize this error message. -Ac
  -                    throw new SAXNotSupportedException(
  -                        "PAR018 " + state + " state for feature \"" + featureId
  -                        + "\" is not supported.\n" + state + '\t' + featureId);
  +            // SAX2 Features
  +            //
  +    
  +            if (featureId.startsWith(Constants.SAX_FEATURE_PREFIX)) {
  +                String feature = featureId.substring(Constants.SAX_FEATURE_PREFIX.length());
  +    
  +                // http://xml.org/sax/features/namespaces
  +                if (feature.equals(Constants.NAMESPACES_FEATURE)) {
  +                    fConfiguration.setFeature(featureId, state);
  +                    fNamespaces = state;
  +                    return;
  +                }
  +                // http://xml.org/sax/features/namespace-prefixes
  +                //   controls the reporting of raw prefixed names and Namespace 
  +                //   declarations (xmlns* attributes): when this feature is false 
  +                //   (the default), raw prefixed names may optionally be reported, 
  +                //   and xmlns* attributes must not be reported.
  +                //
  +                if (feature.equals(Constants.NAMESPACE_PREFIXES_FEATURE)) {
  +                    fConfiguration.setFeature(featureId, state);
  +                    fNamespacePrefixes = state;
  +                    return;
  +                }
  +                // http://xml.org/sax/features/string-interning
  +                //   controls the use of java.lang.String#intern() for strings
  +                //   passed to SAX handlers.
  +                //
  +                if (feature.equals(Constants.STRING_INTERNING_FEATURE)) {
  +                    if (state) {
  +                        // REVISIT: Localize this error message. -Ac
  +                        throw new SAXNotSupportedException(
  +                            "PAR018 " + state + " state for feature \"" + featureId
  +                            + "\" is not supported.\n" + state + '\t' + featureId);
  +                    }
  +                    return;
                   }
  -                return;
  +       
  +                //
  +                // Drop through and perform default processing
  +                //
               }
  -   
  +    
               //
  -            // Drop through and perform default processing
  +            // Xerces Features
               //
  -        }
  -
  -        //
  -        // Xerces Features
  -        //
  -
  -        /*
  -        else if (featureId.startsWith(XERCES_FEATURES_PREFIX)) {
  -            String feature = featureId.substring(XERCES_FEATURES_PREFIX.length());
  +    
  +            /*
  +            else if (featureId.startsWith(XERCES_FEATURES_PREFIX)) {
  +                String feature = featureId.substring(XERCES_FEATURES_PREFIX.length());
  +                //
  +                // Drop through and perform default processing
  +                //
  +            }
  +            */
  +    
               //
  -            // Drop through and perform default processing
  +            // Default handling
               //
  -        }
  -        */
   
  -        //
  -        // Default handling
  -        //
  -
  -        try {
               fConfiguration.setFeature(featureId, state);
           }
           catch (XMLConfigurationException e) {
  @@ -1267,51 +1267,51 @@
        */
       public boolean getFeature(String featureId)
           throws SAXNotRecognizedException, SAXNotSupportedException {
  -
  -        //
  -        // SAX2 Features
  -        //
  -
  -        if (featureId.startsWith(Constants.SAX_FEATURE_PREFIX)) {
  -            String feature =
  -                featureId.substring(Constants.SAX_FEATURE_PREFIX.length());
   
  -            // http://xml.org/sax/features/namespace-prefixes
  -            //   controls the reporting of raw prefixed names and Namespace 
  -            //   declarations (xmlns* attributes): when this feature is false 
  -            //   (the default), raw prefixed names may optionally be reported, 
  -            //   and xmlns* attributes must not be reported.
  +        try {
               //
  -            if (feature.equals(Constants.NAMESPACE_PREFIXES_FEATURE)) {
  -                boolean state = fConfiguration.getFeature(featureId);
  -                return state;
  -            }
  -            // http://xml.org/sax/features/string-interning
  -            //   controls the use of java.lang.String#intern() for strings
  -            //   passed to SAX handlers.
  +            // SAX2 Features
               //
  -            if (feature.equals(Constants.STRING_INTERNING_FEATURE)) {
  -                return false;
  -            }
   
  -            //
  -            // Drop through and perform default processing
  -            //
  -        }
  +            if (featureId.startsWith(Constants.SAX_FEATURE_PREFIX)) {
  +                String feature =
  +                    featureId.substring(Constants.SAX_FEATURE_PREFIX.length());
  +
  +                // http://xml.org/sax/features/namespace-prefixes
  +                //   controls the reporting of raw prefixed names and Namespace 
  +                //   declarations (xmlns* attributes): when this feature is false 
  +                //   (the default), raw prefixed names may optionally be reported, 
  +                //   and xmlns* attributes must not be reported.
  +                //
  +                if (feature.equals(Constants.NAMESPACE_PREFIXES_FEATURE)) {
  +                    boolean state = fConfiguration.getFeature(featureId);
  +                    return state;
  +                }
  +                // http://xml.org/sax/features/string-interning
  +                //   controls the use of java.lang.String#intern() for strings
  +                //   passed to SAX handlers.
  +                //
  +                if (feature.equals(Constants.STRING_INTERNING_FEATURE)) {
  +                    return false;
  +                }
   
  -        //
  -        // Xerces Features
  -        //
  +                //
  +                // Drop through and perform default processing
  +                //
  +            }
   
  -        /*
  -        else if (featureId.startsWith(XERCES_FEATURES_PREFIX)) {
               //
  -            // Drop through and perform default processing
  +            // Xerces Features
               //
  -        }
  -        */
   
  -        try {
  +            /*
  +            else if (featureId.startsWith(XERCES_FEATURES_PREFIX)) {
  +                //
  +                // Drop through and perform default processing
  +                //
  +            }
  +            */
  +
               return fConfiguration.getFeature(featureId);
           }
           catch (XMLConfigurationException e) {
  @@ -1344,93 +1344,93 @@
       public void setProperty(String propertyId, Object value)
           throws SAXNotRecognizedException, SAXNotSupportedException {
   
  -        //
  -        // SAX2 core properties
  -        //
  -
  -        if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) {
  -            String property =
  -                propertyId.substring(Constants.SAX_PROPERTY_PREFIX.length());
  -            //
  -            // http://xml.org/sax/properties/lexical-handler
  -            // Value type: org.xml.sax.ext.LexicalHandler
  -            // Access: read/write, pre-parse only
  -            //   Set the lexical event handler.
  -            //
  -            if (property.equals(Constants.LEXICAL_HANDLER_PROPERTY)) {
  -                try {
  -                    setLexicalHandler((LexicalHandler)value);
  -                }
  -                catch (ClassCastException e) {
  -                    // REVISIT: Localize this error message. -ac
  -                    throw new SAXNotSupportedException(
  -                    "PAR012 For propertyID \""
  -                    +propertyId+"\", the value \""
  -                    +value+"\" cannot be cast to LexicalHandler."
  -                    +'\n'+propertyId+'\t'+value+"\tLexicalHandler");
  -                }
  -                return;
  -            }
  +        try {
               //
  -            // http://xml.org/sax/properties/declaration-handler
  -            // Value type: org.xml.sax.ext.DeclHandler
  -            // Access: read/write, pre-parse only
  -            //   Set the DTD declaration event handler.
  +            // SAX2 core properties
               //
  -            if (property.equals(Constants.DECLARATION_HANDLER_PROPERTY)) {
  -                try {
  -                    setDeclHandler((DeclHandler)value);
  +
  +            if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) {
  +                String property =
  +                    propertyId.substring(Constants.SAX_PROPERTY_PREFIX.length());
  +                //
  +                // http://xml.org/sax/properties/lexical-handler
  +                // Value type: org.xml.sax.ext.LexicalHandler
  +                // Access: read/write, pre-parse only
  +                //   Set the lexical event handler.
  +                //
  +                if (property.equals(Constants.LEXICAL_HANDLER_PROPERTY)) {
  +                    try {
  +                        setLexicalHandler((LexicalHandler)value);
  +                    }
  +                    catch (ClassCastException e) {
  +                        // REVISIT: Localize this error message. -ac
  +                        throw new SAXNotSupportedException(
  +                        "PAR012 For propertyID \""
  +                        +propertyId+"\", the value \""
  +                        +value+"\" cannot be cast to LexicalHandler."
  +                        +'\n'+propertyId+'\t'+value+"\tLexicalHandler");
  +                    }
  +                    return;
                   }
  -                catch (ClassCastException e) {
  +                //
  +                // http://xml.org/sax/properties/declaration-handler
  +                // Value type: org.xml.sax.ext.DeclHandler
  +                // Access: read/write, pre-parse only
  +                //   Set the DTD declaration event handler.
  +                //
  +                if (property.equals(Constants.DECLARATION_HANDLER_PROPERTY)) {
  +                    try {
  +                        setDeclHandler((DeclHandler)value);
  +                    }
  +                    catch (ClassCastException e) {
  +                        // REVISIT: Localize this error message. -ac
  +                        throw new SAXNotSupportedException(
  +                        "PAR012 For propertyID \""
  +                        +propertyId+"\", the value \""
  +                        +value+"\" cannot be cast to DeclHandler."
  +                        +'\n'+propertyId+'\t'+value+"\tDeclHandler"
  +                        );
  +                    }
  +                    return;
  +                }
  +                //
  +                // http://xml.org/sax/properties/dom-node
  +                // Value type: DOM Node
  +                // Access: read-only
  +                //   Get the DOM node currently being visited, if the SAX parser is
  +                //   iterating over a DOM tree.  If the parser recognises and
  +                //   supports this property but is not currently visiting a DOM
  +                //   node, it should return null (this is a good way to check for
  +                //   availability before the parse begins).
  +                //
  +                if (property.equals(Constants.DOM_NODE_PROPERTY)) {
                       // REVISIT: Localize this error message. -ac
                       throw new SAXNotSupportedException(
  -                    "PAR012 For propertyID \""
  -                    +propertyId+"\", the value \""
  -                    +value+"\" cannot be cast to DeclHandler."
  -                    +'\n'+propertyId+'\t'+value+"\tDeclHandler"
  -                    );
  +                        "PAR013 Property \""+propertyId+"\" is read only."
  +                        +'\n'+propertyId
  +                        ); // read-only property
                   }
  -                return;
  +                //
  +                // Drop through and perform default processing
  +                //
               }
  -            //
  -            // http://xml.org/sax/properties/dom-node
  -            // Value type: DOM Node
  -            // Access: read-only
  -            //   Get the DOM node currently being visited, if the SAX parser is
  -            //   iterating over a DOM tree.  If the parser recognises and
  -            //   supports this property but is not currently visiting a DOM
  -            //   node, it should return null (this is a good way to check for
  -            //   availability before the parse begins).
  -            //
  -            if (property.equals(Constants.DOM_NODE_PROPERTY)) {
  -                // REVISIT: Localize this error message. -ac
  -                throw new SAXNotSupportedException(
  -                    "PAR013 Property \""+propertyId+"\" is read only."
  -                    +'\n'+propertyId
  -                    ); // read-only property
  -            }
  +
               //
  -            // Drop through and perform default processing
  +            // Xerces Properties
               //
  -        }
   
  -        //
  -        // Xerces Properties
  -        //
  +            /*
  +            else if (propertyId.startsWith(XERCES_PROPERTIES_PREFIX)) {
  +                //
  +                // Drop through and perform default processing
  +                //
  +            }
  +            */
   
  -        /*
  -        else if (propertyId.startsWith(XERCES_PROPERTIES_PREFIX)) {
               //
  -            // Drop through and perform default processing
  +            // Perform default processing
               //
  -        }
  -        */
   
  -        //
  -        // Perform default processing
  -        //
  -
  -        try {
               fConfiguration.setProperty(propertyId, value);
           }
           catch (XMLConfigurationException e) {
  @@ -1462,70 +1462,70 @@
       public Object getProperty(String propertyId)
           throws SAXNotRecognizedException, SAXNotSupportedException {
   
  -        //
  -        // SAX2 core properties
  -        //
  +        try {
  +            //
  +            // SAX2 core properties
  +            //
   
  -        if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) {
  -            String property =
  -                propertyId.substring(Constants.SAX_PROPERTY_PREFIX.length());
  -            //
  -            // http://xml.org/sax/properties/lexical-handler
  -            // Value type: org.xml.sax.ext.LexicalHandler
  -            // Access: read/write, pre-parse only
  -            //   Set the lexical event handler.
  -            //
  -            if (property.equals(Constants.LEXICAL_HANDLER_PROPERTY)) {
  -                return getLexicalHandler();
  -            }
  -            //
  -            // http://xml.org/sax/properties/declaration-handler
  -            // Value type: org.xml.sax.ext.DeclHandler
  -            // Access: read/write, pre-parse only
  -            //   Set the DTD declaration event handler.
  -            //
  -            if (property.equals(Constants.DECLARATION_HANDLER_PROPERTY)) {
  -                return getDeclHandler();
  -            }
  -            //
  -            // http://xml.org/sax/properties/dom-node
  -            // Value type: DOM Node
  -            // Access: read-only
  -            //   Get the DOM node currently being visited, if the SAX parser is
  -            //   iterating over a DOM tree.  If the parser recognises and
  -            //   supports this property but is not currently visiting a DOM
  -            //   node, it should return null (this is a good way to check for
  -            //   availability before the parse begins).
  -            //
  -            if (property.equals(Constants.DOM_NODE_PROPERTY)) {
  -                // REVISIT: Localize this error message. -Ac
  -                throw new SAXNotSupportedException(
  -                "PAR014 Cannot getProperty(\""+propertyId
  -                +"\". No DOM Tree exists.\n"+propertyId
  -                ); // we are not iterating a DOM tree
  +            if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) {
  +                String property =
  +                    propertyId.substring(Constants.SAX_PROPERTY_PREFIX.length());
  +                //
  +                // http://xml.org/sax/properties/lexical-handler
  +                // Value type: org.xml.sax.ext.LexicalHandler
  +                // Access: read/write, pre-parse only
  +                //   Set the lexical event handler.
  +                //
  +                if (property.equals(Constants.LEXICAL_HANDLER_PROPERTY)) {
  +                    return getLexicalHandler();
  +                }
  +                //
  +                // http://xml.org/sax/properties/declaration-handler
  +                // Value type: org.xml.sax.ext.DeclHandler
  +                // Access: read/write, pre-parse only
  +                //   Set the DTD declaration event handler.
  +                //
  +                if (property.equals(Constants.DECLARATION_HANDLER_PROPERTY)) {
  +                    return getDeclHandler();
  +                }
  +                //
  +                // http://xml.org/sax/properties/dom-node
  +                // Value type: DOM Node
  +                // Access: read-only
  +                //   Get the DOM node currently being visited, if the SAX parser is
  +                //   iterating over a DOM tree.  If the parser recognises and
  +                //   supports this property but is not currently visiting a DOM
  +                //   node, it should return null (this is a good way to check for
  +                //   availability before the parse begins).
  +                //
  +                if (property.equals(Constants.DOM_NODE_PROPERTY)) {
  +                    // REVISIT: Localize this error message. -Ac
  +                    throw new SAXNotSupportedException(
  +                    "PAR014 Cannot getProperty(\""+propertyId
  +                    +"\". No DOM Tree exists.\n"+propertyId
  +                    ); // we are not iterating a DOM tree
  +                }
  +                //
  +                // Drop through and perform default processing
  +                //
               }
  +
               //
  -            // Drop through and perform default processing
  +            // Xerces properties
               //
  -        }
   
  -        //
  -        // Xerces properties
  -        //
  +            /*
  +            else if (propertyId.startsWith(XERCES_PROPERTIES_PREFIX)) {
  +                //
  +                // Drop through and perform default processing
  +                //
  +            }
  +            */
   
  -        /*
  -        else if (propertyId.startsWith(XERCES_PROPERTIES_PREFIX)) {
               //
  -            // Drop through and perform default processing
  +            // Perform default processing
               //
  -        }
  -        */
   
  -        //
  -        // Perform default processing
  -        //
  -
  -        try {
               return fConfiguration.getProperty(propertyId);
           }
           catch (XMLConfigurationException e) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org