1 16 package com.blandware.atleap.webapp.action.core.applicationResource; 17 18 import com.blandware.atleap.service.exception.BeanNotFoundException; 19 import com.blandware.atleap.webapp.action.core.BaseAction; 20 import com.blandware.atleap.webapp.form.core.ApplicationResourceForm; 21 import com.blandware.atleap.webapp.util.core.ApplicationResources; 22 import com.blandware.atleap.webapp.util.core.WebappConstants; 23 import org.apache.commons.validator.GenericValidator; 24 import org.apache.struts.action.ActionForm; 25 import org.apache.struts.action.ActionForward; 26 import org.apache.struts.action.ActionMapping; 27 import org.apache.struts.action.ActionMessage; 28 import org.apache.struts.action.ActionMessages; 29 import org.springframework.orm.ObjectOptimisticLockingFailureException; 30 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpServletResponse ; 33 import java.util.Iterator ; 34 import java.util.Map ; 35 36 61 public final class UpdateApplicationResourceAction extends BaseAction { 62 71 public ActionForward execute(ActionMapping mapping, ActionForm form, 72 HttpServletRequest request, HttpServletResponse response) throws Exception { 73 74 if ( !isCancelled(request) ) { 75 ApplicationResourceForm applicationResourceForm = (ApplicationResourceForm) form; 76 String key = applicationResourceForm.getKey(); 77 if ( GenericValidator.isBlankOrNull(key) ) { 78 if ( log.isWarnEnabled() ) { 79 log.warn("Missing application resource key. Returning to list..."); 80 } 81 return mapping.findForward("listApplicationResources"); 82 } 83 84 Map valueMap = applicationResourceForm.getValueMap(); 85 86 boolean resourceExists = true; 87 boolean alreadyUpdatedExist = false; 88 ApplicationResources applicationResources = ApplicationResources.getInstance(servlet.getServletContext()); 89 for ( Iterator i = valueMap.entrySet().iterator(); i.hasNext(); ) { 90 Map.Entry entry = (Map.Entry ) i.next(); 91 String localeIdentifier = (String ) entry.getKey(); 92 String value = (String ) entry.getValue(); 93 94 String versionString = (String )applicationResourceForm.getVersion(localeIdentifier); 95 Long version; 96 if (GenericValidator.isBlankOrNull(versionString)) { 97 version = null; 98 } else { 99 version = Long.valueOf(versionString); 100 } 101 try { 102 applicationResources.updateResource(localeIdentifier, key, value, version); 103 } catch ( BeanNotFoundException e ) { 104 resourceExists = false; 105 } catch ( ObjectOptimisticLockingFailureException e ) { 106 alreadyUpdatedExist = true; 108 } 109 } 110 111 if ( !resourceExists ) { 112 ActionMessages errors = new ActionMessages(); 114 errors.add("applicationResourceNotFound", new ActionMessage("core.applicationResource.errors.notFound", key)); 115 saveErrors(request, errors); 116 return mapping.findForward("listApplicationResources"); 117 } 118 119 if ( alreadyUpdatedExist ) { 120 ActionMessages errors = new ActionMessages(); 121 errors.add("updateFailed", new ActionMessage("core.applicationResource.errors.updateFailed")); 122 saveErrors(request, errors); 123 request.setAttribute(WebappConstants.APPLICATION_RESOURCE_KEY_KEY, key); 124 return mapping.findForward("callUpdateApplicationResource"); 125 } 126 127 } 128 return mapping.findForward("listApplicationResources"); 129 } 130 } | Popular Tags |