commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skitch...@apache.org
Subject cvs commit: jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules DigesterRuleParser.java FromXmlRuleSet.java
Date Fri, 02 Apr 2004 07:59:04 GMT
skitching    2004/04/01 23:59:04

  Modified:    digester/src/java/org/apache/commons/digester/xmlrules Tag:
                        DIGESTER_PLUGIN_REFACTORING_BRANCH
                        DigesterRuleParser.java FromXmlRuleSet.java
  Log:
  Add new (minor) xmlrules feature which allows new rules to
  be loaded with a specified pattern prefix.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.26.2.1  +21 -2     jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.java
  
  Index: DigesterRuleParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.java,v
  retrieving revision 1.26
  retrieving revision 1.26.2.1
  diff -u -r1.26 -r1.26.2.1
  --- DigesterRuleParser.java	28 Feb 2004 13:32:53 -0000	1.26
  +++ DigesterRuleParser.java	2 Apr 2004 07:59:04 -0000	1.26.2.1
  @@ -76,7 +76,9 @@
        * from the Rules XML document.
        */
       protected Digester targetDigester;
  -    
  +
  +    /** See {@link #setBasePath}. */
  +    protected String basePath = "";
       
       /**
        * A stack whose toString method returns a '/'-separated concatenation
  @@ -155,6 +157,22 @@
       }
       
       /**
  +     * Set a base pattern beneath which all the rules loaded by this
  +     * object will be registered. If this string is not empty, and does
  +     * not end in a "/", then one will be added.
  +     */
  +    public void setBasePath(String path) {
  +        if (path == null) {
  +            basePath = "";
  +        }
  +        else if ((path.length() > 0) && !path.endsWith("/")) {
  +            basePath = path + "/";
  +        } else {
  +            basePath = path;
  +        }
  +    }
  +
  +    /**
        * Sets the location of the digester rules DTD. This is the DTD used
        * to validate the rules XML file.
        */
  @@ -181,7 +199,8 @@
        * @param rule a Rule to add to the target digester.
        */
       public void add(Rule rule) {
  -        targetDigester.addRule(patternStack.toString(), rule);
  +        targetDigester.addRule(
  +            basePath + patternStack.toString(), rule);
       }
       
       
  
  
  
  1.12.2.1  +23 -0     jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/FromXmlRuleSet.java
  
  Index: FromXmlRuleSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/FromXmlRuleSet.java,v
  retrieving revision 1.12
  retrieving revision 1.12.2.1
  diff -u -r1.12 -r1.12.2.1
  --- FromXmlRuleSet.java	28 Feb 2004 13:32:53 -0000	1.12
  +++ FromXmlRuleSet.java	2 Apr 2004 07:59:04 -0000	1.12.2.1
  @@ -138,6 +138,28 @@
        * @see org.apache.commons.digester.RuleSetBase
        */
       public void addRuleInstances(org.apache.commons.digester.Digester digester) throws
XmlLoadException {
  +        addRuleInstances(digester, null);
  +    }
  +    
  +    /**
  +     * Adds to the digester the set of Rule instances defined in the
  +     * XML file for this rule set.
  +     * <p>
  +     * Note that this method doesn't have a matching one on the DigesterLoader
  +     * class, because it is not expected to be widely used, and DigesterLoader's
  +     * load method is already heavily overloaded.
  +     *
  +     * @param digester is the digester that rules will be added to.
  +     * @param basePath is a path that will be prefixed to every
  +     * pattern string defined in the xmlrules input file.
  +     *
  +     * @see org.apache.commons.digester.RuleSetBase
  +     */
  +    public void addRuleInstances(
  +    org.apache.commons.digester.Digester digester,
  +    String basePath) 
  +    throws XmlLoadException {
  +        
           URL dtdURL = getClass().getClassLoader().getResource(DIGESTER_DTD_PATH);
           if (dtdURL == null) {
               throw new XmlLoadException("Cannot find resource \"" +
  @@ -145,6 +167,7 @@
           }
           parser.setDigesterRulesDTD(dtdURL.toString());
           parser.setTarget(digester);
  +        parser.setBasePath(basePath);
   
           rulesDigester.addRuleSet(parser);
           rulesDigester.push(parser);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message