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.MailingListActions;
19  
20  import org.apache.struts.action.ActionMapping;
21  
22  import javax.servlet.http.HttpServletRequest;
23  
24  import java.util.Map;
25  import java.util.HashMap;
26  /**
27   * Form object used for managing and manipulating mailing lists.
28   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
29   * @version $Revision: 1.2 $
30   *
31   * @struts.form name="mailingListForm"
32   */
33  public class MailingListForm extends JoinForm{
34  
35     // Attributes ---------------------------------------------------------------
36  
37     /** The name of this mailing list */
38     private String name;
39     /** A string representing template for generating messages title */
40     private String msgTitleTemplate;
41     /** A string representing template for generating messages content */
42     private String msgContentTemplate;
43     /** The key of event corresponding to mailing list */
44     private String eventKey;
45     /** The identifier of resource to whom event applies when using mailing list */
46     private String resourceId;
47  
48     /** The identifier of user to manage subscriptions for */
49     private String userId;
50     /**
51      * The map of subscribed lists for the associated user. Keys
52      * are the name of list, values are boolean telling if list is subcribes.
53      */
54     private Map subscribedLists = new HashMap();
55  
56  
57     // Constructors -------------------------------------------------------------
58  
59     /** Creates a new instance of MailingListForm */
60     public MailingListForm(){
61     }
62  
63  
64     // Public -------------------------------------------------------------------
65  
66     /** @return The name identifying this mailing list */
67     public String getName(){
68        return name;
69     }
70     /** @param name The name identifying this mailing list */
71     public void setName(String name){
72        this.name = name;
73     }
74     /** @return A string representing template for generating messages title */
75     public String getMsgTitleTemplate(){
76        return msgTitleTemplate;
77     }
78     /** @param msgTitleTemplate String representing template for title generation */
79     public void setMsgTitleTemplate(String msgTitleTemplate){
80        this.msgTitleTemplate = msgTitleTemplate;
81     }
82     /** @return A string representing template for generating messages content */
83     public String getMsgContentTemplate(){
84        return msgContentTemplate;
85     }
86     /** @param msgContentTemplate String representing template for generating messages content */
87     public void setMsgContentTemplate(String msgContentTemplate){
88        this.msgContentTemplate = msgContentTemplate;
89     }
90  
91     /** @return The key of event corresponding to mailing list */
92     public String getEventKey(){
93        return eventKey;
94     }
95     /** @param eventKey The key of event corresponding to mailing list */
96     public void setEventKey(String eventKey){
97        this.eventKey = eventKey;
98     }
99     /** @return The identifier of resource to whom event applies when using mailing list */
100    public String getResourceId(){
101       return resourceId;
102    }
103    /** @param resourceId The identifier of resource to whom event applies when using mailing list */
104    public void setResourceId(String resourceId){
105       this.resourceId = resourceId;
106    }
107 
108    /** @return The identifier of user to manage subscriptions for */
109    public String getUserId(){
110       return userId;
111    }
112    /** @param userId The identifier of user to manage subscriptions for */
113    public void setUserId(String userId){
114       this.userId = userId;
115    }
116 
117    /** @return Map of list subscribed by user. */
118    public Map getSubscribedLists(){
119       return subscribedLists;
120    }
121    /**
122     * @param key Name of list to get subscription for
123     * @return "on" string if list is subscribed by user, null otherwise
124     */
125    public Object getSubscribedList(String key){
126       return subscribedLists.get(key);
127    }
128    /**
129     * @param key Name of list to set subscription for
130     * @param value Value of subscription ("on" || "off" || boolean value)
131     */
132    public void setSubscribedList(String key, Object value){
133       subscribedLists.put(key, value);
134    }
135 
136 
137    // Implementation of JoinForm -----------------------------------------------
138 
139    /**
140     * Validate form attributes.
141     * @param operation String representing the operation to invoke on Action
142     * @param mapping Mapping between forwards name and path for this action
143     * @param request The servlet container request wrapper
144     */
145    public void doValidate(String operation, ActionMapping mapping, HttpServletRequest request){
146 
147       if (MailingListActions.LOAD_OP.equals(operation)){
148          // Check and see if name is missing.
149          if (name == null || name.length() == 0)
150             addActionError("errors.required", getGuiMessageResources().getMessage("label.mailinglist.name"));
151       }
152       else if (MailingListActions.SAVE_OP.equals(operation)){
153          // Check and see if name is missing.
154          if (name == null || name.length() == 0)
155             addActionError("errors.required", getGuiMessageResources().getMessage("label.mailinglist.name"));
156          // Check and see if title template is missing.
157          if (msgTitleTemplate == null || msgTitleTemplate.length() == 0)
158             addActionError("errors.required", getGuiMessageResources().getMessage("label.mailinglist.msgTitleTemplate"));
159          // Check and see if content template is missing.
160          if (msgContentTemplate == null || msgContentTemplate.length() == 0)
161             addActionError("errors.required", getGuiMessageResources().getMessage("label.mailinglist.msgContentTemplate"));
162          // Check and see if event key is missing.
163          if (eventKey == null | eventKey.length() == 0)
164             addActionError("errors.required", getGuiMessageResources().getMessage("label.mailinglist.event"));
165       }
166       else if (MailingListActions.SUBSCRIBE_OP.equals(operation)){
167          // Check and see if userId is missing.
168          if (userId == null || userId.length() == 0)
169             addActionError("errors.required", getGuiMessageResources().getMessage("label.mailingList.subscriberId"));
170       }
171    }
172 
173 
174    // Override of ActionForm ---------------------------------------------------
175 
176    /**
177     * Reset form attributes.
178     * @param mapping Mapping between forwards name and path for this action
179     * @param request The servlet container request wrapper
180     */
181    public void reset(ActionMapping mapping, HttpServletRequest request){
182       super.reset(mapping, request);
183       name = null;
184       msgTitleTemplate = null;
185       msgContentTemplate = null;
186       eventKey = null;
187       resourceId = null;
188       userId = null;
189       subscribedLists = new HashMap();
190    }
191 }
192