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 ; 11 import java.net.MalformedURLException ; 12 13 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 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 45 public int getFormId() { 46 return Constants.DESCRIPTION; 47 } 48 49 50 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 updateSessionAttributes(request, Constants.DESCRIPTION); 69 logger.debug("add sourceUrl "); 70 71 72 74 75 return actionMapping.findForward("browseInit"); 76 } 77 78 79 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 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 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 name = form.getWebClippingName(); 127 String description = form.getWebClippingDescription(); 128 cb.setName(name); 129 cb.setDescription(description); 130 return actionMapping.getInputForward(); 131 } 132 133 134 141 private boolean lookForErrors(HttpServletRequest request, 142 DescriptionClipperForm form) { 143 ActionErrors errors = new ActionErrors(); 145 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 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 (form.getWebClippingTargetUrl()); 157 } 158 } 159 catch (MalformedURLException ex) { 160 errors.add("error.url.malformed", new ActionError("error.url.malformed")); 161 } 162 163 if (form.getWebClippingName() == null || 165 form.getWebClippingName().equals("")) { 166 errors.add("error.name.empty", new ActionError("error.name.empty")); 167 } 168 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 |