1 16 package com.blandware.atleap.webapp.action.testimonials; 17 18 import com.blandware.atleap.common.TestimonialModuleConstants; 19 import com.blandware.atleap.model.testimonials.Testimonial; 20 import com.blandware.atleap.service.testimonials.TestimonialManager; 21 import com.blandware.atleap.webapp.action.core.BaseAction; 22 import com.blandware.atleap.webapp.form.TestimonialForm; 23 import com.blandware.atleap.webapp.util.core.LocaleUtil; 24 import com.blandware.atleap.webapp.util.core.WebappConstants; 25 import com.blandware.atleap.webapp.util.core.WebappUtil; 26 import com.blandware.atleap.webapp.util.testimonials.TestimonialModuleWebConstants; 27 import org.apache.struts.action.ActionForm; 28 import org.apache.struts.action.ActionForward; 29 import org.apache.struts.action.ActionMapping; 30 import org.apache.struts.action.ActionMessage; 31 import org.apache.struts.action.ActionMessages; 32 33 import javax.servlet.http.HttpServletRequest ; 34 import javax.servlet.http.HttpServletResponse ; 35 import java.util.List ; 36 import java.util.Map ; 37 38 39 61 public final class CallUpdateTestimonialBodyAction extends BaseAction { 62 71 public ActionForward execute(ActionMapping mapping, ActionForm form, 72 HttpServletRequest request, HttpServletResponse response) throws Exception { 73 74 request.getSession().removeAttribute(TestimonialModuleWebConstants.TESTIMONIAL_SUBMITTED_ACTION_KEY); 75 76 if ( isCancelled(request) ) { 77 if ( request.getSession().getAttribute(WebappConstants.REDIRECT_URL_KEY) != null ) { 78 String redirectUrl = (String ) request.getSession().getAttribute(WebappConstants.REDIRECT_URL_KEY); 79 ActionForward redirect = new ActionForward(redirectUrl, true); 80 return redirect; 81 } 82 return mapping.findForward("listTestimonials"); 83 } 84 TestimonialForm testimonialForm = (TestimonialForm) form; 85 86 String localesMode = testimonialForm.getLocalesMode(); 89 if ( !"current".equalsIgnoreCase(localesMode) && !"all".equalsIgnoreCase(localesMode) && testimonialForm.getBodyCheckedBoxes().size() == 0 ) { 90 request.setAttribute("beginPage", mapping.findForward("listTestimonials").getPath()); 91 return mapping.findForward("unsatisfiablePage"); 92 } 93 94 if ( !WebappUtil.hasCorrectValues(testimonialForm.getTitleMap()) ) { 95 97 testimonialForm.setAllCheckedFlagForBodyCheckboxes(request, localesMode); 99 100 request.getSession().removeAttribute(TestimonialModuleWebConstants.TESTIMONIAL_SUBMITTED_ACTION_KEY); 101 ActionMessages errors = new ActionMessages(); 102 errors.add("title", new ActionMessage("core.commons.errors.required", getMessage(request, "testimonials.form.title"))); 103 saveErrors(request, errors, false); 104 saveToken(request); 105 return mapping.getInputForward(); 106 } 107 108 Long testimonialId = null; 109 if ( testimonialForm.getId() != null ) { 110 testimonialId = Long.valueOf(testimonialForm.getId()); 111 } else if ( request.getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_ID_KEY) != null ) { 112 testimonialId = (Long ) request.getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_ID_KEY); 113 } else if ( request.getSession().getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_ID_KEY) != null ) { 114 testimonialId = (Long ) request.getSession().getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_ID_KEY); 115 } else { 116 if ( log.isWarnEnabled() ) { 117 log.warn("Missing testimonial item ID. Returning to list..."); 118 } 119 return mapping.findForward("listTestimonials"); 120 } 121 122 if ( !"current".equals(localesMode) && !"all".equals(localesMode) ) { 123 localesMode = "selected"; 124 } 125 testimonialForm.setLocalesMode(localesMode); 126 127 TestimonialManager testimonialManager = (TestimonialManager) getBean(TestimonialModuleConstants.TESTIMONIAL_MANAGER_BEAN); 128 Testimonial testimonial = testimonialManager.retrieveTestimonial(testimonialId); 129 if ( testimonial == null ) { 130 ActionMessages errors = new ActionMessages(); 132 errors.add("testimonialNotFound", new ActionMessage("testimonials.errors.notFound")); 133 saveErrors(request, errors); 134 return mapping.findForward("listTestimonials"); 135 } 136 137 if ( request.getSession().getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_MERGED_BODY_KEY) != null ) { 138 Map mergedBody = (Map ) request.getSession().getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_MERGED_BODY_KEY); 139 testimonialForm.setBodyMap(mergedBody); 140 request.getSession().removeAttribute(TestimonialModuleWebConstants.TESTIMONIAL_MERGED_BODY_KEY); 141 } 142 143 List contentLocales = LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales(); 144 145 request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales); 146 147 saveToken(request); 149 return mapping.findForward("updateTestimonialBody"); 150 } 151 } 152 | Popular Tags |