Author: bpapez
Date: Fri Aug 17 16:13:53 2007
New Revision: 18201

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D18201&repname=
=3Djahia
Log:
Add missing methods to event listener and port optimization from SP branch

Added:
    trunk/core/src/java/org/jahia/services/events/JahiaGroovyEngine.java
Modified:
    trunk/core/src/java/org/jahia/data/events/JahiaEventListenerInterface.j=
ava
    trunk/core/src/java/org/jahia/services/events/GroovyEventListener.java
    trunk/core/src/java/org/jahia/services/events/JSPEventListener.java
    trunk/core/src/webapp/WEB-INF/etc/spring/applicationcontext-basejahiaco=
nfig.xml

Modified: trunk/core/src/java/org/jahia/data/events/JahiaEventListenerInter=
face.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/data/events/JahiaEventListenerInterface.java&rev=3D18201&repname=
=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/core/src/java/org/jahia/data/events/JahiaEventListenerInterface.j=
ava (original)
+++ trunk/core/src/java/org/jahia/data/events/JahiaEventListenerInterface.j=
ava Fri Aug 17 16:13:53 2007
@@ -55,6 +55,7 @@
      */
     public void beforeContainerActivation( JahiaEvent je );
     public void containerValidation(JahiaEvent je);
+    =

     public void addContainerEngineAfterSave( JahiaEvent je );
     public void addContainerEngineBeforeSave( JahiaEvent je );
     public void addContainerEngineAfterInit( JahiaEvent je );

Modified: trunk/core/src/java/org/jahia/services/events/GroovyEventListener=
.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/services/events/GroovyEventListener.java&rev=3D18201&repname=3Djah=
ia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/core/src/java/org/jahia/services/events/GroovyEventListener.java =
(original)
+++ trunk/core/src/java/org/jahia/services/events/GroovyEventListener.java =
Fri Aug 17 16:13:53 2007
@@ -14,10 +14,12 @@
  * 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.jahia.services.events;
+ */
+package org.jahia.services.events;
 =

 import groovy.lang.Binding;
-import groovy.util.GroovyScriptEngine;
+import org.apache.commons.collections.FastHashMap;
+import org.jahia.bin.Jahia;
 import org.jahia.content.events.ContentActivationEvent;
 import org.jahia.content.events.ContentObjectDeleteEvent;
 import org.jahia.content.events.ContentObjectRestoreVersionEvent;
@@ -30,276 +32,421 @@
 import org.jahia.services.workflow.WorkflowEvent;
 =

 import java.io.File;
