1 25 package org.ofbiz.webapp.event; 26 27 import java.util.Locale ; 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 import javax.servlet.ServletContext ; 31 32 import org.ofbiz.base.util.Debug; 33 import org.ofbiz.base.util.UtilHttp; 34 import org.ofbiz.base.util.UtilProperties; 35 import org.ofbiz.minilang.MiniLangException; 36 import org.ofbiz.minilang.SimpleMethod; 37 38 46 public class SimpleEventHandler implements EventHandler { 47 48 public static final String module = SimpleEventHandler.class.getName(); 49 50 public static final String err_resource = "WebappUiLabels"; 51 52 55 public void init(ServletContext context) throws EventHandlerException { 56 } 57 58 67 public String invoke(String eventPath, String eventMethod, HttpServletRequest request, HttpServletResponse response) throws EventHandlerException { 68 String xmlResource = eventPath; 69 String eventName = eventMethod; 70 Locale locale = UtilHttp.getLocale(request); 71 72 if (Debug.verboseOn()) Debug.logVerbose("[Set path/method]: " + xmlResource + " / " + eventName, module); 73 74 if (xmlResource == null) { 75 throw new EventHandlerException("XML Resource (eventPath) cannot be null"); 76 } 77 if (eventName == null) { 78 throw new EventHandlerException("Event Name (eventMethod) cannot be null"); 79 } 80 81 Debug.logVerbose("[Processing]: SIMPLE Event", module); 82 try { 83 String eventReturn = SimpleMethod.runSimpleEvent(xmlResource, eventName, request, response); 84 if (Debug.verboseOn()) Debug.logVerbose("[Event Return]: " + eventReturn, module); 85 return eventReturn; 86 } catch (MiniLangException e) { 87 Debug.logError(e, module); 88 String errMsg = UtilProperties.getMessage(SimpleEventHandler.err_resource, "simpleEventHandler.event_not_completed", (locale != null ? locale : Locale.getDefault())) + ": "; 89 request.setAttribute("_ERROR_MESSAGE_", errMsg + e.getMessage()); 90 return "error"; 91 } 92 } 93 } 94 | Popular Tags |