01: /*
02: * $Id: SimpleEventHandler.java,v 1.2 2003/09/14 05:36:47 jonesde Exp $
03: *
04: * Copyright (c) 2001-2003 The Open For Business Project - www.ofbiz.org
05: *
06: * Permission is hereby granted, free of charge, to any person obtaining a
07: * copy of this software and associated documentation files (the "Software"),
08: * to deal in the Software without restriction, including without limitation
09: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10: * and/or sell copies of the Software, and to permit persons to whom the
11: * Software is furnished to do so, subject to the following conditions:
12: *
13: * The above copyright notice and this permission notice shall be included
14: * in all copies or substantial portions of the Software.
15: *
16: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23: *
24: */
25: package org.ofbiz.content.webapp.event;
26:
27: import javax.servlet.http.HttpServletRequest;
28: import javax.servlet.http.HttpServletResponse;
29:
30: import org.ofbiz.base.util.Debug;
31: import org.ofbiz.minilang.MiniLangException;
32: import org.ofbiz.minilang.SimpleMethod;
33:
34: /**
35: * SimpleEventHandler - Simple Event Mini-Lang Handler
36: *
37: * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
38: * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
39: * @version $Revision: 1.2 $
40: * @since 2.0
41: */
42: public class SimpleEventHandler implements EventHandler {
43:
44: public static final String module = SimpleEventHandler.class
45: .getName();
46:
47: /**
48: * Invoke the web event
49: *@param eventPath The path or location of this event
50: *@param eventMethod The method to invoke
51: *@param request The servlet request object
52: *@param response The servlet response object
53: *@return String Result code
54: *@throws EventHandlerException
55: */
56: public String invoke(String eventPath, String eventMethod,
57: HttpServletRequest request, HttpServletResponse response)
58: throws EventHandlerException {
59: String xmlResource = eventPath;
60: String eventName = eventMethod;
61:
62: if (Debug.verboseOn())
63: Debug.logVerbose("[Set path/method]: " + xmlResource
64: + " / " + eventName, module);
65:
66: if (xmlResource == null)
67: throw new EventHandlerException(
68: "XML Resource (eventPath) cannot be null");
69: if (eventName == null)
70: throw new EventHandlerException(
71: "Event Name (eventMethod) cannot be null");
72:
73: Debug.logVerbose("[Processing]: SIMPLE Event", module);
74: try {
75: String eventReturn = SimpleMethod.runSimpleEvent(
76: xmlResource, eventName, request, response);
77:
78: if (Debug.verboseOn())
79: Debug.logVerbose("[Event Return]: " + eventReturn,
80: module);
81: return eventReturn;
82: } catch (MiniLangException e) {
83: Debug.logError(e, module);
84: request.setAttribute("_ERROR_MESSAGE_",
85: "Could not complete event: " + e.getMessage());
86: return "error";
87: }
88: }
89: }
|