Update of /cvsroot/xdoclet/xdoclet/modules/spring/src/xdoclet/modules/spring
In directory 
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11989/xdoclet/modules/spring/src/xdoclet/modules/spring

Modified Files:
        SpringValidationXmlSubTask.java 
        SpringValidatorTagsHandler.java 
Log Message:
Updated Commons Validator support for 1.1.3, validation-forms.xml merge file 
and indexed properties (XDT-1593)

Index: SpringValidationXmlSubTask.java
===================================================================
RCS file: 
/cvsroot/xdoclet/xdoclet/modules/spring/src/xdoclet/modules/spring/SpringValidationXmlSubTask.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** SpringValidationXmlSubTask.java     29 Apr 2004 18:35:22 -0000      1.1
--- SpringValidationXmlSubTask.java     13 Jan 2006 00:46:46 -0000      1.2
***************
*** 9,15 ****
  
  /**
!  * Generates Struts Validator validation.xml deployment descriptor.
   *
!  * @author               Erik Hatcher ([EMAIL PROTECTED])
   * @created              August 23, 2002
   * @ant.element          display-name="validation.xml" 
name="springvalidationxml"
--- 9,15 ----
  
  /**
!  * Generates Commons Validator validation.xml deployment descriptor for 
Spring.
   *
!  * @author               Matt Raible ([EMAIL PROTECTED])
   * @created              August 23, 2002
   * @ant.element          display-name="validation.xml" 
name="springvalidationxml"
***************
*** 18,33 ****
   * @xdoclet.merge-file   file="validation-global.xml" 
relates-to="validation.xml" description="An XML unparsed entity
   *      containing the global elements for the validation descriptor."
   */
  public class SpringValidationXmlSubTask extends XmlSubTask
  {
!     private final static String DTD_FILE_NAME_11 = 
"resources/validation_1_1.dtd";
!     private final static String VALIDATION_PUBLICID_11 = "-//Apache Software 
Foundation//DTD Commons Validator Rules Configuration 1.1//EN";
!     private final static String VALIDATION_SYSTEMID_11 = 
"http://jakarta.apache.org/commons/dtds/validator_1_1.dtd";;
  
      private static String DEFAULT_TEMPLATE_FILE = 
"resources/validation_xml.xdt";
!     private static String GENERATED_FILE_NAME = "validation.xml";
  
      /**
!      * Describe what the StrutsValidationXmlSubTask constructor does
       */
      public SpringValidationXmlSubTask()
--- 18,40 ----
   * @xdoclet.merge-file   file="validation-global.xml" 
relates-to="validation.xml" description="An XML unparsed entity
   *      containing the global elements for the validation descriptor."
+  * @xdoclet.merge-file   file="validation-forms.xml" 
relates-to="validation.xml" description="An XML unparsed entity
+  *      containing form validations."
   */
  public class SpringValidationXmlSubTask extends XmlSubTask
  {
!     protected final static String DTD_FILE_NAME_11 = 
"resources/validation_1_1.dtd";
!     protected final static String VALIDATION_PUBLICID_11 = "-//Apache 
Software Foundation//DTD Commons Validator Rules Configuration 1.1//EN";
!     protected final static String VALIDATION_SYSTEMID_11 = 
"http://jakarta.apache.org/commons/dtds/validator_1_1.dtd";;
! 
!     protected final static String DTD_FILE_NAME_113 = 
"resources/validation_1_1_3.dtd";
!     protected final static String VALIDATION_PUBLICID_113 = "-//Apache 
Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN";
!     protected final static String VALIDATION_SYSTEMID_113 = 
"http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd";;
!     protected static String GENERATED_FILE_NAME = "validation.xml";
  
      private static String DEFAULT_TEMPLATE_FILE = 
"resources/validation_xml.xdt";
!     protected String version = "1.1";
  
      /**
!      * Describe what the SpringValidationXmlSubTask constructor does
       */
      public SpringValidationXmlSubTask()
***************
*** 35,41 ****
          setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
          setDestinationFile(GENERATED_FILE_NAME);
!         setPublicId(VALIDATION_PUBLICID_11);
!         setSystemId(VALIDATION_SYSTEMID_11);
!         setDtdURL(getClass().getResource(DTD_FILE_NAME_11));
      }
  
--- 42,66 ----
          setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
          setDestinationFile(GENERATED_FILE_NAME);
!     }
! 
!     /**
!      * Gets the Version attribute of the task tag.
!      *
!      * @return   The Version value
!      */
!     public String getVersion()
!     {
!         return this.version;
!     }
! 
!     /**
!      * Sets the validator version to use. Legal values are "1.1" and "1.1.3".
!      *
!      * @param version
!      * @ant.not-required   No. Default is "1.1".
!      */
!     public void setVersion(String version)
!     {
!         this.version = version;
      }
  
***************
*** 44,51 ****
       *
       * @exception XDocletException
-      * @todo                        is this method even needed here?
       */
      public void execute() throws XDocletException
      {
          startProcess();
      }
--- 69,85 ----
       *
       * @exception XDocletException
       */
      public void execute() throws XDocletException
      {
+         if (version.equals("1.1")) {
+             setPublicId(VALIDATION_PUBLICID_11);
+             setSystemId(VALIDATION_SYSTEMID_11);
+             setDtdURL(getClass().getResource(DTD_FILE_NAME_11));
+         }
+         else {
+             setPublicId(VALIDATION_PUBLICID_113);
+             setSystemId(VALIDATION_SYSTEMID_113);
+             setDtdURL(getClass().getResource(DTD_FILE_NAME_113));
+         }
          startProcess();
      }

Index: SpringValidatorTagsHandler.java
===================================================================
RCS file: 
/cvsroot/xdoclet/xdoclet/modules/spring/src/xdoclet/modules/spring/SpringValidatorTagsHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** SpringValidatorTagsHandler.java     16 Oct 2004 19:37:12 -0000      1.3
--- SpringValidatorTagsHandler.java     13 Jan 2006 00:46:46 -0000      1.4
***************
*** 23,26 ****
--- 23,27 ----
  import xdoclet.tagshandler.AbstractProgramElementTagsHandler;
  import xdoclet.tagshandler.MethodTagsHandler;
+ import xdoclet.util.Translator;
  
  /**
***************
*** 34,41 ****
  public class SpringValidatorTagsHandler extends 
AbstractProgramElementTagsHandler
  {
!     private final static List supportedTypes = new ArrayList();
!     private String  curFieldName;
!     private String  currentArgKey;
!     private Map     args;
  
      static {
--- 35,42 ----
  public class SpringValidatorTagsHandler extends 
AbstractProgramElementTagsHandler
  {
!     protected final static List supportedTypes = new ArrayList();
!     protected String curFieldName;
!     protected String currentArgKey;
!     protected Map   args;
  
      static {
***************
*** 110,115 ****
       * Current argument index number (0 to 3).
       *
!      * @param props  The attributes of the template tag
!      * @return       argument index
       * @doc.tag      type="content"
       */
--- 111,116 ----
       * Current argument index number (0 to 3).
       *
!      * @param props  The content tag attributes.
!      * @return       current argument index
       * @doc.tag      type="content"
       */
***************
*** 122,127 ****
       * Current argument name - only valid if argument is for a specific 
validator type.
       *
!      * @param props  The attributes of the template tag
!      * @return       argument name
       * @doc.tag      type="content"
       */
--- 123,128 ----
       * Current argument name - only valid if argument is for a specific 
validator type.
       *
!      * @param props  The content tag attributes.
!      * @return       current argument name
       * @doc.tag      type="content"
       */
***************
*** 136,141 ****
       * Current argument value, which is either an inline value or resource 
key.
       *
!      * @param props  The attributes of the template tag
!      * @return       argument value
       * @doc.tag      type="content"
       */
--- 137,142 ----
       * Current argument value, which is either an inline value or resource 
key.
       *
!      * @param props  The content tag attributes.
!      * @return       current argument value
       * @doc.tag      type="content"
       */
***************
*** 221,224 ****
--- 222,240 ----
  
      /**
+      * Evaluates the body if the current field has an indexed component.
+      *
+      * @param template           The body of the block tag
+      * @param attributes         The attributes of the template tag
+      * @throws XDocletException
+      * @doc.tag                  type="block"
+      */
+     public void ifFieldIsIndexed(String template, Properties attributes) 
throws XDocletException
+     {
+         if (curFieldName.indexOf("[]") >= 0) {
+             generate(template);
+         }
+     }
+ 
+     /**
       * Iterates the body for each field of the current form requiring 
validation.
       *
***************
*** 245,257 ****
  
      /**
!      * Returns the current fields name.
       *
!      * @param props  The attributes of the template tag
!      * @return       current field's name
       * @doc.tag      type="content"
       */
      public String fieldName(Properties props)
      {
!         return curFieldName;
      }
  
--- 261,300 ----
  
      /**
!      * Returns the current field's name, local to the indexed property if 
there is one.
       *
!      * @param props  The content tag attributes.
!      * @return       current field name
       * @doc.tag      type="content"
       */
      public String fieldName(Properties props)
      {
!         int listIdx = curFieldName.indexOf("[]");
! 
!         if (listIdx == -1)
!             return curFieldName;
! 
!         String result = curFieldName.substring(listIdx + 3);
! 
!         if (result.length() == 0)
!             return curFieldName.substring(0, listIdx);
! 
!         return result;
!     }
! 
!     /**
!      * Returns the current field's indexedListProperty attribute, if any.
!      *
!      * @param props  The content tag attributes.
!      * @return       current field's indexedListProperty
!      * @doc.tag      type="content"
!      */
!     public String indexedListProperty(Properties props)
!     {
!         int listIdx = curFieldName.indexOf("[]");
! 
!         if (listIdx == -1)
!             return "";
! 
!         return curFieldName.substring(0, listIdx);
      }
  
