package org.appfuse.webapp.form;

import org.apache.struts.upload.FormFile;


/**
 * This class is modeled after the UploadForm from the struts-upload example
 * application. For more information on implementation details, please
 * see that application.
 *
 * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
 * @version $Revision: 1.6 $ $Date: 2004/03/31 13:04:28 $
 */
public class UploadForm extends BaseForm {
    public static final String ERROR_PROPERTY_MAX_LENGTH_EXCEEDED =
        "org.appfuse.webapp.MaxLengthExceeded";

    /** The value of the text the user has sent as form data */
    protected String name;

    /** The file that the user has uploaded */
    protected FormFile theFile;

    /**
     * Retrieve the name the user has given the uploaded file
     *
     * @return the file's name
     */
    public String getName() {
        return name;
    }

    /**
     * Set the name of the uploaded file (by the user)
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Retrieve a representation of the file the user has uploaded
     *
     * @return FormFile the uploaded file
     */
    public FormFile getTheFile() {
        return theFile;
    }

    /**
     * Set a representation of the file the user has uploaded
     *
     * @param theFile the file to upload
     */
    public void setTheFile(FormFile theFile) {
        this.theFile = theFile;
    }

    /**
     * Check to make sure the client hasn't exceeded the maximum allowed upload size inside of this
     * validate method.
     */

    // Commented out to avoid: Unhandled Exception thrown: class java.lang.NullPointerException

    /*
       public ActionErrors validate(ActionMapping mapping,
                                    HttpServletRequest request) {
           ActionErrors errors = null;
           //has the maximum length been exceeded?
           Boolean maxLengthExceeded =
               (Boolean) request.getAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);
           if ((maxLengthExceeded != null) && (maxLengthExceeded.booleanValue())) {
               errors = new ActionErrors();
               errors.add(ERROR_PROPERTY_MAX_LENGTH_EXCEEDED,
                          new ActionError("maxLengthExceeded"));
           }
           return errors;
       }*/
}