Update of /cvsroot/xdoclet/xdoclet/modules/apache/src/xdoclet/modules/apache/struts
In directory 
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17974/modules/apache/src/xdoclet/modules/apache/struts

Modified Files:
        StrutsValidatorTagsHandler.java 
Added Files:
        StrutsDynaFormValidatorTagsHandler.java 
Log Message:
Added support for validating nested DynaForm properties.

--- NEW FILE: StrutsDynaFormValidatorTagsHandler.java ---
/*
 * Copyright (c) 2001, 2002 The XDoclet team
 * All rights reserved.
 */
package xdoclet.modules.apache.struts;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import xjavadoc.XClass;
import xjavadoc.XMethod;
import xjavadoc.XTag;

import xdoclet.DocletSupport;
import xdoclet.XDocletException;

/**
 * Struts dynamic form validator tag handler.
 *
 * @author               Nick Heudecker (nick at systemmobile dot com)
 * @created              September 27, 2004
 * @xdoclet.taghandler   namespace="DFValidator"
 * @version              $Revision: 1.1 $
 */
public class StrutsDynaFormValidatorTagsHandler extends StrutsValidatorTagsHandler
{

    /**
     * Iterates over all POJOs with dynaform tags and evaluates the body of the tag 
for each class.
     *
     * @param template              The body of the block tag
     * @param attributes            The attributes of the template tag
     * @exception XDocletException
     * @doc.tag                     type="block"
     */
    public void forAllForms(String template, Properties attributes) throws 
XDocletException
    {
        Collection classes = getAllClasses();

        for (Iterator i = classes.iterator(); i.hasNext(); ) {
            XClass currentClass = (XClass) i.next();

            setCurrentClass(currentClass);
            if (DocletSupport.isDocletGenerated(getCurrentClass()) || 
(getCurrentClass().isAbstract())) {
                continue;
            }
            if (currentClass.getDoc().hasTag("struts.dynaform")) {
                XTag tag = currentClass.getDoc().getTag("struts.dynaform");
                String validateAttr = tag.getAttributeValue("validate");

                if ((validateAttr != null) && (validateAttr.equals("true"))) {
                    generate(template);
                }
            }
        }
    }

    /**
     * Gets the "name" attribute for the <form> element in the xml descriptor. 
     *
     * @param attributes         The content tag attributes.
     * @return                   form name
     * @throws XDocletException  if anything goes awry.
     * @doc.tag                  type="content"
     */
    public String formName(Properties attributes) throws XDocletException
    {
        return getTagValue(FOR_CLASS, "struts.dynaform", "name", null, null, false, 
true);
    }

    /**
     * Iterates the body for each field of the current form requiring validation.
     *
     * @param template           The body of the block tag
     * @param attributes         The attributes of the template tag
     * @throws XDocletException
     * @doc.tag                  type="block"
     */
    public void forAllFields(String template, Properties attributes) throws 
XDocletException
    {
        XClass clazz = getCurrentClass();
        Map setters = getFields(clazz);

        for (Iterator iterator = setters.keySet().iterator(); iterator.hasNext(); ) {
            curFieldName = (String) iterator.next();

            XMethod field = (XMethod) setters.get(curFieldName);

            if (field.getDoc().hasTag("struts.validator")) {
                setCurrentMethod(field);
                loadFieldArguments();
                generate(template);
            }
        }
    }

}

Index: StrutsValidatorTagsHandler.java
===================================================================
RCS file: 
/cvsroot/xdoclet/xdoclet/modules/apache/src/xdoclet/modules/apache/struts/StrutsValidatorTagsHandler.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** StrutsValidatorTagsHandler.java     14 Aug 2004 19:41:24 -0000      1.10
--- StrutsValidatorTagsHandler.java     27 Sep 2004 21:51:22 -0000      1.11
***************
*** 37,44 ****
  public class StrutsValidatorTagsHandler extends AbstractProgramElementTagsHandler
  {
!     private final static List supportedTypes = new ArrayList();
!     private String  curFieldName;
!     private String  currentArgKey;
!     private Map     args;
  
      static {
--- 37,44 ----
  public class StrutsValidatorTagsHandler extends AbstractProgramElementTagsHandler
  {
!     protected final static List supportedTypes = new ArrayList();
!     protected String curFieldName;
!     protected String currentArgKey;
!     protected Map   args;
  
      static {
***************
*** 69,73 ****
  
          for (Iterator i = classes.iterator(); i.hasNext(); ) {
!             XClass currentClass = (XClass)i.next();
  
              setCurrentClass(currentClass);
--- 69,73 ----
  
          for (Iterator i = classes.iterator(); i.hasNext(); ) {
!             XClass currentClass = (XClass) i.next();
  
              setCurrentClass(currentClass);
***************
*** 329,338 ****
      }
  
!     private Map getFields(XClass clazz) throws XDocletException
      {
          return getFields(clazz, "");
      }
  
!     private Map getFields(XClass clazz, String prefix) throws XDocletException
      {
          Map fields = new SequencedHashMap();
--- 329,338 ----
      }
  
!     protected Map getFields(XClass clazz) throws XDocletException
      {
          return getFields(clazz, "");
      }
  
!     protected Map getFields(XClass clazz, String prefix) throws XDocletException
      {
          Map fields = new SequencedHashMap();
***************
*** 394,398 ****
      }
  
!     private void loadFieldArguments()
      {
          /*
--- 394,398 ----
      }
  
!     protected void loadFieldArguments()
      {
          /*



-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to