You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2008/06/02 08:28:55 UTC

svn commit: r662337 - in /ofbiz/trunk: applications/manufacturing/webapp/manufacturing/WEB-INF/ applications/manufacturing/webapp/manufacturing/jobshopmgt/ framework/example/webapp/example/WEB-INF/ framework/example/webapp/example/WEB-INF/actions/inclu...

Author: jacopoc
Date: Sun Jun  1 23:28:55 2008
New Revision: 662337

URL: http://svn.apache.org/viewvc?rev=662337&view=rev
Log:
Implemented new event handler for Groovy scripts; converted two Beanshell events to Groovy.

Added:
    ofbiz/trunk/applications/manufacturing/webapp/manufacturing/jobshopmgt/ShowProductionRun.groovy
      - copied unchanged from r662324, ofbiz/trunk/applications/manufacturing/webapp/manufacturing/jobshopmgt/ShowProductionRun.bsh
    ofbiz/trunk/framework/example/webapp/example/WEB-INF/actions/includes/findExampleFeatures.groovy
      - copied unchanged from r662324, ofbiz/trunk/framework/example/webapp/example/WEB-INF/actions/includes/findExampleFeatures.bsh
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/GroovyEventHandler.java   (with props)
Removed:
    ofbiz/trunk/applications/manufacturing/webapp/manufacturing/jobshopmgt/ShowProductionRun.bsh
    ofbiz/trunk/framework/example/webapp/example/WEB-INF/actions/includes/findExampleFeatures.bsh
Modified:
    ofbiz/trunk/applications/manufacturing/webapp/manufacturing/WEB-INF/controller.xml
    ofbiz/trunk/framework/example/webapp/example/WEB-INF/controller.xml

Modified: ofbiz/trunk/applications/manufacturing/webapp/manufacturing/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/webapp/manufacturing/WEB-INF/controller.xml?rev=662337&r1=662336&r2=662337&view=diff
==============================================================================
--- ofbiz/trunk/applications/manufacturing/webapp/manufacturing/WEB-INF/controller.xml (original)
+++ ofbiz/trunk/applications/manufacturing/webapp/manufacturing/WEB-INF/controller.xml Sun Jun  1 23:28:55 2008
@@ -27,6 +27,7 @@
     <!-- event handlers -->
     <handler name="service-multi" type="request" class="org.ofbiz.webapp.event.ServiceMultiEventHandler"/>
     <handler name="bsf" type="request" class="org.ofbiz.webapp.event.BsfEventHandler"/>
+    <handler name="groovy" type="request" class="org.ofbiz.webapp.event.GroovyEventHandler"/>
 
     <!-- Events to run on every request before security (chains exempt) -->
     <!--
@@ -443,7 +444,8 @@
     </request-map>
     <request-map uri="ShowProductionRun">
         <security https="true" auth="true"/>
-        <event type="bsf" path="/jobshopmgt/" invoke="ShowProductionRun.bsh"/>
+        <!-- <event type="bsf" path="/jobshopmgt/" invoke="ShowProductionRun.bsh"/>  -->
+        <event type="groovy" path="component://manufacturing/webapp/manufacturing/jobshopmgt/" invoke="ShowProductionRun.groovy"/>
         <response name="docs_not_printed" type="view" value="EditProductionRun"/>
         <response name="docs_printed" type="view" value="ProductionRunDeclaration"/>
         <response name="error" type="view" value="FindProductionRun"/>

Modified: ofbiz/trunk/framework/example/webapp/example/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/webapp/example/WEB-INF/controller.xml?rev=662337&r1=662336&r2=662337&view=diff
==============================================================================
--- ofbiz/trunk/framework/example/webapp/example/WEB-INF/controller.xml (original)
+++ ofbiz/trunk/framework/example/webapp/example/WEB-INF/controller.xml Sun Jun  1 23:28:55 2008
@@ -28,7 +28,7 @@
     <description>Example Component Site Configuration File</description>
     <owner>Copyright 2001-2008 The Apache Software Foundation</owner>
 
-    <handler name="bsf" type="request" class="org.ofbiz.webapp.event.BsfEventHandler"/>
+    <handler name="groovy" type="request" class="org.ofbiz.webapp.event.GroovyEventHandler"/>
 
     <!--
       These can be used to return the reports as views; make sure the classes are compiled and available
@@ -160,7 +160,7 @@
     </request-map>
     <request-map uri="findExampleFeatures">
         <security https="true" auth="true"/>
-        <event type="bsf" path="/WEB-INF/actions/includes/" invoke="findExampleFeatures.bsh"/>
+        <event type="groovy" path="component://example/webapp/example/WEB-INF/actions/includes/" invoke="findExampleFeatures.groovy"/>
         <response name="success" type="view" value="ajaxAutocompleteOptions"/>
         <response name="error" type="view" value="ajaxAutocompleteOptions"/>
     </request-map>

Added: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/GroovyEventHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/GroovyEventHandler.java?rev=662337&view=auto
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/GroovyEventHandler.java (added)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/GroovyEventHandler.java Sun Jun  1 23:28:55 2008
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+package org.ofbiz.webapp.event;
+
+import java.util.Map;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.ofbiz.base.util.GroovyUtil;
+import javolution.util.FastMap;
+
+public class GroovyEventHandler implements EventHandler {
+    
+    public static final String module = GroovyEventHandler.class.getName();
+
+    public void init(ServletContext context) throws EventHandlerException {
+    }
+
+    public String invoke(String eventPath, String eventMethod, HttpServletRequest request, HttpServletResponse response) throws EventHandlerException {
+        try {
+            Map<String, Object> groovyContext = FastMap.newInstance();
+            groovyContext.put("request", request);
+            groovyContext.put("response", response);
+            Object result = GroovyUtil.runScriptAtLocation(eventPath + eventMethod, groovyContext);
+            // check the result
+            if (result != null && !(result instanceof String)) {
+                throw new EventHandlerException("Event did not return a String result, it returned a " + result.getClass().getName());           
+            }
+            return (String) result;
+        } catch(Exception e) {
+            throw new EventHandlerException("Groovy Event Error", e);
+        }                
+    }
+}

Propchange: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/GroovyEventHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/GroovyEventHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/GroovyEventHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain