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 21 public class ConfigureAction extends LookupDispatchAction { 22 private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(ConfigureAction.class); 23 24 25 31 public DefaultConfigurationManager getDefaultConfigurationManager() { 32 ApplicationContext cxt = org.jahia.clipbuilder.util.JahiaUtils.getSpringApplicationContext(); 33 if (cxt == null) { 34 cxt = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext()); 36 } 37 return (DefaultConfigurationManager) cxt.getBean("htmlClipperDefaultConfigurationManager"); 38 } 39 40 41 42 51 public ActionForward saveDefaultConfiguration(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse httpServletResponse) { 52 ConfigureForm form = (ConfigureForm) actionForm; 53 String portletCacheExpiration = form.getPortletCacheExpiration(); 54 55 if (portletCacheExpiration != null && !portletCacheExpiration.equalsIgnoreCase("")) { 56 try { 57 Integer.parseInt(form.getPortletCacheExpiration()); 58 } 59 catch (NumberFormatException 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 ConfigureBean configureBean; 70 if (getDefaultConfigurationManager().defaultConfigurationExist()) { 71 configureBean = getDefaultConfigurationManager().getDefaultConfigurationBean(); 72 } 73 else { 74 configureBean = new ConfigureBean(); 75 } 76 configureBean.load(form); 77 78 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 102 public ActionForward saveForCurrentClipper(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse httpServletResponse) { 103 try { 104 ConfigureForm form = (ConfigureForm) actionForm; 105 String portletCacheExpiration = form.getPortletCacheExpiration(); 106 if (portletCacheExpiration != null && !portletCacheExpiration.equalsIgnoreCase("")) { 107 try { 108 Integer.parseInt(form.getPortletCacheExpiration()); 109 } 110 catch (NumberFormatException 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 ConfigureBean configureBean = new ConfigureBean(); 120 121 configureBean.load(form); 122 123 ClipperBean bean = SessionManager.getClipperBean(request); 124 bean.setConfigurationBean(configureBean); 125 126 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 ex) { 135 ex.printStackTrace(); 136 return actionMapping.getInputForward(); 137 } 138 139 return actionMapping.findForward("description"); 140 } 141 142 143 144 153 public ActionForward reset(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { 154 ConfigureForm form = (ConfigureForm) actionForm; 155 156 return actionMapping.findForward("manage"); 158 } 159 160 161 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 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 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 |