mrglavas    2005/10/03 21:30:25

  Modified:    java/src/org/apache/xerces/impl/dtd XMLDTDValidator.java
                        XMLDTDLoader.java
               java/src/org/apache/xerces/impl Constants.java
  Log:
  Adding a feature which controls whether the syntax trees generated
  while parsing a DTD are balanced. Turning on this feature prevents
  deep recursion for large content models. We could extend this to the
  schema syntax trees in the future.
  
  Revision  Changes    Path
  1.63      +28 -7     
xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java
  
  Index: XMLDTDValidator.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java,v
  retrieving revision 1.62
  retrieving revision 1.63
  diff -u -r1.62 -r1.63
  --- XMLDTDValidator.java      10 May 2005 15:36:42 -0000      1.62
  +++ XMLDTDValidator.java      4 Oct 2005 04:30:24 -0000       1.63
  @@ -97,19 +97,23 @@
   
       /** Feature identifier: namespaces. */
       protected static final String NAMESPACES =
  -    Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
  +        Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
   
       /** Feature identifier: validation. */
       protected static final String VALIDATION =
  -    Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
  +        Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
   
       /** Feature identifier: dynamic validation. */
       protected static final String DYNAMIC_VALIDATION = 
  -    Constants.XERCES_FEATURE_PREFIX + Constants.DYNAMIC_VALIDATION_FEATURE;
  +        Constants.XERCES_FEATURE_PREFIX + 
Constants.DYNAMIC_VALIDATION_FEATURE;
  +    
  +    /** Feature identifier: balance syntax trees. */
  +    protected static final String BALANCE_SYNTAX_TREES =
  +        Constants.XERCES_FEATURE_PREFIX + Constants.BALANCE_SYNTAX_TREES;
   
       /** Feature identifier: warn on duplicate attdef */
       protected static final String WARN_ON_DUPLICATE_ATTDEF = 
  -    Constants.XERCES_FEATURE_PREFIX 
+Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE; 
  +        Constants.XERCES_FEATURE_PREFIX + 
Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE; 
       
        protected static final String PARSER_SETTINGS = 
                Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS;    
  @@ -144,7 +148,8 @@
       private static final String[] RECOGNIZED_FEATURES = {
           NAMESPACES,
           VALIDATION,
  -        DYNAMIC_VALIDATION
  +        DYNAMIC_VALIDATION,
  +        BALANCE_SYNTAX_TREES
       };
   
       /** Feature defaults. */
  @@ -152,6 +157,7 @@
           null,
           null,
           Boolean.FALSE,
  +        Boolean.FALSE,
       };
   
       /** Recognized properties. */
  @@ -206,6 +212,9 @@
        * the validation feature is set to <code>true</code>.
        */
       protected boolean fDynamicValidation;
  +    
  +    /** Controls whether the DTD grammar produces balanced syntax trees. */
  +    protected boolean fBalanceSyntaxTrees;
   
       /** warn on duplicate attribute definition, this feature works only when 
validation is true */
       protected boolean fWarnDuplicateAttdef;
  @@ -469,6 +478,13 @@
           }
           
           try {
  +            fBalanceSyntaxTrees = 
componentManager.getFeature(BALANCE_SYNTAX_TREES);
  +        }
  +        catch (XMLConfigurationException e) {
  +            fBalanceSyntaxTrees = false;
  +        }
  +        
  +        try {
               fWarnDuplicateAttdef = 
componentManager.getFeature(WARN_ON_DUPLICATE_ATTDEF);
           }
           catch (XMLConfigurationException e) {
  @@ -733,7 +749,12 @@
           }
           if(fDTDGrammar == null) {
               // we'll have to create it...
  -            fDTDGrammar = new DTDGrammar(fSymbolTable, grammarDesc);
  +            if (!fBalanceSyntaxTrees) {
  +                fDTDGrammar = new DTDGrammar(fSymbolTable, grammarDesc);
  +            }
  +            else {
  +                fDTDGrammar = new BalancedDTDGrammar(fSymbolTable, 
grammarDesc);
  +            }
           } else {
               // we've found a cached one;so let's make sure not to read
               // any external subset!
  
  
  
  1.12      +51 -13    
xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDLoader.java
  
  Index: XMLDTDLoader.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDLoader.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- XMLDTDLoader.java 4 Oct 2004 21:57:30 -0000       1.11
  +++ XMLDTDLoader.java 4 Oct 2005 04:30:25 -0000       1.12
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999-2004 The Apache Software Foundation.
  + * Copyright 1999-2005 The Apache Software Foundation.
    * 
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -74,13 +74,18 @@
       /** Feature identifier: standard uri conformant feature. */
       protected static final String STANDARD_URI_CONFORMANT_FEATURE =
           Constants.XERCES_FEATURE_PREFIX + 
Constants.STANDARD_URI_CONFORMANT_FEATURE;
  +    
  +    /** Feature identifier: balance syntax trees. */
  +    protected static final String BALANCE_SYNTAX_TREES =
  +        Constants.XERCES_FEATURE_PREFIX + Constants.BALANCE_SYNTAX_TREES;
   
       // recognized features:
  -    private static final String[] RECOGNIZED_FEATURES = {
  +    private static final String[] LOADER_RECOGNIZED_FEATURES = {
           VALIDATION,
           WARN_ON_DUPLICATE_ATTDEF,
           NOTIFY_CHAR_REFS,
  -        STANDARD_URI_CONFORMANT_FEATURE
  +        STANDARD_URI_CONFORMANT_FEATURE,
  +        BALANCE_SYNTAX_TREES
       };
   
       // property identifiers
  @@ -105,6 +110,9 @@
   
       // enforcing strict uri?
       private boolean fStrictURI = false;
  +    
  +    /** Controls whether the DTD grammar produces balanced syntax trees. */
  +    private boolean fBalanceSyntaxTrees = false;
   
       /** Entity resolver . */
       protected XMLEntityResolver fEntityResolver;
  @@ -166,6 +174,15 @@
       } // init(SymbolTable, XMLGrammarPool, XMLErrorReporter, 
XMLEntityResolver)
   
       // XMLGrammarLoader methods
  +    
  +    /**
  +     * Returns a list of feature identifiers that are recognized by
  +     * this component. This method may return null if no features
  +     * are recognized by this component.
  +     */
  +    public String[] getRecognizedFeatures() {
  +        return (String[])(LOADER_RECOGNIZED_FEATURES.clone());
  +    } // getRecognizedFeatures():String[]
   
       /**
        * Sets the state of a feature. This method is called by the component
  @@ -184,15 +201,22 @@
        */
       public void setFeature(String featureId, boolean state)
               throws XMLConfigurationException {
  -        if(featureId.equals(VALIDATION)) {
  +        if (featureId.equals(VALIDATION)) {
               fValidation = state;
  -        } else if(featureId.equals(WARN_ON_DUPLICATE_ATTDEF)) {
  +        } 
  +        else if (featureId.equals(WARN_ON_DUPLICATE_ATTDEF)) {
               fWarnDuplicateAttdef = state;
  -        } else if(featureId.equals(NOTIFY_CHAR_REFS)) {
  +        } 
  +        else if (featureId.equals(NOTIFY_CHAR_REFS)) {
               fDTDScanner.setFeature(featureId, state);
  -        } else if(featureId.equals(STANDARD_URI_CONFORMANT_FEATURE)) {
  +        } 
  +        else if (featureId.equals(STANDARD_URI_CONFORMANT_FEATURE)) {
               fStrictURI = state;
  -        }  else {
  +        }
  +        else if (featureId.equals(BALANCE_SYNTAX_TREES)) {
  +            fBalanceSyntaxTrees = state;
  +        }
  +        else {
               throw new 
XMLConfigurationException(XMLConfigurationException.NOT_RECOGNIZED, featureId);
           }
       } // setFeature(String,boolean)
  @@ -282,13 +306,21 @@
        */
       public boolean getFeature(String featureId) 
               throws XMLConfigurationException {
  -        if(featureId.equals( VALIDATION)) {
  +        if (featureId.equals(VALIDATION)) {
               return fValidation;
  -        } else if(featureId.equals( WARN_ON_DUPLICATE_ATTDEF)) {
  +        } 
  +        else if (featureId.equals(WARN_ON_DUPLICATE_ATTDEF)) {
               return fWarnDuplicateAttdef;
  -        } else if(featureId.equals( NOTIFY_CHAR_REFS)) {
  +        } 
  +        else if (featureId.equals(NOTIFY_CHAR_REFS)) {
               return fDTDScanner.getFeature(featureId);
           }
  +        else if (featureId.equals(STANDARD_URI_CONFORMANT_FEATURE)) {
  +            return fStrictURI;
  +        }
  +        else if (featureId.equals(BALANCE_SYNTAX_TREES)) {
  +            return fBalanceSyntaxTrees;
  +        }
           throw new 
XMLConfigurationException(XMLConfigurationException.NOT_RECOGNIZED, featureId);
       } //getFeature(String):  boolean
   
  @@ -353,7 +385,13 @@
           reset();
           // First chance checking strict URI
           String eid = XMLEntityManager.expandSystemId(source.getSystemId(), 
source.getBaseSystemId(), fStrictURI);
  -        fDTDGrammar = new DTDGrammar(fSymbolTable, new 
XMLDTDDescription(source.getPublicId(), source.getSystemId(), 
source.getBaseSystemId(), eid, null));
  +        XMLDTDDescription desc = new XMLDTDDescription(source.getPublicId(), 
source.getSystemId(), source.getBaseSystemId(), eid, null);
  +        if (!fBalanceSyntaxTrees) {
  +            fDTDGrammar = new DTDGrammar(fSymbolTable, desc);
  +        }
  +        else {
  +            fDTDGrammar = new BalancedDTDGrammar(fSymbolTable, desc);
  +        }
           fGrammarBucket = new DTDGrammarBucket();
           fGrammarBucket.setStandalone(false);
           fGrammarBucket.setActiveGrammar(fDTDGrammar); 
  
  
  
  1.53      +4 -1      xml-xerces/java/src/org/apache/xerces/impl/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/Constants.java,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- Constants.java    17 Jun 2005 22:00:20 -0000      1.52
  +++ Constants.java    4 Oct 2005 04:30:25 -0000       1.53
  @@ -255,6 +255,9 @@
       /** Validate datatypes feature ("validation/validate-datatypes"). */
       public static final String VALIDATE_DATATYPES_FEATURE = 
"validation/validate-datatypes";
       
  +    /** Balanace syntax trees feature ("validation/balance-syntax-trees"). */
  +    public static final String BALANCE_SYNTAX_TREES = 
"validation/balance-syntax-trees";
  +    
       /** Notify character references feature (scanner/notify-char-refs"). */
       public static final String NOTIFY_CHAR_REFS_FEATURE = 
"scanner/notify-char-refs";
       
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to