+import java.util.Map;
 =

 /**
- * <p>Title: A Jahia Event Listener that dispatches to Groovy script files=
</p>
- * <p>Description: This event listeners allows the use of Groovy script fi=
les as
- * event listeners, allowing for customizations in a more script-like way
- * than having to compile actual code. </p>
- * <p>Copyright: Copyright (c) 2006</p>
- * <p>Company: Jahia Ltd</p>
- *
+ * <p>
+ * Title: A Jahia Event Listener that dispatches to Groovy script files
+ * </p>
+ * <p>
+ * Description: This event listeners allows the use of Groovy script files=
 as event listeners, allowing for customizations in a more
+ * script-like way than having to compile actual code.
+ * </p>
+ * <p>
+ * Copyright: Copyright (c) 2006
+ * </p>
+ * <p>
+ * Company: Jahia Ltd
+ * </p>
+ * =

  * @author Serge Huber
  * @version 1.0
  */
 =

 public class GroovyEventListener extends JahiaEventListener {
 =

-    private static org.apache.log4j.Logger logger =3D
-            org.apache.log4j.Logger.getLogger (GroovyEventListener.class);
+    private static org.apache.log4j.Logger logger =3D org.apache.log4j.Log=
ger
+            .getLogger(GroovyEventListener.class);
 =

     private boolean configLoaded =3D false;
     private String defaultPathToGroovy =3D null;
     private String groovyFileName =3D null;
 =

-    private static final String DEFAULT_PATH_TO_GROOVY =3D
-            "events/EventListener.groovy";
+    private static final String DEFAULT_PATH_TO_GROOVY =3D "events/EventLi=
stener.groovy";
     private static final String GROOVY_FILE_NAME =3D "EventListener.groovy=
";
 =

-    private GroovyScriptEngine groovyScriptEngine;
+    private JahiaGroovyEngine jahiaScriptEngine;
+    private static long lastCall =3D 0;// used for performance mode
 =

-    private boolean checkConfig (ProcessingContext processingContext) {
+    private boolean checkConfig(ProcessingContext processingContext) {
         if (configLoaded)
             return configLoaded;
 =

-        loadConfig (processingContext);
+        loadConfig(processingContext);
 =

         return configLoaded;
     }
 =

-    private void loadConfig (ProcessingContext processingContext) {
+    private static Map eventsHandled =3D null;
+    private static Map siteEventFile =3D new FastHashMap(64);
+    private static String staticeventsToHandleList =3D "";
+
+    private void loadConfig(ProcessingContext processingContext) {
 =

         /**
-         * @todo for the moment this stuff is hardcoded, but we might want=
 to
-         * make this configurable through an XML file.
+         * @todo for the moment this stuff is hardcoded, but we might want=
 to make this configurable through an XML file.
          */
 =

         defaultPathToGroovy =3D GroovyEventListener.DEFAULT_PATH_TO_GROOVY;
         groovyFileName =3D GroovyEventListener.GROOVY_FILE_NAME;
-        groovyScriptEngine =3D (GroovyScriptEngine) SpringContextSingleton=
.getInstance().getContext().getBean("groovyScriptEngine");
+        jahiaScriptEngine =3D (JahiaGroovyEngine) SpringContextSingleton
+                .getInstance().getContext().getBean("groovyScriptEngine");
 =

         configLoaded =3D true;
     }
 =

-    public GroovyEventListener () {
+    public GroovyEventListener() {
     }
 =

-    private void dispatchToGroovyScript (String eventName, JahiaEvent je) {
-        if (!checkConfig (je.getProcessingContext ())) {
-            return;
-        }
-
-        ProcessingContext processingContext =3D je.getProcessingContext ();
-        try {
-            String groovyFileName =3D resolveGroovyFullFileName (processin=
gContext);
-
-            long startTime =3D System.currentTimeMillis();
-            synchronized(groovyScriptEngine) {
-            Binding binding =3D new Binding();
-                binding.setVariable ("eventName", eventName);
-                binding.setVariable ("jahiaEvent", je);
-                groovyScriptEngine.run(groovyFileName, binding);
+    private void dispatchToGroovyScript(String eventName, JahiaEvent je) {
+        ProcessingContext processingContext =3D je.getProcessingContext();
+        if (checkConfig(processingContext)
+                && (eventsHandled =3D=3D null || eventsHandled
+                        .containsKey(eventName))) {
+            try {
+                String groovyFileName =3D resolveGroovyFullFileName(proces=
singContext);
+
+                // Developement mode flag
+                boolean checkDependances =3D Jahia.getSettings()
+                        .isDevelopmentMode();
+                long startTime =3D System.currentTimeMillis();
+
+                // performance mode
+                if (startTime - lastCall < 1500 && checkDependances
+                        && enabledPerformanceMode) {
+                    // under heavy load we avoid the checking bottleneck r=
epeatedly, assuming script unchanged and dependencies too
+                    checkDependances =3D false;
+                    logger
+                            .debug("lapse between 2 dependency checks too =
close: no checks");
+                }
+                if (lastCall =3D=3D 0)
+                    checkDependances =3D true;// only the first time
+                lastCall =3D startTime;
+                synchronized (jahiaScriptEngine) {
+                    Binding binding =3D new Binding();
+                    binding.setVariable("eventName", eventName);
+                    binding.setVariable("jahiaEvent", je);
+                    jahiaScriptEngine.run(groovyFileName, binding,
+                            checkDependances);
+                }
+                long endTime =3D System.currentTimeMillis();
+                long executionTime =3D endTime - startTime;
+                logger.debug("Groovy script event listener=3D" + groovyFil=
eName
+                        + " event=3D" + eventName + " execution time=3D"
+                        + executionTime + "ms");
+
+            } catch (Throwable t) {
+                logger.error("Error while dispatching to Groovy script : "
+                        + groovyFileName, t);
             }
-            long endTime =3D System.currentTimeMillis();
-            long executionTime =3D endTime - startTime;
-            logger.debug("Groovy script event listener=3D"+ groovyFileName=
 + " event=3D" + eventName + " execution time=3D" + executionTime + "ms");
-
-        } catch (Throwable t) {
-            logger.error ("Error while dispatching to Groovy script : " + =
groovyFileName, t);
         }
     }
 =

-    private String resolveGroovyFullFileName (ProcessingContext processing=
Context) {
+    private String resolveGroovyFullFileName(ProcessingContext processingC=
ontext) {
         String groovyFullFileName;
         StringBuffer nameBuilder =3D new StringBuffer("/jsp/jahia/");
-
-        if (    (processingContext !=3D null) &&
-                (processingContext.getContentPage() !=3D null) &&
-            (processingContext.getContentPage ().getPageTemplate (processi=
ngContext) !=3D null) &&
-            (processingContext.getContentPage ().getPageTemplate (processi=
ngContext).getSourcePath () !=3D null)) {
-            groovyFullFileName =3D processingContext.getContentPage ().
-                    getPageTemplate (processingContext).
-                    getSourcePath ();
-            logger.debug ("template source path :" + groovyFullFileName);
-
-            groovyFullFileName =3D groovyFullFileName.substring (0,
-                    groovyFullFileName.lastIndexOf ("/") + 1) + groovyFile=
Name;
-
-            groovyFullFileName =3D groovyFullFileName.substring(nameBuilde=
r.length());
-
-            logger.debug ("resolvedGroovyFullFileName :" + groovyFullFileN=
ame);
-
-            File groovyScriptFile =3D new File (processingContext.settings=
().getPathResolver().resolvePath(groovyFullFileName));
-            if (!groovyScriptFile.exists ()) {
+        if (processingContext !=3D null
+                && siteEventFile.containsKey(processingContext.getSiteKey(=
)))
+            return (String) siteEventFile.get(processingContext.getSiteKey=
());
+        else if ((processingContext !=3D null)
+                && (processingContext.getSite() !=3D null)
+                && (processingContext.getSite().getHomeContentPage() !=3D =
null)
+                && (processingContext.getSite().getHomeContentPage()
+                        .getPageTemplate(processingContext) !=3D null)
+                && (processingContext.getSite().getHomeContentPage()
+                        .getPageTemplate(processingContext).getSourcePath(=
) !=3D null)) {
+            groovyFullFileName =3D processingContext.getSite()
+                    .getHomeContentPage().getPageTemplate(processingContex=
t)
+                    .getSourcePath();
+            logger.debug("template source path :" + groovyFullFileName);
+
+            groovyFullFileName =3D groovyFullFileName.substring(0,
+                    groovyFullFileName.lastIndexOf("/") + 1)
+                    + groovyFileName;
+
+            groovyFullFileName =3D groovyFullFileName.substring(nameBuilder
+                    .length());
+
+            logger.debug("resolvedGroovyFullFileName :" + groovyFullFileNa=
me);
+
+            File groovyScriptFile =3D new File(processingContext.settings()
+                    .getPathResolver().resolvePath(groovyFullFileName));
+            if (!groovyScriptFile.exists()) {
                 groovyFullFileName =3D defaultPathToGroovy;
             }
+            siteEventFile.put(processingContext.getSiteKey(),
+                    groovyFullFileName);
         } else {
             groovyFullFileName =3D defaultPathToGroovy;
         }
         return groovyFullFileName;
     }
 =

-    public void beforeServicesLoad (JahiaEvent je) {
-        dispatchToGroovyScript ("beforeServicesLoad", je);
+    public void beforeServicesLoad(JahiaEvent je) {
+        dispatchToGroovyScript("beforeServicesLoad", je);
+    }
+
+    public void afterServicesLoad(JahiaEvent je) {
+        dispatchToGroovyScript("afterServicesLoad", je);
     }
 =

-    public void afterServicesLoad (JahiaEvent je) {
-        dispatchToGroovyScript ("afterServicesLoad", je);
+    public void siteAdded(JahiaEvent je) {
+        dispatchToGroovyScript("siteAdded", je);
     }
 =

-    public void beforeFieldActivation (JahiaEvent je) {
-        dispatchToGroovyScript ("beforeFieldActivation", je);
+    public void siteDeleted(JahiaEvent je) {
+        dispatchToGroovyScript("siteDeleted", je);
     }
 =

-    public void fieldAdded (JahiaEvent je) {
-        dispatchToGroovyScript ("fieldAdded", je);
+    public void beforeFieldActivation(JahiaEvent je) {
+        dispatchToGroovyScript("beforeFieldActivation", je);
     }
 =

-    public void fieldUpdated (JahiaEvent je) {
-        dispatchToGroovyScript ("fieldUpdated", je);
+    public void fieldAdded(JahiaEvent je) {
+        dispatchToGroovyScript("fieldAdded", je);
     }
 =

-    public void fieldDeleted (JahiaEvent je) {
-        dispatchToGroovyScript ("fieldDeleted", je);
+    public void fieldUpdated(JahiaEvent je) {
+        dispatchToGroovyScript("fieldUpdated", je);
     }
 =

-    public void addContainerEngineAfterInit (JahiaEvent je) {
-        dispatchToGroovyScript ("addContainerEngineAfterInit", je);
+    public void fieldDeleted(JahiaEvent je) {
+        dispatchToGroovyScript("fieldDeleted", je);
     }
 =

-    public void addContainerEngineBeforeSave (JahiaEvent je) {
-        dispatchToGroovyScript ("addContainerEngineBeforeSave", je);
+    public void beforeContainerActivation(JahiaEvent je) {
+        dispatchToGroovyScript("beforeContainerActivation", je);
     }
 =

-    public void containerAdded (JahiaEvent je) {
-        dispatchToGroovyScript ("containerAdded", je);
+    public void containerValidation(JahiaEvent je) {
+        dispatchToGroovyScript("containerValidation", je);
     }
 =

-    public void containerUpdated (JahiaEvent je) {
-        dispatchToGroovyScript ("containerUpdated", je);
+    public void addContainerEngineAfterSave(JahiaEvent je) {
+        dispatchToGroovyScript("addContainerEngineAfterSave", je);
     }
 =

-    public void containerDeleted (JahiaEvent je) {
-        dispatchToGroovyScript ("containerDeleted", je);
+    public void addContainerEngineBeforeSave(JahiaEvent je) {
+        dispatchToGroovyScript("addContainerEngineBeforeSave", je);
     }
 =

-    public void pageAdded (JahiaEvent je) {
-        dispatchToGroovyScript ("pageAdded", je);
+    public void addContainerEngineAfterInit(JahiaEvent je) {
+        dispatchToGroovyScript("addContainerEngineAfterInit", je);
     }
 =

-    public void pageLoaded (JahiaEvent je) {
-        dispatchToGroovyScript ("pageLoaded", je);
+    public void updateContainerEngineBeforeSave(JahiaEvent je) {
+        dispatchToGroovyScript("updateContainerEngineBeforeSave", je);
     }
 =

-    public void pagePropertiesSet (JahiaEvent je) {
-        dispatchToGroovyScript ("pagePropertiesSet", je);
+    public void updateContainerEngineAfterInit(JahiaEvent je) {
+        dispatchToGroovyScript("updateContainerEngineAfterInit", je);
     }
 =

-    public void userPropertiesSet (JahiaEvent je) {
-        dispatchToGroovyScript ("userPropertiesSet", je);
+    public void containerAdded(JahiaEvent je) {
+        dispatchToGroovyScript("containerAdded", je);
     }
 =

-    public void containerListPropertiesSet (JahiaEvent je) {
-        dispatchToGroovyScript ("containerListPropertiesSet", je);
+    public void containerUpdated(JahiaEvent je) {
+        dispatchToGroovyScript("containerUpdated", je);
     }
 =

-    public void rightsSet (JahiaEvent je) {
-        dispatchToGroovyScript ("rightsSet", je);
+    public void containerDeleted(JahiaEvent je) {
+        dispatchToGroovyScript("containerDeleted", je);
     }
 =

-    public void userLoggedIn (JahiaEvent je) {
-        dispatchToGroovyScript ("userLoggedIn", je);
+    public void pageAdded(JahiaEvent je) {
+        dispatchToGroovyScript("pageAdded", je);
     }
 =

-    public void userLoggedOut (JahiaEvent je) {
-        dispatchToGroovyScript ("userLoggedOut", je);
+    public void pageLoaded(JahiaEvent je) {
+        dispatchToGroovyScript("pageLoaded", je);
     }
 =

-    public void beforeContainerActivation (JahiaEvent je) {
-        dispatchToGroovyScript ("beforeContainerActivation", je);
+    public void pagePropertiesSet(JahiaEvent je) {
+        dispatchToGroovyScript("pagePropertiesSet", je);
     }
 =

-    public void updateContainerEngineBeforeSave (JahiaEvent je) {
-        dispatchToGroovyScript ("updateContainerEngineBeforeSave", je);
+    public void containerListPropertiesSet(JahiaEvent je) {
+        dispatchToGroovyScript("containerListPropertiesSet", je);
     }
 =

-    public void updateContainerEngineAfterInit (JahiaEvent je) {
-        dispatchToGroovyScript ("updateContainerEngineAfterInit", je);
+    public void userPropertiesSet(JahiaEvent je) {
+        dispatchToGroovyScript("userPropertiesSet", je);
     }
 =

-    public void objectChanged (WorkflowEvent we) {
-        dispatchToGroovyScript ("objectChanged", we);
+    public void templateUpdated(JahiaEvent theEvent) {
+        dispatchToGroovyScript("templateUpdated", theEvent);
+    }
+
+    public void categoryUpdated(JahiaEvent theEvent) {
+        dispatchToGroovyScript("categoryUpdated", theEvent);
+    }
+
+    public void rightsSet(JahiaEvent je) {
+        dispatchToGroovyScript("rightsSet", je);
+    }
+
+    public void userLoggedIn(JahiaEvent je) {
+        dispatchToGroovyScript("userLoggedIn", je);
+    }
+
+    public void userLoggedOut(JahiaEvent je) {
+        dispatchToGroovyScript("userLoggedOut", je);
+    }
+
+    public void objectChanged(WorkflowEvent we) {
+        dispatchToGroovyScript("objectChanged", we);
+    }
+
+    public void aggregatedObjectChanged(JahiaEvent je) {
+        dispatchToGroovyScript("aggregatedObjectChanged", je);
     }
 =

     public void beforeStagingContentIsDeleted(JahiaEvent je) {
-        dispatchToGroovyScript ("beforeStagingContentIsDeleted", je);
+        dispatchToGroovyScript("beforeStagingContentIsDeleted", je);
+    }
+
+    public void metadataEngineAfterInit(JahiaEvent theEvent) {
+        dispatchToGroovyScript("metadataEngineAfterInit", theEvent);
     }
 =

-    public void metadataEngineAfterInit (JahiaEvent theEvent) {
-        dispatchToGroovyScript ("metadataEngineAfterInit", theEvent);
+    public void metadataEngineBeforeSave(JahiaEvent theEvent) {
+        dispatchToGroovyScript("metadataEngineBeforeSave", theEvent);
     }
 =

-    public void metadataEngineBeforeSave (JahiaEvent theEvent) {
-        dispatchToGroovyScript ("metadataEngineBeforeSave", theEvent);
+    public void metadataEngineAfterSave(JahiaEvent theEvent) {
+        dispatchToGroovyScript("metadataEngineAfterSave", theEvent);
     }
 =

-    public void metadataEngineAfterSave (JahiaEvent theEvent) {
-        dispatchToGroovyScript ("metadataEngineAfterSave", theEvent);
+    public void afterGroupActivation(ContentActivationEvent theEvent) {
+        dispatchToGroovyScript("afterGroupActivation", theEvent);
     }
 =

-    public void contentActivation (ContentActivationEvent theEvent) {
-        dispatchToGroovyScript ("contentActivation", theEvent);
+    public void contentActivation(ContentActivationEvent theEvent) {
+        dispatchToGroovyScript("contentActivation", theEvent);
     }
 =

-    public void afterGroupActivation (ContentActivationEvent theEvent) {
-        dispatchToGroovyScript ("afterGroupActivation", theEvent);
+    public void aggregatedContentActivation(JahiaEvent theEvent) {
+        dispatchToGroovyScript("aggregatedContentActivation", theEvent);
     }
 =

-    public void contentObjectCreated (JahiaEvent theEvent) {
-        dispatchToGroovyScript ("contentObjectCreated", theEvent);
+    public void contentObjectCreated(JahiaEvent theEvent) {
+        dispatchToGroovyScript("contentObjectCreated", theEvent);
     }
 =

-    public void contentObjectUpdated (JahiaEvent theEvent) {
-        dispatchToGroovyScript ("contentObjectUpdated", theEvent);
+    public void aggregatedContentObjectCreated(JahiaEvent theEvent) {
+        dispatchToGroovyScript("aggregatedContentObjectCreated", theEvent);
+    }
+
+    public void contentObjectUpdated(JahiaEvent theEvent) {
+        dispatchToGroovyScript("contentObjectUpdated", theEvent);
     }
 =

     /**
      * Event fired once a content object has been updated ( changes stored=
 in persistence )
-     *
-     * @param theEvent JahiaEvent
+     * =

+     * @param theEvent
+     *                JahiaEvent
      */
-    public void contentObjectUndoStaging (ContentUndoStagingEvent theEvent=
) {
-        dispatchToGroovyScript ("contentObjectUndoStaging", theEvent);
+    public void contentObjectUndoStaging(ContentUndoStagingEvent theEvent)=
 {
+        dispatchToGroovyScript("contentObjectUndoStaging", theEvent);
     }
 =

     /**
      * Event fired after a call to contentObjectonce a content object has =
been updated ( changes stored in persistence )
-     *
-     * @param theEvent JahiaEvent
+     * =

+     * @param theEvent
+     *                JahiaEvent
      */
-    public void contentObjectDelete (ContentObjectDeleteEvent theEvent) {
-        dispatchToGroovyScript ("contentObjectDelete", theEvent);
+    public void contentObjectDelete(ContentObjectDeleteEvent theEvent) {
+        dispatchToGroovyScript("contentObjectDelete", theEvent);
     }
 =

     /**
      * Event fired on content object restore version
-     *
-     * @param theEvent JahiaEvent
+     * =

+     * @param theEvent
+     *                JahiaEvent
      */
-    public void contentObjectRestoreVersion (ContentObjectRestoreVersionEv=
ent theEvent) {
-        dispatchToGroovyScript ("contentObjectRestoreVersion", theEvent);
+    public void contentObjectRestoreVersion(
+            ContentObjectRestoreVersionEvent theEvent) {
+        dispatchToGroovyScript("contentObjectRestoreVersion", theEvent);
     }
 =

     public void fileManagerAclChanged(JahiaEvent theEvent) {
-        dispatchToGroovyScript ("fileManagerAclChanged", theEvent);
+        dispatchToGroovyScript("fileManagerAclChanged", theEvent);
     }
 =

-    public void templateUpdated(JahiaEvent theEvent) {
-        dispatchToGroovyScript ("templateUpdated", theEvent);
+    public void timeBasedPublishingEvent(RetentionRuleEvent theEvent) {
+        dispatchToGroovyScript("timeBasedPublishingEvent", theEvent);
     }
 =

-    public void timeBasedPublishingEvent( RetentionRuleEvent theEvent ) {
-        dispatchToGroovyScript ("timeBasedPublishingEvent", theEvent);
+    public void aggregatedEventsFlush(JahiaEvent theEvent) {
+        dispatchToGroovyScript("aggregatedEventsFlush", theEvent);
+    }
+
+    public void flushEsiCacheEvent(JahiaEvent theEvent) {
+        dispatchToGroovyScript("flushEsiCacheEvent", theEvent);
+    }
+
+    // Nicol=C3=AF=C2=BF=C2=BDs Charczewski - Neoris Argentina - added 28/=
03/2006 - Begin
+    public void pageDeleted(JahiaEvent theEvent) {
+        dispatchToGroovyScript("pageDeleted", theEvent);
+    }
+
+    public void pageAccepted(JahiaEvent theEvent) {
+        dispatchToGroovyScript("pageAccepted", theEvent);
+    }
+
+    public void pageRejected(JahiaEvent theEvent) {
+        dispatchToGroovyScript("pageRejected", theEvent);
+    }
+
+    public void templateAdded(JahiaEvent theEvent) {
+        dispatchToGroovyScript("templateAdded", theEvent);
+    }
+
+    public void templateDeleted(JahiaEvent theEvent) {
+        dispatchToGroovyScript("templateDeleted", theEvent);
+    }
+
+    public void userAdded(JahiaEvent theEvent) {
+        dispatchToGroovyScript("userAdded", theEvent);
+    }
+
+    public void userDeleted(JahiaEvent theEvent) {
+        dispatchToGroovyScript("userDeleted", theEvent);
+    }
+
+    public void userUpdated(JahiaEvent theEvent) {
+        dispatchToGroovyScript("userUpdated", theEvent);
+    }
+
+    public void groupAdded(JahiaEvent theEvent) {
+        dispatchToGroovyScript("groupAdded", theEvent);
+    }
+
+    public void groupDeleted(JahiaEvent theEvent) {
+        dispatchToGroovyScript("groupDeleted", theEvent);
+    }
+
+    public void groupUpdated(JahiaEvent theEvent) {
+        dispatchToGroovyScript("groupUpdated", theEvent);
+        super.groupUpdated(theEvent);
+    }
+
+    public static void registerEvents(String eventsToHandleList) {
+        if (!staticeventsToHandleList.equals(eventsToHandleList)) {
+            staticeventsToHandleList =3D eventsToHandleList;
+            String eventsToHandle[] =3D eventsToHandleList.split(",");
+            eventsHandled =3D new FastHashMap(64);
+            for (int i =3D 0; i < eventsToHandle.length; i++) {
+                String s =3D eventsToHandle[i];
+                eventsHandled.put(s, s);
+            }
+        }
     }
 =

+    // this flag could be use to control the repeated dependencies check f=
rom groovy script
+    public static boolean enabledPerformanceMode =3D true;
 }

Modified: trunk/core/src/java/org/jahia/services/events/JSPEventListener.ja=
va
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/services/events/JSPEventListener.java&rev=3D18201&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/core/src/java/org/jahia/services/events/JSPEventListener.java (or=
iginal)
+++ trunk/core/src/java/org/jahia/services/events/JSPEventListener.java Fri=
 Aug 17 16:13:53 2007
@@ -100,8 +100,8 @@
             String jspFileName =3D resolveJSPFullFileName (processingConte=
xt);
 =

             if (logger.isDebugEnabled())
-               logger.debug ("Dispatching to JSP " + jspFileName +
-                    " for processing of event " + eventName);
+                               logger.debug("Dispatching to JSP " + jspFileName
+                                               + " for processing of event " + 
eventName);
             if (paramBean !=3D null && paramBean.getRequest()!=3Dnull) {
                 paramBean.getRequest ().setAttribute ("eventName", eventNa=
me);
                 paramBean.getRequest ().setAttribute ("jahiaEvent", je);
@@ -111,7 +111,9 @@
                 long endTime =3D System.currentTimeMillis();
                 long executionTime =3D endTime - startTime;
                 if (logger.isDebugEnabled())
-                       logger.debug("JSP Event Listener "+ jspFileName + " 
event=
=3D" + eventName + " execution time=3D" + executionTime + "ms");
+                                       logger.debug("JSP Event Listener " + 
jspFileName
+                                                       + " event=3D" + 
eventName + " execution time=3D"
+                                                       + executionTime + "ms");
             } else {
                 logger.warn("ParamBean is null, why ?");
             }
@@ -158,10 +160,18 @@
         dispatchToJSP ("afterServicesLoad", je);
     }
 =

+    public void siteAdded(JahiaEvent je) {
+        dispatchToJSP("siteAdded", je);
+    }
+
+    public void siteDeleted(JahiaEvent je) {
+        dispatchToJSP("siteDeleted", je);
+    }    =

+
     public void beforeFieldActivation (JahiaEvent je) {
         dispatchToJSP ("beforeFieldActivation", je);
     }
-
+    =

     public void fieldAdded (JahiaEvent je) {
         dispatchToJSP ("fieldAdded", je);
     }
@@ -174,12 +184,32 @@
         dispatchToJSP ("fieldDeleted", je);
     }
 =

-    public void addContainerEngineAfterInit (JahiaEvent je) {
-        dispatchToJSP ("addContainerEngineAfterInit", je);
+    public void beforeContainerActivation (JahiaEvent je) {
+        dispatchToJSP ("beforeContainerActivation", je);
+    }
+    =

+    public void containerValidation(JahiaEvent je) {
+        dispatchToJSP("containerValidation", je);
+    }
+
+    public void addContainerEngineAfterSave(JahiaEvent je) {
+        dispatchToJSP("addContainerEngineAfterSave", je);
     }
 =

     public void addContainerEngineBeforeSave (JahiaEvent je) {
         dispatchToJSP ("addContainerEngineBeforeSave", je);
+    }    =

+    =

+    public void addContainerEngineAfterInit (JahiaEvent je) {
+        dispatchToJSP ("addContainerEngineAfterInit", je);
+    }
+
+    public void updateContainerEngineBeforeSave (JahiaEvent je) {
+        dispatchToJSP ("updateContainerEngineBeforeSave", je);
+    }
+
+    public void updateContainerEngineAfterInit (JahiaEvent je) {
+        dispatchToJSP ("updateContainerEngineAfterInit", je);
     }
 =

     public void containerAdded (JahiaEvent je) {
@@ -206,14 +236,22 @@
         dispatchToJSP ("pagePropertiesSet", je);
     }
 =

+    public void containerListPropertiesSet (JahiaEvent je) {
+        dispatchToJSP ("containerListPropertiesSet", je);
+    }    =

+    =

     public void userPropertiesSet (JahiaEvent je) {
         dispatchToJSP ("userPropertiesSet", je);
     }
-
-    public void containerListPropertiesSet (JahiaEvent je) {
-        dispatchToJSP ("containerListPropertiesSet", je);
+    =

+    public void templateUpdated(JahiaEvent theEvent) {
+        dispatchToJSP ("templateUpdated", theEvent);
     }
-
+ =

+    public void categoryUpdated(JahiaEvent theEvent) {
+        dispatchToJSP ("categoryUpdated", theEvent);
+    }
+    =

     public void rightsSet (JahiaEvent je) {
         dispatchToJSP ("rightsSet", je);
     }
@@ -226,21 +264,13 @@
         dispatchToJSP ("userLoggedOut", je);
     }
 =

-    public void beforeContainerActivation (JahiaEvent je) {
-        dispatchToJSP ("beforeContainerActivation", je);
-    }
-
-    public void updateContainerEngineBeforeSave (JahiaEvent je) {
-        dispatchToJSP ("updateContainerEngineBeforeSave", je);
-    }
-
-    public void updateContainerEngineAfterInit (JahiaEvent je) {
-        dispatchToJSP ("updateContainerEngineAfterInit", je);
-    }
-
     public void objectChanged (WorkflowEvent we) {
         dispatchToJSP ("objectChanged", we);
     }
+    =

+    public void aggregatedObjectChanged(JahiaEvent je) {
+        dispatchToJSP("aggregatedObjectChanged", je);
+    }    =

 =

     public void beforeStagingContentIsDeleted(JahiaEvent je) {
         dispatchToJSP ("beforeStagingContentIsDeleted", je);
@@ -258,17 +288,25 @@
         dispatchToJSP ("metadataEngineAfterSave", theEvent);
     }
 =

-    public void contentActivation (ContentActivationEvent theEvent) {
-        dispatchToJSP ("contentActivation", theEvent);
-    }
-
     public void afterGroupActivation (ContentActivationEvent theEvent) {
         dispatchToJSP ("afterGroupActivation", theEvent);
     }
+    =

+    public void contentActivation (ContentActivationEvent theEvent) {
+        dispatchToJSP ("contentActivation", theEvent);
+    }
 =

+    public void aggregatedContentActivation(JahiaEvent theEvent) {
+        dispatchToJSP("aggregatedContentActivation", theEvent);
+    }    =

+    =

     public void contentObjectCreated (JahiaEvent theEvent) {
         dispatchToJSP ("contentObjectCreated", theEvent);
     }
+    =

+    public void aggregatedContentObjectCreated(JahiaEvent theEvent) {
+        dispatchToJSP("aggregatedContentObjectCreated", theEvent);
+    }    =

 =

     public void contentObjectUpdated (JahiaEvent theEvent) {
         dispatchToJSP ("contentObjectUpdated", theEvent);
@@ -305,12 +343,62 @@
         dispatchToJSP ("fileManagerAclChanged", theEvent);
     }
 =

-    public void templateUpdated(JahiaEvent theEvent) {
-        dispatchToJSP ("templateUpdated", theEvent);
-    }
-
     public void timeBasedPublishingEvent( RetentionRuleEvent theEvent ) {
         dispatchToJSP ("timeBasedPublishingEvent", theEvent);
     }
 =

+    public void aggregatedEventsFlush(JahiaEvent theEvent) {
+        dispatchToJSP("aggregatedEventsFlush", theEvent);
+    }
+
+    public void flushEsiCacheEvent(JahiaEvent theEvent) {
+        dispatchToJSP("flushEsiCacheEvent", theEvent);
+    }
+
+    // Nicol=C3=AF=C2=BF=C2=BDs Charczewski - Neoris Argentina - added 28/=
03/2006 - Begin
+    public void pageDeleted(JahiaEvent theEvent) {
+        dispatchToJSP("pageDeleted", theEvent);
+    }
+
+    public void pageAccepted(JahiaEvent theEvent) {
+        dispatchToJSP("pageAccepted", theEvent);
+    }
+
+    public void pageRejected(JahiaEvent theEvent) {
+        dispatchToJSP("pageRejected", theEvent);
+    }
+
+    public void templateAdded(JahiaEvent theEvent) {
+        dispatchToJSP("templateAdded", theEvent);
+    }
+
+    public void templateDeleted(JahiaEvent theEvent) {
+        dispatchToJSP("templateDeleted", theEvent);
+    }
+
+    public void userAdded(JahiaEvent theEvent) {
+        dispatchToJSP("userAdded", theEvent);
+    }
+
+    public void userDeleted(JahiaEvent theEvent) {
+        dispatchToJSP("userDeleted", theEvent);
+    }
+
+    public void userUpdated(JahiaEvent theEvent) {
+        dispatchToJSP("userUpdated", theEvent);
+    }
+
+    public void groupAdded(JahiaEvent theEvent) {
+        dispatchToJSP("groupAdded", theEvent);
+    }
+
+    public void groupDeleted(JahiaEvent theEvent) {
+        dispatchToJSP("groupDeleted", theEvent);
+    }
+
+    public void groupUpdated(JahiaEvent theEvent) {
+        dispatchToJSP("groupUpdated", theEvent);
+        super.groupUpdated(theEvent);
+    }
+    =

 }

Added: trunk/core/src/java/org/jahia/services/events/JahiaGroovyEngine.java
URL: https://svndev.jahia.net/websvn/filedetails.php?path=3D/trunk/core/src=
/java/org/jahia/services/events/JahiaGroovyEngine.java&rev=3D18201&repname=
=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/core/src/java/org/jahia/services/events/JahiaGroovyEngine.java (a=
dded)
+++ trunk/core/src/java/org/jahia/services/events/JahiaGroovyEngine.java Fr=
i Aug 17 16:13:53 2007
@@ -0,0 +1,182 @@
+package org.jahia.services.events;
+
+import groovy.lang.Binding;
+import groovy.lang.GroovyClassLoader;
+import groovy.lang.Script;
+import groovy.util.GroovyScriptEngine;
+import groovy.util.ResourceConnector;
+import groovy.util.ResourceException;
+import groovy.util.ScriptException;
+import org.codehaus.groovy.control.CompilationFailedException;
+import org.codehaus.groovy.runtime.InvokerHelper;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Jahia groovy script engine
+ *
+ */
+public class JahiaGroovyEngine extends GroovyScriptEngine {
+
+   private static org.apache.log4j.Logger logger =3D
+            org.apache.log4j.Logger.getLogger (JahiaGroovyEngine.class);
+
+     private static class ScriptCacheEntry {
+        private Class scriptClass;
+        private long lastModified;
+        private Map dependencies =3D new HashMap();
+    }
+
+    //private URL[] roots;
+    private Map scriptCache =3D Collections.synchronizedMap(new HashMap());
+    private ResourceConnector rc;
+
+    /**
+     * The groovy script engine will run groovy scripts and reload them and
+     * their dependencies when they are modified. This is useful for embed=
ding
+     * groovy in other containers like games and application servers.
+     *
+     * @param roots This an array of URLs where Groovy scripts will be sto=
red. They should
+     *              be layed out using their package structure like Java c=
lasses
+     */
+    public JahiaGroovyEngine(URL[] roots) {
+        super(roots);
+        this.rc=3Dthis;
+        logger.debug("length URLS:"+roots.length);
+        for(int i=3D0;i<roots.length;i++){
+            logger.debug(i+" "+roots[i].getFile());
+        }
+
+    }
+
+     /**
+     * Run a script identified by name with dependencies control.
+     *
+     * @param scriptName name of the script to run
+     * @param binding binding to pass to the script
+     * @param DependenciesCheck boolean to control dependency check
+     * @return an object
+     * @throws groovy.util.ResourceException resource issue
+     * @throws groovy.util.ScriptException script parsing issue
+     */
+    public Object run(String scriptName, Binding binding,boolean Dependenc=
iesCheck) throws ResourceException, ScriptException {
+        ScriptCacheEntry entry =3D updateCacheEntry(scriptName, getParentC=
lassLoader(),DependenciesCheck);
+        Script scriptObject =3D InvokerHelper.createScript(entry.scriptCla=
ss, binding);
+        return scriptObject.run();
+    }
+
+    /**
+     * Locate the class and reload it or any of its dependencies
+     * (from private method of parent class)
+     * @param scriptName
+     * @param parentClassLoader
+     * @return the scriptName cache entry
+     * @throws ResourceException
+     * @throws ScriptException
+     */
+    private ScriptCacheEntry updateCacheEntry(String scriptName, final Cla=
ssLoader parentClassLoader, boolean dependenciesCheck)
+            throws ResourceException, ScriptException
+    {
+        ScriptCacheEntry entry;
+
+        scriptName =3D scriptName.intern();
+        synchronized (scriptName) {
+
+            URLConnection groovyScriptConn =3D rc.getResourceConnection(sc=
riptName);
+
+            // URL last modified
+            long lastModified =3D groovyScriptConn.getLastModified();
+            // Check the cache for the scriptName
+            entry =3D (ScriptCacheEntry) scriptCache.get(scriptName);
+            // If the entry isn't null check all the dependencies
+
+            boolean dependencyOutOfDate =3D false;
+
+            //checks only if dependenciesCheck is requested by caller or s=
cript is modified
+            if ((entry !=3D null && dependenciesCheck)||(entry !=3D null &=
& entry.lastModified < lastModified)) {
+
+                logger.debug("checking "+entry.dependencies.keySet().size(=
)+" dependencies");
+                for (Iterator i =3D entry.dependencies.keySet().iterator()=
; i.hasNext();) {
+                    URLConnection urlc =3D null;
+                    URL url =3D (URL) i.next();
+                    try {
+                        urlc =3D url.openConnection();
+                        urlc.setDoInput(false);
+                        urlc.setDoOutput(false);
+                        long dependentLastModified =3D urlc.getLastModifie=
d();
+                        if (dependentLastModified > ((Long) entry.dependen=
cies.get(url)).longValue()) {
+                            dependencyOutOfDate =3D true;
+                            break;
+                        }
+                    } catch (IOException ioe) {
+                        dependencyOutOfDate =3D true;
+                        break;
+                    }
+                }
+                =

+            }
+
+            if (entry =3D=3D null || entry.lastModified < lastModified || =
dependencyOutOfDate) {
+                String loggermessage=3D"updating cache entry because ";
+                if(entry =3D=3D null)
+                     loggermessage+=3D"entry is null, creating...";
+                if(entry !=3D null && entry.lastModified < lastModified)
+                     loggermessage+=3D"entry is modified, updating...";
+                if(dependencyOutOfDate)
+                    loggermessage+=3D"dependencies need to be updated";
+                logger.debug(loggermessage);
+                // Make a new entry
+                entry =3D new ScriptCacheEntry();
+
+                // Closure variable
+                final ScriptCacheEntry finalEntry =3D entry;
+
+                // Compile the scriptName into an object
+                GroovyClassLoader groovyLoader =3D
+                        (GroovyClassLoader) AccessController.doPrivileged(=
new PrivilegedAction() {
+                            public Object run() {
+                                return new GroovyClassLoader(parentClassLo=
ader) {
+                                    protected Class findClass(String class=
Name) throws ClassNotFoundException {
+                                        String filename =3D className.repl=
ace('.', File.separatorChar) + ".groovy";
+                                        URLConnection dependentScriptConn =
=3D null;
+                                        try {
+                                            dependentScriptConn =3D rc.get=
ResourceConnection(filename);
+                                            finalEntry.dependencies.put(
+                                                    dependentScriptConn.ge=
tURL(),
+                                                    new Long(dependentScri=
ptConn.getLastModified()));
+                                        } catch (ResourceException e1) {
+                                            throw new ClassNotFoundExcepti=
on("Could not read " + className + ": " + e1);
+                                        }
+                                        try {
+                                            return parseClass(dependentScr=
iptConn.getInputStream(), filename);
+                                        } catch (CompilationFailedExceptio=
n e2) {
+                                            throw new ClassNotFoundExcepti=
on("Syntax error in " + className + ": " + e2);
+                                        } catch (IOException e2) {
+                                            throw new ClassNotFoundExcepti=
on("Problem reading " + className + ": " + e2);
+                                        }
+                                    }
+                                };
+                            }
+                        });
+
+                try {
+                    entry.scriptClass =3D groovyLoader.parseClass(groovySc=
riptConn.getInputStream(), scriptName);
+                } catch (Exception e) {
+                    throw new ScriptException("Could not parse scriptName:=
 " + scriptName, e);
+                }
+                entry.lastModified =3D lastModified;
+                scriptCache.put(scriptName, entry);
+            }
+        }
+        return entry;
+    }
+}

Modified: trunk/core/src/webapp/WEB-INF/etc/spring/applicationcontext-basej=
ahiaconfig.xml
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/webapp=
/WEB-INF/etc/spring/applicationcontext-basejahiaconfig.xml&rev=3D18201&repn=
ame=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/core/src/webapp/WEB-INF/etc/spring/applicationcontext-basejahiaco=
nfig.xml (original)
+++ trunk/core/src/webapp/WEB-INF/etc/spring/applicationcontext-basejahiaco=
nfig.xml Fri Aug 17 16:13:53 2007
@@ -172,7 +172,7 @@
         </property>
     </bean>
 =

-    <bean id=3D"groovyScriptEngine" class=3D"groovy.util.GroovyScriptEngin=
e">
+    <bean id=3D"groovyScriptEngine" class=3D"org.jahia.services.events.Jah=
iaGroovyEngine">
         <constructor-arg>
             <list>
                 <value>file:///${jahiaWebAppRoot}/WEB-INF/var/scripts/groo=
vy/</value>

_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list

Reply via email to