You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2005/06/19 23:29:41 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/jaxp DocumentBuilderFactoryImpl.java DocumentBuilderImpl.java

mrglavas    2005/06/19 14:29:41

  Modified:    java/src/org/apache/xerces/jaxp
                        DocumentBuilderFactoryImpl.java
                        DocumentBuilderImpl.java
  Log:
  Support DocumentBuilderFactory.setFeature/getFeature for all existing Xerces features.
  
  Revision  Changes    Path
  1.18      +37 -10    xml-xerces/java/src/org/apache/xerces/jaxp/DocumentBuilderFactoryImpl.java
  
  Index: DocumentBuilderFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/jaxp/DocumentBuilderFactoryImpl.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- DocumentBuilderFactoryImpl.java	10 Jun 2005 03:20:41 -0000	1.17
  +++ DocumentBuilderFactoryImpl.java	19 Jun 2005 21:29:41 -0000	1.18
  @@ -28,6 +28,8 @@
   import org.apache.xerces.parsers.DOMParser;
   import org.apache.xerces.util.SAXMessageFormatter;
   import org.xml.sax.SAXException;
  +import org.xml.sax.SAXNotRecognizedException;
  +import org.xml.sax.SAXNotSupportedException;
   
   /**
    * @author Rajiv Mordani
  @@ -37,6 +39,7 @@
   public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory {
       /** These are DocumentBuilderFactory attributes not DOM attributes */
       private Hashtable attributes;
  +    private Hashtable features;
       private Schema grammar;
       private boolean isXIncludeAware;
       
  @@ -53,7 +56,7 @@
           throws ParserConfigurationException 
       {
           try {
  -            return new DocumentBuilderImpl(this, attributes, fSecureProcess);
  +            return new DocumentBuilderImpl(this, attributes, features, fSecureProcess);
           } catch (SAXException se) {
               // Handles both SAXNotSupportedException, SAXNotRecognizedException
               throw new ParserConfigurationException(se.getMessage());
  @@ -90,7 +93,7 @@
   
           // Test the attribute name by possibly throwing an exception
           try {
  -            new DocumentBuilderImpl(this, attributes);
  +            new DocumentBuilderImpl(this, attributes, features);
           } catch (Exception e) {
               attributes.remove(name);
               throw new IllegalArgumentException(e.getMessage());
  @@ -117,7 +120,7 @@
               // We create a dummy DocumentBuilderImpl in case the attribute
               // name is not one that is in the attributes hashtable.
               domParser =
  -                new DocumentBuilderImpl(this, attributes).getDOMParser();
  +                new DocumentBuilderImpl(this, attributes, features).getDOMParser();
               return domParser.getProperty(name);
           } catch (SAXException se1) {
               // assert(name is not recognized or not supported), try feature
  @@ -153,9 +156,20 @@
           if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
               return fSecureProcess;
           }
  -        throw new ParserConfigurationException(
  -                SAXMessageFormatter.formatMessage(Locale.getDefault(), 
  -                        "feature-not-supported", new Object [] {name}));
  +        // See if it's in the features Hashtable
  +        if (features != null) {
  +            Object val = features.get(name);
  +            if (val != null) {
  +                return ((Boolean) val).booleanValue();
  +            }
  +        }
  +        try {
  +            DOMParser domParser = new DocumentBuilderImpl(this, attributes, features).getDOMParser();
  +            return domParser.getFeature(name);
  +        }
  +        catch (SAXException e) {
  +            throw new ParserConfigurationException(e.getMessage());
  +        }
       }
       
       public void setFeature(String name, boolean value) 
  @@ -165,8 +179,21 @@
               fSecureProcess = value;
               return;
           }
  -        throw new ParserConfigurationException(
  -                SAXMessageFormatter.formatMessage(Locale.getDefault(), 
  -                        "feature-not-supported", new Object [] {name}));
  +        if (features == null) {
  +            features = new Hashtable();
  +        }
  +        features.put(name, value ? Boolean.TRUE : Boolean.FALSE);
  +        // Test the feature by possibly throwing SAX exceptions
  +        try {
  +            new DocumentBuilderImpl(this, attributes, features);
  +        } 
  +        catch (SAXNotSupportedException e) {
  +            features.remove(name);
  +            throw new ParserConfigurationException(e.getMessage());
  +        } 
  +        catch (SAXNotRecognizedException e) {
  +            features.remove(name);
  +            throw new ParserConfigurationException(e.getMessage());
  +        }
       }
   }
  
  
  
  1.30      +19 -4     xml-xerces/java/src/org/apache/xerces/jaxp/DocumentBuilderImpl.java
  
  Index: DocumentBuilderImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/jaxp/DocumentBuilderImpl.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- DocumentBuilderImpl.java	19 Jun 2005 17:12:22 -0000	1.29
  +++ DocumentBuilderImpl.java	19 Jun 2005 21:29:41 -0000	1.30
  @@ -90,12 +90,12 @@
       /** Initial EntityResolver */
       private final EntityResolver fInitEntityResolver;
       
  -    DocumentBuilderImpl(DocumentBuilderFactoryImpl dbf, Hashtable dbfAttrs)
  +    DocumentBuilderImpl(DocumentBuilderFactoryImpl dbf, Hashtable dbfAttrs, Hashtable features)
           throws SAXNotRecognizedException, SAXNotSupportedException {
  -        this(dbf, dbfAttrs, false);
  +        this(dbf, dbfAttrs, features, false);
       }
   
  -    DocumentBuilderImpl(DocumentBuilderFactoryImpl dbf, Hashtable dbfAttrs, boolean secureProcessing)
  +    DocumentBuilderImpl(DocumentBuilderFactoryImpl dbf, Hashtable dbfAttrs, Hashtable features, boolean secureProcessing)
           throws SAXNotRecognizedException, SAXNotSupportedException
       {
           domParser = new DOMParser();
  @@ -140,11 +140,26 @@
           
           this.grammar = dbf.getSchema();
   
  +        // Set features
  +        setFeatures(features);
  +        
  +        // Set attributes
           setDocumentBuilderFactoryAttributes(dbfAttrs);
           
           // Initial EntityResolver
           fInitEntityResolver = domParser.getEntityResolver();
       }
  +    
  +    private 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();
  +                domParser.setFeature(feature, value);
  +            }
  +        }
  +    }
   
       /**
        * Set any DocumentBuilderFactory attributes of our underlying DOMParser
  
  
  

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