View Javadoc

1   /**
2    * Copyright 2005-2006 the original author or authors.
3    *
4    * Licensed under the Gnu General Pubic License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    *
8    *      http://www.opensource.org/licenses/gpl-license.php
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13   * See the Gnu General Public License for more details.
14   */
15  package org.figure8.join.control.form;
16  
17  import org.figure8.join.control.JoinForm;
18  import org.figure8.join.control.action.ResourceUpdateActions;
19  
20  import org.apache.struts.action.ActionMapping;
21  
22  import javax.servlet.http.HttpServletRequest;
23  /**
24   * Form object used for requesting resource updates.
25   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
26   * @version $Revision: 1.1 $
27   *
28   * @struts.form name="resourceUpdateForm"
29   */
30  public class ResourceUpdateForm extends JoinForm{
31  
32     // Attributes ---------------------------------------------------------------
33  
34     /** The name of resource to update */
35     private String resourceName;
36     /** The name of resource version to apply */
37     private String resourceVersionName;
38  
39  
40     // Constructors -------------------------------------------------------------
41  
42     /** Creates a new instance of ResourceUpdateForm */
43     public ResourceUpdateForm(){
44     }
45  
46  
47     // Public -------------------------------------------------------------------
48  
49     /** @return The name of resource to update */
50     public String getResourceName(){
51        return resourceName;
52     }
53     /** @param resourceName The name of resource to update */
54     public void setResourceName(String resourceName){
55        this.resourceName = resourceName;
56     }
57  
58     /** @return The name of resource version to apply */
59     public String getResourceVersionName(){
60        return resourceVersionName;
61     }
62     /** @param resourceVersionName The name of resource version to apply */
63     public void setResourceVersionName(String resourceVersionName){
64        this.resourceVersionName = resourceVersionName;
65     }
66  
67  
68     // Implementation of JoinForm -----------------------------------------------
69  
70     /**
71      * Validate form attributes.
72      * @param operation String representing the operation to invoke on Action
73      * @param mapping Mapping between forwards name and path for this action
74      * @param request The servlet container request wrapper
75      */
76     public void doValidate(String operation, ActionMapping mapping, HttpServletRequest request){
77        // Check attributes depending on operation.
78        if (ResourceUpdateActions.FORM_OP.equals(operation)){
79           // Check if resource name is missing.
80           if (resourceName == null || resourceName.length() == 0)
81              addActionError("errors.required", getGuiMessageResources().getMessage("label.resource"));
82        }
83        else if (ResourceUpdateActions.SAVE_OP.equals(operation)){
84           // Check if resource name is missing.
85           if (resourceName == null || resourceName.length() == 0)
86              addActionError("errors.required", getGuiMessageResources().getMessage("label.resource"));
87           // Check if resource version name is missing.
88           if (resourceVersionName == null || resourceVersionName.length() == 0)
89              addActionError("errors.required", getGuiMessageResources().getMessage("label.resourceversion"));
90        }
91     }
92  
93  
94     // Override of ActionForm ---------------------------------------------------
95  
96     /**
97      * Reset form attributes.
98      * @param mapping Mapping between forwards name and path for this action
99      * @param request The servlet container request wrapper
100     */
101    public void reset(ActionMapping mapping, HttpServletRequest request){
102       super.reset(mapping, request);
103       // Reset form attributes.
104       resourceName = null;
105       resourceVersionName = null;
106    }
107 }