commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgra...@apache.org
Subject cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator digester-rules.xml ValidatorResourcesInitializer.java
Date Thu, 22 May 2003 00:26:52 GMT
dgraham     2003/05/21 17:26:52

  Modified:    validator/src/share/org/apache/commons/validator
                        ValidatorResourcesInitializer.java
  Added:       validator/src/share/org/apache/commons/validator
                        digester-rules.xml
  Log:
  Moved Digester rule configuration to new digester-rules.xml file instead 
  configuring it with code.
  
  Revision  Changes    Path
  1.16      +10 -141   jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResourcesInitializer.java
  
  Index: ValidatorResourcesInitializer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResourcesInitializer.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- ValidatorResourcesInitializer.java	20 May 2003 02:05:33 -0000	1.15
  +++ ValidatorResourcesInitializer.java	22 May 2003 00:26:52 -0000	1.16
  @@ -68,6 +68,7 @@
   import java.net.URL;
   
   import org.apache.commons.digester.Digester;
  +import org.apache.commons.digester.xmlrules.DigesterLoader;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.xml.sax.SAXException;
  @@ -157,10 +158,12 @@
           boolean process)
           throws IOException {
   
  -        Digester digester = new Digester();
  -        digester.push(resources);
  +        URL rulesUrl = ValidatorResourcesInitializer.class.getResource("digester-rules.xml");
  +        Digester digester = DigesterLoader.createDigester(rulesUrl);
           digester.setNamespaceAware(true);
           digester.setValidating(false);
  +        digester.setUseContextClassLoader(true);
  +        
           // register DTDs
           for (int i = 0; i < registrations.length; i += 2) {
               URL url =
  @@ -171,143 +174,9 @@
               }
           }
   
  -        digester.setUseContextClassLoader(true);
  -
  -        // Create Global Constant objects
  -        digester.addCallMethod(
  -            "form-validation/global/constant",
  -            "addConstantParam",
  -            2);
  -        digester.addCallParam("form-validation/global/constant/constant-name", 0);
  -        digester.addCallParam("form-validation/global/constant/constant-value", 1);
  -        
  -        // Create Global ValidatorAction objects
  -        digester.addObjectCreate(
  -            "form-validation/global/validator",
  -            "org.apache.commons.validator.ValidatorAction",
  -            "className");
  -        digester.addSetProperties("form-validation/global/validator");
  -        digester.addSetNext(
  -            "form-validation/global/validator",
  -            "addValidatorAction",
  -            "org.apache.commons.validator.ValidatorAction");
  -            
  -        // Add the body of a javascript element to the Validatoraction
  -        digester.addCallMethod(
  -            "form-validation/global/validator/javascript",
  -            "setJavascript",
  -            0);
  -
  -        // Create FormSet objects
  -        digester.addObjectCreate(
  -            "form-validation/formset",
  -            "org.apache.commons.validator.FormSet",
  -            "className");
  -        digester.addSetProperties("form-validation/formset");
  -        digester.addSetNext(
  -            "form-validation/formset",
  -            "put",
  -            "org.apache.commons.validator.FormSet");
  -
  -        // Create Constant objects
  -        digester.addCallMethod(
  -            "form-validation/formset/constant",
  -            "addConstantParam",
  -            2);
  -        digester.addCallParam("form-validation/formset/constant/constant-name", 0);
  -        digester.addCallParam("form-validation/formset/constant/constant-value", 1);
  -
  -        // Create Form objects
  -        digester.addObjectCreate(
  -            "form-validation/formset/form",
  -            "org.apache.commons.validator.Form",
  -            "className");
  -        digester.addSetProperties("form-validation/formset/form");
  -        digester.addSetNext(
  -            "form-validation/formset/form",
  -            "addForm",
  -            "org.apache.commons.validator.Form");
  -            
  -        // Create Field objects
  -        digester.addObjectCreate(
  -            "form-validation/formset/form/field",
  -            "org.apache.commons.validator.Field",
  -            "className");
  -        digester.addSetProperties("form-validation/formset/form/field");
  -        digester.addSetNext(
  -            "form-validation/formset/form/field",
  -            "addField",
  -            "org.apache.commons.validator.Field");
  -
  -        // Create Var objects
  -        digester.addCallMethod(
  -            "form-validation/formset/form/field/var",
  -            "addVarParam",
  -            3);
  -        digester.addCallParam("form-validation/formset/form/field/var/var-name", 0);
  -        digester.addCallParam("form-validation/formset/form/field/var/var-value", 1);
  -        digester.addCallParam(
  -            "form-validation/formset/form/field/var/var-jstype",
  -            2);
  -
  -        // Create Msg object
  -        digester.addObjectCreate(
  -            "form-validation/formset/form/field/msg",
  -            "org.apache.commons.validator.Msg",
  -            "className");
  -        digester.addSetProperties("form-validation/formset/form/field/msg");
  -        digester.addSetNext(
  -            "form-validation/formset/form/field/msg",
  -            "addMsg",
  -            "org.apache.commons.validator.Msg");
  -
  -        // Create Arg objects
  -        // Arg0
  -        digester.addObjectCreate(
  -            "form-validation/formset/form/field/arg0",
  -            "org.apache.commons.validator.Arg",
  -            "className");
  -        digester.addSetProperties("form-validation/formset/form/field/arg0");
  -        digester.addSetNext(
  -            "form-validation/formset/form/field/arg0",
  -            "addArg0",
  -            "org.apache.commons.validator.Arg");
  -
  -        // Arg1
  -        digester.addObjectCreate(
  -            "form-validation/formset/form/field/arg1",
  -            "org.apache.commons.validator.Arg",
  -            "className");
  -        digester.addSetProperties("form-validation/formset/form/field/arg1");
  -        digester.addSetNext(
  -            "form-validation/formset/form/field/arg1",
  -            "addArg1",
  -            "org.apache.commons.validator.Arg");
  -
  -        // Arg2
  -        digester.addObjectCreate(
  -            "form-validation/formset/form/field/arg2",
  -            "org.apache.commons.validator.Arg",
  -            "className");
  -        digester.addSetProperties("form-validation/formset/form/field/arg2");
  -        digester.addSetNext(
  -            "form-validation/formset/form/field/arg2",
  -            "addArg2",
  -            "org.apache.commons.validator.Arg");
  -
  -        // Arg3
  -        digester.addObjectCreate(
  -            "form-validation/formset/form/field/arg3",
  -            "org.apache.commons.validator.Arg",
  -            "className");
  -        digester.addSetProperties("form-validation/formset/form/field/arg3");
  -        digester.addSetNext(
  -            "form-validation/formset/form/field/arg3",
  -            "addArg3",
  -            "org.apache.commons.validator.Arg");
  +        digester.push(resources);
   
           try {
  -            // Parse the input stream to initialize our database
               digester.parse(in);
   
           } catch (SAXException e) {
  
  
  
  1.1                  jakarta-commons/validator/src/share/org/apache/commons/validator/digester-rules.xml
  
  Index: digester-rules.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <!--
  	digester-rules.xml defines the rules our Digester will use to transform 
  	validation.xml files into Java objects.
  	
  	$Id$
  -->
  
  
  <!DOCTYPE digester-rules PUBLIC "-//Jakarta Apache //DTD digester-rules XML V1.0//EN"

  	"http://jakarta.apache.org/commons/digester/dtds/digester-rules.dtd">
  
  <digester-rules>
  
  	<pattern value="form-validation/global">
  		
  		<pattern value="constant">
  			<call-method-rule methodname="addConstantParam" paramcount="2" />
  			<call-param-rule pattern="constant-name" paramnumber="0" />
  			<call-param-rule pattern="constant-value" paramnumber="1" />
  		</pattern>
  		
  		<pattern value="validator">	
  			<object-create-rule classname="org.apache.commons.validator.ValidatorAction" />
  			<set-properties-rule/>
  			<set-next-rule methodname="addValidatorAction" paramtype="org.apache.commons.validator.ValidatorAction"
/>
  			<call-method-rule pattern="javascript" methodname="setJavascript" paramcount="0" />
  		</pattern>
  		
  	</pattern>
  	
  	
  	<pattern value="form-validation/formset">
  		<object-create-rule classname="org.apache.commons.validator.FormSet" />
  		<set-properties-rule/>
  		<set-next-rule methodname="addFormSet" paramtype="org.apache.commons.validator.FormSet"
/>
  		
  		<pattern value="constant">
  			<call-method-rule methodname="addConstantParam" paramcount="2" />
  			<call-param-rule pattern="constant-name" paramnumber="0" />
  			<call-param-rule pattern="constant-value" paramnumber="1" />
  		</pattern>
  		
  		<pattern value="form">
  			<object-create-rule classname="org.apache.commons.validator.Form" />
  			<set-properties-rule/>
  			<set-next-rule methodname="addForm" paramtype="org.apache.commons.validator.Form"
/>
  			
  			<pattern value="field">
  				<object-create-rule classname="org.apache.commons.validator.Field" />
  				<set-properties-rule/>
  				<set-next-rule methodname="addField" paramtype="org.apache.commons.validator.Field"
/>
  				
  				<pattern value="var">
  					<call-method-rule methodname="addVarParam" paramcount="3" />
  					<call-param-rule pattern="var-name" paramnumber="0" />
  					<call-param-rule pattern="var-value" paramnumber="1" />
  					<call-param-rule pattern="var-jstype" paramnumber="2" />
  				</pattern>
  				
  				<pattern value="msg">
  					<object-create-rule classname="org.apache.commons.validator.Msg" />
  					<set-properties-rule/>
  					<set-next-rule methodname="addMsg" paramtype="org.apache.commons.validator.Msg"
/>
  				</pattern>
  				
  				<pattern value="arg0">
  					<object-create-rule classname="org.apache.commons.validator.Arg" />
  					<set-properties-rule/>
  					<set-next-rule methodname="addArg0" paramtype="org.apache.commons.validator.Arg"
/>
  				</pattern>
  				<pattern value="arg1">
  					<object-create-rule classname="org.apache.commons.validator.Arg" />
  					<set-properties-rule/>
  					<set-next-rule methodname="addArg1" paramtype="org.apache.commons.validator.Arg"
/>
  				</pattern>
  				<pattern value="arg2">
  					<object-create-rule classname="org.apache.commons.validator.Arg" />
  					<set-properties-rule/>
  					<set-next-rule methodname="addArg2" paramtype="org.apache.commons.validator.Arg"
/>
  				</pattern>
  				<pattern value="arg3">
  					<object-create-rule classname="org.apache.commons.validator.Arg" />
  					<set-properties-rule/>
  					<set-next-rule methodname="addArg3" paramtype="org.apache.commons.validator.Arg"
/>
  				</pattern>
  			
  			</pattern>	
  			
  		</pattern>
  		
  	</pattern>
  </digester-rules>
  
  
  

---------------------------------------------------------------------
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