***************
*** 259,264 ****
       * Returns a comma-separated list of the specified validator types.
       *
!      * @param props  The attributes of the template tag
!      * @return       validator type list
       * @doc.tag      type="content"
       */
--- 302,307 ----
       * Returns a comma-separated list of the specified validator types.
       *
!      * @param props  The content tag attributes.
!      * @return       validator types list
       * @doc.tag      type="content"
       */
***************
*** 280,289 ****
      }
  
!     private Map getFields(XClass clazz) throws XDocletException
      {
          return getFields(clazz, "");
      }
  
!     private Map getFields(XClass clazz, String prefix) throws XDocletException
      {
          Map fields = new SequencedHashMap();
--- 323,332 ----
      }
  
!     protected Map getFields(XClass clazz) throws XDocletException
      {
          return getFields(clazz, "");
      }
  
!     protected Map getFields(XClass clazz, String prefix) throws 
XDocletException
      {
          Map fields = new SequencedHashMap();
***************
*** 296,313 ****
          // only requires a getter.
          for (Iterator iterator = curFields.iterator(); iterator.hasNext(); ) {
!             XMethod setter = (XMethod) iterator.next();
  
!             if (MethodTagsHandler.isSetterMethod(setter)) {
!                 if (setter.getDoc().getTag("spring.validator") != null) {
!                     String name = 
MethodTagsHandler.getPropertyNameFor(setter);
!                     XParameter param = (XParameter) 
setter.getParameters().iterator().next();
!                     String type = param.getType().getQualifiedName();
  
!                     if (supportedTypes.contains(type)) {
!                         fields.put(prefix + name, setter);
!                     }
!                     else {
!                         fields.putAll(getFields(param.getType(), prefix + 
(prefix.length() == 0 ? "" : ".") + name + "."));
                      }
                  }
              }
--- 339,393 ----
          // only requires a getter.
          for (Iterator iterator = curFields.iterator(); iterator.hasNext(); ) {
!             XMethod method = (XMethod) iterator.next();
!             XTag tag = method.getDoc().getTag("spring.validator");
!             String override = null;
! 
!             if (tag != null) {
!                 override = tag.getAttributeValue("override");
!             }
  
!             if (tag != null) {
!                 List params = method.getParameters();
!                 String name = method.getPropertyName();
!                 XParameter param = null;
  
!                 if (MethodTagsHandler.isSetterMethod(method)) {
!                     param = (XParameter) params.get(0);
!                 }
!                 else if (params.size() == 2) {
!                     // Check for indexed setter setBlah(int index, <type> 
value)
!                     if (!MethodTagsHandler.isSetter(method.getName()))
!                         continue;
! 
!                     Iterator paramIter = params.iterator();
! 
!                     if (!((XParameter) paramIter.next()).getType().isA("int"))
!                         continue;
! 
!                     if (name.indexOf("[]") >= 0) {
!                         throw new 
XDocletException(Translator.getString(SpringValidatorMessages.class,
!                             SpringValidatorMessages.ONLY_ONE_LEVEL_LIST_PROPS,
!                             new String[]{clazz.getName() + '.' + name + 
"[]"}));
                      }
+ 
+                     name = name + "[]";
+                     param = (XParameter) paramIter.next();
+                 }
+                 else
+                     continue;
+ 
+                 String type = param.getType().getQualifiedName();
+ 
+                 if (supportedTypes.contains(type)) {
+                     fields.put(prefix + name, method);
+                 }
+                 else if ((override != null) && (override.equals("true"))) {
+                     fields.put(prefix + name, method);
+                 }
+                 else {
+ 
+                     boolean preDot = (prefix.length() > 0 && 
prefix.charAt(prefix.length() - 1) != '.');
+ 
+                     fields.putAll(getFields(param.getType(), prefix + (preDot 
? "." : "") + name + "."));
                  }
              }
***************
*** 317,321 ****
      }
  
!     private void loadFieldArguments()
      {
          /*
--- 397,401 ----
      }
  
!     protected void loadFieldArguments()
      {
          /*
***************
*** 324,328 ****
           * I simply store them into a Map with the value being the value
           * from the parameter.  The name, however, represents the argument
!          * index, whether its a resource or an inline value, and whether it
           * is attached to a particular validator type.  The name format is:
           * argN[resource|value][_TYPE]
--- 404,408 ----
           * I simply store them into a Map with the value being the value
           * from the parameter.  The name, however, represents the argument
!          * index, whether it's a resource or an inline value, and whether it
           * is attached to a particular validator type.  The name format is:
           * argN[resource|value][_TYPE]



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
xdoclet-devel mailing list
xdoclet-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to