KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jahia.clipbuilder.html.struts;
2
3 import org.apache.struts.actions.*;
4 import org.apache.struts.action.*;
5 import org.apache.struts.action.*;
6 import javax.servlet.http.*;
7 import java.util.*;
8
9 import org.jahia.clipbuilder.html.bean.*;
10 import org.jahia.clipbuilder.html.struts.Util.*;
11 import org.jahia.clipbuilder.html.*;
12 import org.springframework.web.context.support.WebApplicationContextUtils;
13 import org.jahia.clipbuilder.html.database.hibernate.service.DefaultConfigurationManager;
14 import org.springframework.context.ApplicationContext;
15
16 /**
17  * Description of the Class
18  *
19  *@author Tlili Khaled
20  */

21 public class ConfigureAction extends LookupDispatchAction {
22     private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(ConfigureAction.class);
23
24
25     /**
26      * Gets the DefaultConfigurationManager attribute of the ConfigureAction
27      * object
28      *
29      *@return The DefaultConfigurationManager value
30      */

31     public DefaultConfigurationManager getDefaultConfigurationManager() {
32         ApplicationContext cxt = org.jahia.clipbuilder.util.JahiaUtils.getSpringApplicationContext();
33         if (cxt == null) {
34             // clip builder is not part of jahia
35
cxt = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext());
36         }
37         return (DefaultConfigurationManager) cxt.getBean("htmlClipperDefaultConfigurationManager");
38     }
39
40
41
42     /**
43      * Description of the Method
44      *
45      *@param actionMapping Description of Parameter
46      *@param actionForm Description of Parameter
47      *@param request Description of Parameter
48      *@param httpServletResponse Description of Parameter
49      *@return Description of the Returned Value
50      */

51     public ActionForward saveDefaultConfiguration(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse httpServletResponse) {
52         ConfigureForm form = (ConfigureForm) actionForm;
53         String JavaDoc portletCacheExpiration = form.getPortletCacheExpiration();
54
55         if (portletCacheExpiration != null && !portletCacheExpiration.equalsIgnoreCase("")) {
56             try {
57                 Integer.parseInt(form.getPortletCacheExpiration());
58             }
59             catch (NumberFormatException JavaDoc ex) {
60                 logger.error("NumberFormatException: " + ex.toString());
61                 ActionErrors errors = new ActionErrors();
62                 errors.add("portlet.cacheExpiration.error", new ActionError("portlet.cacheExpiration.error"));
63                 saveErrors(request, errors);
64                 return actionMapping.getInputForward();
65             }
66         }
67
68         //Build the configuration bean
69
ConfigureBean configureBean;
70         if (getDefaultConfigurationManager().defaultConfigurationExist()) {
71             configureBean = getDefaultConfigurationManager().getDefaultConfigurationBean();
72         }
73         else {
74             configureBean = new ConfigureBean();
75         }
76         configureBean.load(form);
77
78         //save or update
79
getDefaultConfigurationManager().saveOrDefaultConfigureBean(configureBean);
80
81         HttpSession session = request.getSession();
82         if (session.getAttribute(org.jahia.clipbuilder.html.struts.Util.Constants.DESCRIPTION_FORM) != null) {
83             return actionMapping.findForward("description");
84         }
85         else {
86             return actionMapping.findForward("manage");
87         }
88
89     }
90
91
92
93     /**
94      * Description of the Method
95      *
96      *@param actionMapping Description of Parameter
97      *@param actionForm Description of Parameter
98      *@param request Description of Parameter
99      *@param httpServletResponse Description of Parameter
100      *@return Description of the Returned Value
101      */

102     public ActionForward saveForCurrentClipper(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse httpServletResponse) {
103         try {
104             ConfigureForm form = (ConfigureForm) actionForm;
105             String JavaDoc portletCacheExpiration = form.getPortletCacheExpiration();
106             if (portletCacheExpiration != null && !portletCacheExpiration.equalsIgnoreCase("")) {
107                 try {
108                     Integer.parseInt(form.getPortletCacheExpiration());
109                 }
110                 catch (NumberFormatException JavaDoc ex) {
111                     logger.error("NumberFormatException: " + ex.toString());
112                     ActionErrors errors = new ActionErrors();
113                     errors.add("portlet.cacheExpiration.error", new ActionError("portlet.cacheExpiration.error"));
114                     saveErrors(request, errors);
115                     return actionMapping.getInputForward();
116                 }
117             }
118             //Build the configuration bean
119
ConfigureBean configureBean = new ConfigureBean();
120
121             configureBean.load(form);
122
123             ClipperBean bean = SessionManager.getClipperBean(request);
124             bean.setConfigurationBean(configureBean);
125
126             //remove all form bean comming after Description form
127
HttpSession session = request.getSession();
128             session.removeAttribute(Constants.BROWSE_FORM);
129             session.removeAttribute(Constants.SELECTPART_FORM);
130             session.removeAttribute(Constants.EDITPARAM_FORM);
131             session.removeAttribute(Constants.PREVIEW_FORM);
132
133         }
134         catch (Exception JavaDoc ex) {
135             ex.printStackTrace();
136             return actionMapping.getInputForward();
137         }
138
139         return actionMapping.findForward("description");
140     }
141
142
143
144     /**
145      * Description of the Method
146      *
147      *@param actionMapping Description of Parameter
148      *@param actionForm Description of Parameter
149      *@param httpServletRequest Description of Parameter
150      *@param httpServletResponse Description of Parameter
151      *@return Description of the Returned Value
152      */

153     public ActionForward reset(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
154         ConfigureForm form = (ConfigureForm) actionForm;
155
156         //load clippers
157
return actionMapping.findForward("manage");
158     }
159
160
161     /**
162      * Description of the Method
163      *
164      *@param actionMapping Description of Parameter
165      *@param actionForm Description of Parameter
166      *@param httpServletRequest Description of Parameter
167      *@param httpServletResponse Description of Parameter
168      *@return Description of the Returned Value
169      */

170     public ActionForward initManager(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
171         logger.debug("[ Init Manager ]");
172         ConfigureForm form = (ConfigureForm) actionForm;
173         if (getDefaultConfigurationManager().defaultConfigurationExist()) {
174             form.load(getDefaultConfigurationManager().getDefaultConfigurationBean());
175         }
176         return actionMapping.getInputForward();
177     }
178
179
180     /**
181      * Description of the Method
182      *
183      *@param actionMapping Description of Parameter
184      *@param actionForm Description of Parameter
185      *@param httpServletRequest Description of Parameter
186      *@param httpServletResponse Description of Parameter
187      *@return Description of the Returned Value
188      */

189     public ActionForward initDescription(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
190         logger.debug("[ Init Configuration from clipper ]");
191         ConfigureForm form = (ConfigureForm) actionForm;
192         ClipperBean bean = SessionManager.getClipperBean(httpServletRequest);
193         form.load(bean.getConfigurationBean());
194         return actionMapping.getInputForward();
195     }
196
197
198
199     /**
200      * Gets the KeyMethodMap attribute of the ConfigureAction object
201      *
202      *@return The KeyMethodMap value
203      */

204     protected Map getKeyMethodMap() {
205         Map map = new HashMap();
206         map.put("initManager", "initManager");
207         map.put("initDescription", "initDescription");
208         map.put("configuration.button.saveDefault", "saveDefaultConfiguration");
209         map.put("configuration.button.saveCurrentClipper", "saveForCurrentClipper");
210         map.put("configuration.button.reset", "reset");
211         return map;
212     }
213
214 }
215
Popular Tags