KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > clipbuilder > html > struts > DescriptionClipperAction


1 package org.jahia.clipbuilder.html.struts;
2
3 import org.apache.struts.action.*;
4 import org.jahia.clipbuilder.html.struts.Util.*;
5 import javax.servlet.http.*;
6 import java.util.*;
7 import org.jahia.clipbuilder.html.bean.ClipperBean;
8 import org.jahia.clipbuilder.html.web.Url.*;
9 import org.jahia.clipbuilder.html.*;
10 import java.net.URL JavaDoc;
11 import java.net.MalformedURLException JavaDoc;
12
13 /**
14  * Description of the Class
15  *
16  *@author Tlili Khaled
17  */

18 public class DescriptionClipperAction extends AbstractWizardAction {
19     private boolean errorHasOccured = false;
20     private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(DescriptionClipperAction.class);
21
22
23     /**
24      * Gets the KeyMethodMap attribute of the DescriptionClipperAction object
25      *
26      *@return The KeyMethodMap value
27      */

28     public Map getKeyMethodMap() {
29         Map map = super.getKeyMethodMap();
30         map.put("wizard.description", "view");
31         map.put("button.next", "goToBrowse");
32         map.put("description.button.reset", "init");
33         map.put("description.button.configure", "configure");
34         map.put("button.description.update", "update");
35         return map;
36     }
37
38
39
40     /**
41      * Gets the FormId attribute of the DescriptionClipperAction object
42      *
43      *@return The FormId value
44      */

45     public int getFormId() {
46         return Constants.DESCRIPTION;
47     }
48
49
50     /**
51      * Description of the Method
52      *
53      *@param actionMapping Description of Parameter
54      *@param actionForm Description of Parameter
55      *@param request Description of Parameter
56      *@param httpServletResponse Description of Parameter
57      *@return Description of the Returned Value
58      */

59     public ActionForward goToBrowse(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse httpServletResponse) {
60         logger.debug("[ Validate and go to browse ]");
61         DescriptionClipperForm form = (DescriptionClipperForm) actionForm;
62         boolean foundError = lookForErrors(request, form);
63         if (foundError) {
64             return actionMapping.getInputForward();
65         }
66
67         //init Wizard
68
updateSessionAttributes(request, Constants.DESCRIPTION);
69         logger.debug("add sourceUrl ");
70
71
72         //request.getSession().setAttribute(Constants.BROWSE_FORM, new BrowseForm());
73

74
75         return actionMapping.findForward("browseInit");
76     }
77
78
79     /**
80      * Description of the Method
81      *
82      *@param actionMapping Description of Parameter
83      *@param actionForm Description of Parameter
84      *@param httpServletRequest Description of Parameter
85      *@param httpServletResponse Description of Parameter
86      *@return Description of the Returned Value
87      */

88     public ActionForward configure(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
89         logger.debug("[ Configure webClipper builder ]");
90         return actionMapping.findForward("configure");
91     }
92
93
94
95     /**
96      * Description of the Method
97      *
98      *@param actionMapping Description of Parameter
99      *@param actionForm Description of Parameter
100      *@param httpServletRequest Description of Parameter
101      *@param httpServletResponse Description of Parameter
102      *@return Description of the Returned Value
103      */

104     public ActionForward reset(ActionMapping actionMapping, ActionForm actionForm,
105             HttpServletRequest httpServletRequest,
106             HttpServletResponse httpServletResponse) {
107         logger.debug("[ Reset ]");
108         DescriptionClipperForm form = (DescriptionClipperForm) actionForm;
109         return actionMapping.getInputForward();
110     }
111
112
113     /**
114      * Description of the Method
115      *
116      *@param actionMapping Description of Parameter
117      *@param actionForm Description of Parameter
118      *@param httpServletRequest Description of Parameter
119      *@param httpServletResponse Description of Parameter
120      *@return Description of the Returned Value
121      */

122     public ActionForward update(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
123         logger.debug("[ update ]");
124         DescriptionClipperForm form = (DescriptionClipperForm) actionForm;
125         ClipperBean cb = SessionManager.getClipperBean(httpServletRequest);
126         String JavaDoc name = form.getWebClippingName();
127         String JavaDoc description = form.getWebClippingDescription();
128         cb.setName(name);
129         cb.setDescription(description);
130         return actionMapping.getInputForward();
131     }
132
133
134     /**
135      * Description of the Method
136      *
137      *@param request Description of Parameter
138      *@param form Description of Parameter
139      *@return Description of the Returned Value
140      */

141     private boolean lookForErrors(HttpServletRequest request,
142             DescriptionClipperForm form) {
143         // manange errors
144
ActionErrors errors = new ActionErrors();
145         //Target Url
146
try {
147             if (form.getWebClippingTargetUrl() == null || form.getWebClippingTargetUrl().equals("")) {
148                 errors.add("error.url.empty", new ActionError("error.url.empty"));
149             }
150             else {
151                 String JavaDoc url = form.getWebClippingTargetUrl();
152                 if (url.indexOf("http://") != 0 && url.indexOf("https://") != 0) {
153                     url = "http://" + url;
154                     form.setWebClippingTargetUrl(url);
155                 }
156                 new URL JavaDoc(form.getWebClippingTargetUrl());
157             }
158         }
159         catch (MalformedURLException JavaDoc ex) {
160             errors.add("error.url.malformed", new ActionError("error.url.malformed"));
161         }
162
163         //Name
164
if (form.getWebClippingName() == null ||
165                 form.getWebClippingName().equals("")) {
166             errors.add("error.name.empty", new ActionError("error.name.empty"));
167         }
168         // return null;
169
this.saveErrors(request, errors);
170
171         if (errors.isEmpty()) {
172             return false;
173         }
174         else {
175             return true;
176         }
177
178     }
179
180 }
181
Popular Tags