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.model.core.ContentLocale; 21 import com.blandware.atleap.service.testimonials.TestimonialManager; 22 import com.blandware.atleap.webapp.action.core.BaseAction; 23 import com.blandware.atleap.webapp.form.TestimonialForm; 24 import com.blandware.atleap.webapp.util.core.LocaleUtil; 25 import com.blandware.atleap.webapp.util.core.WebappConstants; 26 import com.blandware.atleap.webapp.util.core.WebappUtil; 27 import com.blandware.atleap.webapp.util.testimonials.TestimonialModuleWebConstants; 28 import org.apache.commons.validator.GenericValidator; 29 import org.apache.struts.action.ActionForm; 30 import org.apache.struts.action.ActionForward; 31 import org.apache.struts.action.ActionMapping; 32 import org.apache.struts.action.ActionMessage; 33 import org.apache.struts.action.ActionMessages; 34 35 import javax.servlet.http.HttpServletRequest ; 36 import javax.servlet.http.HttpServletResponse ; 37 import java.util.List ; 38 import java.util.Map ; 39 import java.util.Iterator ; 40 41 60 public final class CallUpdateTestimonialAction extends BaseAction { 61 70 public ActionForward execute(ActionMapping mapping, ActionForm form, 71 HttpServletRequest request, HttpServletResponse response) throws Exception { 72 73 request.getSession().removeAttribute(TestimonialModuleWebConstants.TESTIMONIAL_SUBMITTED_ACTION_KEY); 74 75 if ( isCancelled(request) ) { 76 return mapping.findForward("listTestimonials"); 77 } 78 79 if ( !request.isUserInRole("testimonials-item-update") ) { 80 response.sendError(HttpServletResponse.SC_FORBIDDEN); 81 return null; 82 } 83 84 TestimonialForm testimonialForm = (TestimonialForm) form; 85 Long testimonialId = null; 86 if ( testimonialForm.getId() != null ) { 87 testimonialId = Long.valueOf(testimonialForm.getId()); 88 } else if ( request.getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_ID_KEY) != null ) { 89 testimonialId = (Long ) request.getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_ID_KEY); 90 } else if ( request.getSession().getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_ID_KEY) != null ) { 91 testimonialId = (Long ) request.getSession().getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_ID_KEY); 92 } else { 93 if ( log.isWarnEnabled() ) { 94 log.warn("Missing testimonial item ID. Returning to list..."); 95 } 96 return mapping.findForward("listTestimonials"); 97 } 98 99 String redirectUrl = request.getParameter("redirectUrl"); 100 if ( GenericValidator.isBlankOrNull(redirectUrl) ) { 101 redirectUrl = (String ) request.getAttribute(WebappConstants.REDIRECT_URL_KEY); 102 } 103 if ( !GenericValidator.isBlankOrNull(redirectUrl) ) { 104 request.getSession().setAttribute(WebappConstants.REDIRECT_URL_KEY, redirectUrl); 105 } else { 106 request.getSession().removeAttribute(WebappConstants.REDIRECT_URL_KEY); 107 } 108 109 String localesMode = testimonialForm.getLocalesMode(); 110 if ( !"current".equalsIgnoreCase(localesMode) && !"all".equalsIgnoreCase(localesMode) ) { 111 localesMode = "selected"; 112 } 113 testimonialForm.setLocalesMode(localesMode); 114 115 TestimonialManager testimonialManager = (TestimonialManager) getBean(TestimonialModuleConstants.TESTIMONIAL_MANAGER_BEAN); 116 Testimonial testimonial = testimonialManager.retrieveTestimonial(testimonialId); 117 if ( testimonial == null ) { 118 ActionMessages errors = new ActionMessages(); 120 errors.add("testimonialNotFound", new ActionMessage("testimonials.errors.notFound")); 121 saveErrors(request, errors); 122 return mapping.findForward("listTestimonials"); 123 } 124 WebappUtil.copyProperties(testimonialForm, testimonial, request); 125 testimonialForm.setTitleMap(testimonial.getTitle()); 126 testimonialForm.setBodyMap(testimonial.getBody()); 127 128 List contentLocales = LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales(); 129 130 request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales); 131 132 if ("selected".equalsIgnoreCase(localesMode)) { 133 Map bodyCheckedBoxes = testimonialForm.getBodyCheckedBoxes(); 135 for (Iterator i = contentLocales.iterator(); i.hasNext();) { 136 ContentLocale contentLocale = (ContentLocale) i.next(); 137 bodyCheckedBoxes.put(contentLocale.getIdentifier(), Boolean.TRUE); 138 } 139 140 request.setAttribute(WebappConstants.SELECT_ALL_LOCALES_CHECKBOX_IS_CHECKED, Boolean.TRUE); 142 } 143 144 saveToken(request); 146 return mapping.findForward("updateTestimonial"); 147 } 148 } | Popular Tags |