Author: tdraier
Date: Wed Jul 25 18:27:53 2007
New Revision: 18058

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D18058&repname=
=3Djahia
Log:
ContainerCache updates
-integrate caching into <content:container> tag (deactivated by default)
-updated <content:cache-container> tag with optional cacheKey for different=
 rendering =

-improved keys (acl group sharing, cacheKey)
-invalidation listener

Added:
    branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/cache/Cac=
heEventListener.java
Modified:
    branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/dao/Jahi=
aAclDAO.java
    branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/manager/=
JahiaAclManager.java
    branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/acl/Jahia=
ACLManagerService.java
    branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/cache/Con=
tainerHTMLCache.java
    branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/taglibs/container/=
ContainerCacheTag.java
    branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/taglibs/container/=
ContainerTag.java
    branches/JAHIA-5-0-SP-BRANCH/core/src/webapp/WEB-INF/etc/config/listene=
rs.registry
    branches/JAHIA-5-0-SP-BRANCH/core/src/webapp/WEB-INF/etc/taglibs/conten=
t.tld

Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/da=
o/JahiaAclDAO.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/hibernate/dao/JahiaAclDAO.java&rev=3D18058&=
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
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/dao/Jahi=
aAclDAO.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/dao/Jahi=
aAclDAO.java Wed Jul 25 18:27:53 2007
@@ -166,6 +166,14 @@
         return ret;
     }
 =

+    public Collection findAllTarget(int type) {
+        String hql =3D "select distinct a.comp_id.target from JahiaAclEntr=
y a where a.comp_id.type=3D?";
+        final HibernateTemplate template =3D getHibernateTemplate();
+        template.setCacheQueries(true);
+        template.setFlushMode(HibernateTemplate.FLUSH_NEVER);
+        return template.find(hql, new Integer(type));
+    }
+
     private void saveOrUpdateEntry(final Map userEntries, String key, Hibe=
rnateTemplate hibernateTemplate)
             throws HibernateException {
         JahiaAclEntry jahiaAclEntry =3D (JahiaAclEntry) userEntries.get(ke=
y);

Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/ma=
nager/JahiaAclManager.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/hibernate/manager/JahiaAclManager.java&rev=
=3D18058&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
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/manager/=
JahiaAclManager.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/manager/=
JahiaAclManager.java Wed Jul 25 18:27:53 2007
@@ -32,6 +32,7 @@
 import org.springframework.orm.ObjectRetrievalFailureException;
 =

 import java.util.List;
+import java.util.Collection;
 =

 /**
  * Created by IntelliJ IDEA.
@@ -132,6 +133,10 @@
         return dao.isGroupUsedInAclEntries(groupName);
     }
 =

+    public Collection findAllTarget(int type) {
+        return dao.findAllTarget(type);
+    }
+
     public void saveAcl(JahiaAcl acl) {
         if(acl.getId()!=3Dnull)  {
             flushCache();

Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/acl=
/JahiaACLManagerService.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/services/acl/JahiaACLManagerService.java&re=
v=3D18058&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
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/acl/Jahia=
ACLManagerService.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/acl/Jahia=
ACLManagerService.java Wed Jul 25 18:27:53 2007
@@ -694,4 +694,13 @@
         }
         return result;
     }
+
+    public Collection getAllUsersInAcl() {
+        return manager.findAllTarget(1);
+    }
+    public Collection getAllGroupsInAcl() {
+        return manager.findAllTarget(2);
+    }
+
+
 }

Added: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/cache/=
CacheEventListener.java
URL: https://svndev.jahia.net/websvn/filedetails.php?path=3D/branches/JAHIA=
-5-0-SP-BRANCH/core/src/java/org/jahia/services/cache/CacheEventListener.ja=
va&rev=3D18058&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
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/cache/Cac=
heEventListener.java (added)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/cache/Cac=
heEventListener.java Wed Jul 25 18:27:53 2007
@@ -0,0 +1,121 @@
+package org.jahia.services.cache;
+
+import org.jahia.data.events.JahiaEventListener;
+import org.jahia.data.events.JahiaEvent;
+import org.jahia.services.workflow.WorkflowEvent;
+import org.jahia.services.fields.ContentField;
+import org.jahia.services.version.EntryLoadRequest;
+import org.jahia.services.containers.ContentContainer;
+import org.jahia.content.*;
+import org.jahia.content.events.ContentActivationEvent;
+import org.jahia.registries.ServicesRegistry;
+import org.jahia.exceptions.JahiaInitializationException;
+import org.jahia.exceptions.JahiaException;
+
+import java.util.*;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: toto
+ * Date: 19 juil. 2007
+ * Time: 17:50:23
+ * To change this template use File | Settings | File Templates.
+ */
+public class CacheEventListener extends JahiaEventListener {
+
+    private ContainerHTMLCache chtmlCache;
+
+
+    public void aggregatedObjectChanged(JahiaEvent je) {
+        List allEvents =3D (List) je.getObject();
+        List myEvents =3D new ArrayList();
+
+        Set viewed =3D new HashSet();
+
+        for (Iterator iterator =3D allEvents.iterator(); iterator.hasNext(=
);) {
+            WorkflowEvent we =3D (WorkflowEvent) iterator.next();
+            ContentObject object =3D (ContentObject) we.getObject();
+            if (object !=3D null) {
+                String languageCode =3D we.getLanguageCode();
+                ContentObjectKey objectKey =3D (ContentObjectKey) object.g=
etObjectKey();
+                Set languageCodes =3D new HashSet();
+                if (ContentField.SHARED_LANGUAGE.equals(languageCode)) {
+                    try {
+                        List locales =3D ServicesRegistry.getInstance().ge=
tJahiaSitesService().getSite(object.getSiteID()).getLanguageSettingsAsLocal=
es(true);
+                        for (Iterator iterator2 =3D locales.iterator(); it=
erator2.hasNext();) {
+                            Locale locale =3D (Locale) iterator2.next();
+                            languageCodes.add(locale.toString());
+                        }
+                    } catch (JahiaException e) {
+                        e.printStackTrace();  //To change body of catch st=
atement use File | Settings | File Templates.
+                    }
+                } else {
+                    languageCodes.add(languageCode);
+                }
+                addObjectKey(objectKey, languageCodes, myEvents, viewed);
+            }
+        }
+        for (Iterator iterator =3D myEvents.iterator(); iterator.hasNext()=
;) {
+            Object[] objs =3D (Object[]) iterator.next();
+            invalidate((ContentContainerKey) objs[0], EntryLoadRequest.STA=
GING_WORKFLOW_STATE, (String) objs[1]);
+        }
+    }
+
+    public void aggregatedContentActivation(JahiaEvent je) {
+        List allEvents =3D (List) je.getObject();
+        List myEvents =3D new ArrayList();
+
+        Set viewed =3D new HashSet();
+
+        for (Iterator iterator =3D allEvents.iterator(); iterator.hasNext(=
);) {
+            ContentActivationEvent ce =3D (ContentActivationEvent) iterato=
r.next();
+            ContentObjectKey object =3D (ContentObjectKey) ce.getObjectKey=
();
+            addObjectKey(object, ce.getLanguageCodes(), myEvents, viewed);
+        }
+        for (Iterator iterator =3D myEvents.iterator(); iterator.hasNext()=
;) {
+            Object[] objs =3D (Object[]) iterator.next();
+            invalidate((ContentContainerKey) objs[0], EntryLoadRequest.ACT=
IVE_WORKFLOW_STATE, (String) objs[1]);
+        }
+    }
+
+    public void rightsSet(JahiaEvent je) {
+        getChtmlCache().rightsUpdated();
+    }
+
+    public ContainerHTMLCache getChtmlCache() {
+        if (chtmlCache =3D=3D null ) {
+            try {
+                chtmlCache =3D ServicesRegistry.getInstance().getCacheServ=
ice().getContainerHTMLCacheInstance();
+            } catch (JahiaInitializationException e) {
+                e.printStackTrace();  //To change body of catch statement =
use File | Settings | File Templates.
+            }
+        }
+        return chtmlCache;
+    }
+
+    private void addObjectKey(ContentObjectKey objectKey, Set languageCode=
s, List myEvents, Set viewed) {
+        if (ContentPageKey.PAGE_TYPE.equals(objectKey.getType())) {
+            objectKey =3D objectKey.getParent(EntryLoadRequest.STAGED);
+        }
+        if (ContentFieldKey.FIELD_TYPE.equals(objectKey.getType())) {
+            objectKey =3D objectKey.getParent(EntryLoadRequest.STAGED);
+        }
+        while (ContentContainerKey.CONTAINER_TYPE.equals(objectKey.getType=
())) {
+            for (Iterator iterator =3D languageCodes.iterator(); iterator.=
hasNext();) {
+                String languageCode =3D iterator.next().toString();
+                String key =3D objectKey + languageCode;
+                if (!viewed.contains(key)) {
+                    myEvents.add(new Object[]{objectKey, languageCode});
+                    viewed.add(key);
+                }
+            }
+            ContentContainerListKey cclk =3D (ContentContainerListKey) obj=
ectKey.getParent(EntryLoadRequest.STAGED);
+            objectKey =3D cclk.getParent(EntryLoadRequest.STAGED);
+        }
+    }
+
+    private void invalidate(ContentContainerKey object, int entryLoadReque=
st, String locale) {
+        getChtmlCache().invalidateContainerEntries(object.getIDInType(), e=
ntryLoadRequest, locale);
+    }
+
+}

Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/cac=
he/ContainerHTMLCache.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/services/cache/ContainerHTMLCache.java&rev=
=3D18058&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
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/cache/Con=
tainerHTMLCache.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/cache/Con=
tainerHTMLCache.java Wed Jul 25 18:27:53 2007
@@ -1,10 +1,11 @@
 package org.jahia.services.cache;
 =

-import org.jahia.bin.Jahia;
-import org.jahia.settings.SettingsBean;
+import org.jahia.services.usermanager.JahiaUser;
+import org.jahia.services.usermanager.JahiaGroup;
+import org.jahia.data.containers.JahiaContainer;
+import org.jahia.registries.ServicesRegistry;
 =

-import java.util.Set;
-import java.util.HashSet;
+import java.util.*;
 =

 /**
  * Created by IntelliJ IDEA.
@@ -23,6 +24,7 @@
 =

     private static final String CONTAINER_PREFIX =3D "CONTAINER-";
     private static final String PARENTCONTAINER_PREFIX =3D "PARENTCONTAINE=
R-";
+    private static final String KEY_PREFIX =3D "KEY-";
     private static final String USERNAME_PREFIX =3D "USERNAME-";
     private static final String LANGUAGECODE_PREFIX =3D "LANGUAGECODE-";
     private static final String WORKFLOWSTATE_PREFIX =3D "WORKFLOWSTATE-";
@@ -40,55 +42,56 @@
      * <p>Builds the cache key that is used to reference the cache entries=
 in the
      * lookup table.</p>
      *
-     * @param parentContainerID the identifier for the parent container ID
-     * @param containerID   the container identification number
-     * @param userName      the user name
+     * @param container   the container identification number
+     * @param group
+     [EMAIL PROTECTED] user          the user name
      * @param languageCode  the language code
      * @param workflowState the workflow state
      * @param scheme        the request scheme (http/https)
-     *
      * @return  the generated cache key
      */
-    public GroupCacheKey computeEntryKey (int parentContainerID,
-                                          int containerID,
-                                          String userName,
-                                          String languageCode,
-                                          int workflowState,
-                                          String scheme)
+    public GroupCacheKey computeEntryKey(
+            JahiaContainer container,
+            String group, JahiaUser user,
+            String languageCode,
+            int workflowState,
+            String scheme)
     {
-        Set compositeKeyElements =3D new HashSet();
-        String containerid =3D CONTAINER_PREFIX + containerID;
-        compositeKeyElements.add(containerid);
-        // compositeKeyElements.add(USERNAME_PREFIX + userName);
-        compositeKeyElements.add(LANGUAGECODE_PREFIX + languageCode);
-        String workflowStateString =3D WORKFLOWSTATE_PREFIX + workflowStat=
e;
-        compositeKeyElements.add(workflowStateString);
-        if (!"http".equals(scheme)) {
-            compositeKeyElements.add(SCHEME_PREFIX + scheme);
-        }
-        compositeKeyElements.add(containerid +workflowStateString);
-        return new GroupCacheKey(compositeKeyElements);
+        int id =3D container.getID();
+        String usercachekey =3D getUserCacheKey(user, container.getSiteID(=
));
+
+        String key =3D getKey(id, workflowState, languageCode, usercacheke=
y, group, scheme);
+
+        return new GroupCacheKey(key, new HashSet());
     }
 =

-    /**
-     * <p>Invalidates all the cache entries related to the specified conta=
iner <code>containerID</code>,
-     * by removing the cache entries.</p>
-     *
-     * @param containerID  the container identification number
-     */
-    public synchronized void invalidateContainerEntries (String containerI=
D) {
-        if (!Jahia.getSettings().lookupBoolean(SettingsBean.OUTPUT_CACHE_A=
CTIVATED))
-            return;
+    public GroupCacheKey computeEntryKeyWithGroups(
+            JahiaContainer container,
+            String group, JahiaUser user,
+            String languageCode,
+            int workflowState,
+            String scheme)
+    {
+        int id =3D container.getID();
+        String usercachekey =3D getUserCacheKey(user, container.getSiteID(=
));
 =

-        if (containerID =3D=3D null) {
-            logger.debug ("Cannot remove a null container ID from the cach=
e!");
-            return;
-        }
-        logger.debug ("Removing cache entries for container ["+ containerI=
D +"]");
+        String key =3D getKey(id, workflowState, languageCode, usercacheke=
y, group, scheme);
 =

-        String pageKey =3D CONTAINER_PREFIX + containerID;
+        Set groups =3D new HashSet();
+        groups.add(CONTAINER_PREFIX + id + WORKFLOWSTATE_PREFIX + workflow=
State + LANGUAGECODE_PREFIX + languageCode);
+        groups.add(USERNAME_PREFIX + usercachekey);
+        return new GroupCacheKey(key, groups);
+    }
 =

-        flushGroup(pageKey);
+    private String getKey(int id, int workflowState, String languageCode, =
String usercachekey, String group, String scheme) {
+        String key =3D id + "-" + workflowState + "-" + languageCode + "-"=
 +usercachekey ;
+        if (group !=3D null) {
+            key +=3D "-" + group;
+        }
+        if (!"http".equals(scheme)) {
+            key +=3D "-" +  scheme;
+        }
+        return key;
     }
 =

     /**
@@ -97,46 +100,61 @@
      *
      * @param containerID  the container identification number
      * @param workflowState the workflow state for which to invalidate the=
 containers.
+     * @param languageCode the language code for which to invalidate the c=
ontainers.
      */
-    public synchronized void invalidatePageEntries (String containerID, in=
t workflowState) {
-        if (!Jahia.getSettings().lookupBoolean(SettingsBean.OUTPUT_CACHE_A=
CTIVATED))
-            return;
+
+    public synchronized void invalidateContainerEntries(String containerID=
, int workflowState, String languageCode) {
 =

         if (containerID =3D=3D null) {
             logger.debug ("Cannot remove a null container ID from the cach=
e!");
             return;
         }
 =

-        logger.debug ("Removing cache entries for page ["+ containerID +"]=
");
+        logger.debug ("Removing cache entries for page ["+ containerID + "=
], workflow ["+workflowState+"], lang ["+languageCode+"]");
 =

-        String pageKey =3D CONTAINER_PREFIX + containerID + WORKFLOWSTATE_=
PREFIX + workflowState;
+        String pageKey =3D CONTAINER_PREFIX + containerID + WORKFLOWSTATE_=
PREFIX + workflowState + LANGUAGECODE_PREFIX + languageCode;
 =

         flushGroup(pageKey);
     }
 =

+    public void rightsUpdated() {
+        SortedSet newgroups =3D new TreeSet(ServicesRegistry.getInstance()=
.getJahiaACLManagerService().getAllGroupsInAcl());
+        if (!newgroups.equals(groups)) {
+            groups =3D newgroups;
+            flush();
+        }
+    }
 =

-    /** <p>Invalidates all the cache entries related to the specified user
-     *  <code>username</code>, by removing the cache entries.</p>
-     *
-     * <p><b>Caution</b>: depending of the HTML cache size, this operation=
 can be
-     * time consumming!</p>
-     *
-     * @param username    the page identification
-     */
-    public synchronized void invalidateUserEntries (String username) {
-        if (!Jahia.getSettings().lookupBoolean(SettingsBean.OUTPUT_CACHE_A=
CTIVATED))
-            return;
+    private String getUserCacheKey(JahiaUser user, int siteID) {
+        String usercachekey;
 =

-        if (username =3D=3D null) {
-            logger.debug ("Cannot remove a null username fromt the cache!"=
);
-            return;
-        }
+        Set users =3D new HashSet(ServicesRegistry.getInstance().getJahiaA=
CLManagerService().getAllUsersInAcl());
+        SortedSet groups =3D getAllGroups();
 =

-        logger.debug ("Removing cache entries for user ["+ username +"]");
+        if (users.contains(user.getUserKey())) {
+            usercachekey =3D user.getUserKey();
+        } else {
+            StringBuffer b =3D new StringBuffer();
+            for (Iterator iterator =3D groups.iterator(); iterator.hasNext=
();) {
+                String groupName =3D (String) iterator.next();
+                JahiaGroup g =3D ServicesRegistry.getInstance().getJahiaGr=
oupManagerService().lookupGroup(groupName);
+                if (g.getSiteID() =3D=3D siteID && g.isMember(user)) {
+                    b.append(groupName);
+                    b.append("|");
+                }
+            }
+            usercachekey =3D b.toString();
+        }
+        return usercachekey;
+    }
 =

-        String userKey =3D USERNAME_PREFIX + username;
+    private SortedSet groups;
 =

-        flushGroup(userKey);
+    private synchronized SortedSet getAllGroups() {
+        if (groups =3D=3D null) {
+            groups =3D new TreeSet(ServicesRegistry.getInstance().getJahia=
ACLManagerService().getAllGroupsInAcl());
+        }
+        return groups;
     }
 =

 }

Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/taglibs/cont=
ainer/ContainerCacheTag.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/taglibs/container/ContainerCacheTag.java&re=
v=3D18058&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
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/taglibs/container/=
ContainerCacheTag.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/taglibs/container/=
ContainerCacheTag.java Wed Jul 25 18:27:53 2007
@@ -34,10 +34,18 @@
     private String containerContent =3D null;
     private int counter =3D 1;
     private JahiaData jData =3D null;
-
+    private String cacheKey =3D null;
 =

     private boolean display =3D true;
 =

+    public String getCacheKey() {
+        return cacheKey;
+    }
+
+    public void setCacheKey(String cacheKey) {
+        this.cacheKey =3D cacheKey;
+    }
+
     /**
          * @jsp:attribute name=3D"id" required=3D"false" rtexprvalue=3D"tr=
ue"
          * description=3D"id attribute for this tag.
@@ -68,6 +76,7 @@
 =

         ContainerListTag cListTag =3D (ContainerListTag) findAncestorWithC=
lass(this, ContainerListTag.class);
         ContainerTag containerTag =3D (ContainerTag) findAncestorWithClass=
(this, ContainerTag.class);
+        containerTag.setCache("false");
         container =3D containerTag.getContainer();
         containerList =3D cListTag.getContainerList();
         if ((containerList =3D=3D null) || (container =3D=3D null)) {
@@ -77,7 +86,7 @@
         ServletRequest request =3D pageContext.getRequest();
         jData =3D (JahiaData) request.getAttribute("org.jahia.data.JahiaDa=
ta");
         try {
-            containerContent =3D getFromContainerCache(containerList, cont=
ainer, jData);
+            containerContent =3D getFromContainerCache(container, jData);
             if (containerContent !=3D null) {
                 return SKIP_BODY;
             }
@@ -94,7 +103,7 @@
         if (this.display) {
             try {
                 String bodyContent =3D getBodyContent().getString();
-                writeToContainerCache(containerList, container, jData, bod=
yContent);
+                writeToContainerCache(container, jData, bodyContent);
                 getBodyContent().writeOut(getPreviousOut());
                 getBodyContent().clear();
                 this.counter++;
@@ -126,17 +135,15 @@
         firstContainer =3D null;
         containerContent =3D null;
         counter =3D 1;
-
+        cacheKey =3D null;
         jData =3D null;
 =

         display =3D true;
         return EVAL_PAGE;
     }
 =

-    private void writeToContainerCache(JahiaContainerList jahiaContainerLi=
st,
-                                       JahiaContainer jahiaContainer,
-                                       JahiaData jahiaData,
-                                       String bodyContent) throws JahiaIni=
tializationException {
+    private void writeToContainerCache(JahiaContainer jahiaContainer,Jahia=
Data jahiaData,
+            String bodyContent) throws JahiaInitializationException {
         ContainerHTMLCache containerHTMLCache =3D ServicesRegistry.getInst=
ance().getCacheService().getContainerHTMLCacheInstance();
         ProcessingContext processingContext =3D jahiaData.getProcessingCon=
text();
         int workflowState =3D processingContext.getEntryLoadRequest().
@@ -144,17 +151,15 @@
         // Get the language code
         String curLanguageCode =3D LanguageCodeConverters.localeToLanguage=
Tag(
             processingContext.getLocale());
-        GroupCacheKey containerKey =3D containerHTMLCache.computeEntryKey(=
jahiaContainerList.getParentEntryID(),
-                jahiaContainer.getID(), processingContext.getUser().getUse=
rKey(),
+        GroupCacheKey containerKey =3D containerHTMLCache.computeEntryKeyW=
ithGroups(
+                jahiaContainer, cacheKey, processingContext.getUser(),
                 curLanguageCode,
                 workflowState,
                 processingContext.getScheme());
         containerHTMLCache.put(containerKey, bodyContent);
     }
 =

-    private String getFromContainerCache(JahiaContainerList jahiaContainer=
List,
-                                       JahiaContainer jahiaContainer,
-                                       JahiaData jahiaData) throws JahiaIn=
itializationException {
+    private String getFromContainerCache(JahiaContainer jahiaContainer,Jah=
iaData jahiaData) throws JahiaInitializationException {
         ContainerHTMLCache containerHTMLCache =3D ServicesRegistry.getInst=
ance().getCacheService().getContainerHTMLCacheInstance();
         ProcessingContext processingContext =3D jahiaData.getProcessingCon=
text();
         int workflowState =3D processingContext.getEntryLoadRequest().
@@ -162,8 +167,8 @@
         // Get the language code
         String curLanguageCode =3D LanguageCodeConverters.localeToLanguage=
Tag(
             processingContext.getLocale());
-        GroupCacheKey containerKey =3D containerHTMLCache.computeEntryKey(=
jahiaContainerList.getParentEntryID(),
-                jahiaContainer.getID(), processingContext.getUser().getUse=
rKey(),
+        GroupCacheKey containerKey =3D containerHTMLCache.computeEntryKey(
+                jahiaContainer, cacheKey, processingContext.getUser(),
                 curLanguageCode,
                 workflowState,
                 processingContext.getScheme());

Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/taglibs/cont=
ainer/ContainerTag.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/taglibs/container/ContainerTag.java&rev=3D1=
8058&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
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/taglibs/container/=
ContainerTag.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/taglibs/container/=
ContainerTag.java Wed Jul 25 18:27:53 2007
@@ -20,7 +20,6 @@
 import org.jahia.data.beans.ContainerBean;
 import org.jahia.data.containers.JahiaContainer;
 import org.jahia.data.containers.JahiaContainerList;
-import org.jahia.data.containers.JahiaContainerDefinition;
 import org.jahia.params.ProcessingContext;
 import org.jahia.registries.ServicesRegistry;
 import org.jahia.services.cache.ContainerHTMLCache;
@@ -31,6 +30,7 @@
 import javax.servlet.ServletRequest;
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.JspTagException;
+import javax.servlet.jsp.JspWriter;
 import javax.servlet.jsp.tagext.BodyTagSupport;
 import java.io.IOException;
 import java.util.Enumeration;
@@ -57,6 +57,9 @@
 =

     private Enumeration containers;
 =

+    // default value for container caching
+    private static final String CACHING_DEFAULT_VALUE =3D "false";
+
     private boolean first =3D true;
     private boolean last =3D true;
     private JahiaContainer container =3D null;
@@ -65,6 +68,9 @@
     private int counter =3D 1;
     private JahiaData jData =3D null;
 =

+    private String cache =3D CACHING_DEFAULT_VALUE;
+    private String cacheKey =3D "";
+
     private boolean initLoop =3D true;
 =

     private boolean display =3D true;
@@ -88,6 +94,22 @@
         return this.last;
     }
 =

+    public String getCache() {
+        return cache;
+    }
+
+    public void setCache(String cache) {
+        this.cache =3D cache;
+    }
+
+    public String getCacheKey() {
+        return cacheKey;
+    }
+
+    public void setCacheKey(String cacheKey) {
+        this.cacheKey =3D cacheKey;
+    }
+
     public JahiaContainer getContainer() {
         return this.container;
     }
@@ -117,15 +139,12 @@
                 // here is stuff we need to do only once...
                 // reads the containers of this list
                 containers =3D containerList.getContainers();
-                int ct =3D 0;
                 if (containers.hasMoreElements()) {
                     this.container =3D (JahiaContainer)containers.nextElem=
ent();
                     if (getId() !=3D null) {
                         pageContext.setAttribute(getId(), getContainerBean=
());
                     }
-                    if (ct =3D=3D 0) {
-                        this.firstContainer =3D this.container;
-                    }
+                    this.firstContainer =3D this.container;
                     if (containers.hasMoreElements()) {
                         this.last =3D false;
                     }
@@ -134,43 +153,72 @@
                     this.display =3D false;
                 }
                 containers =3D containerList.getContainers();
-                if (containers.hasMoreElements()) {
-                    this.container =3D (JahiaContainer) containers.nextEle=
ment();
-                    if (getId() !=3D null) {
-                        pageContext.setAttribute(getId(), getContainerBean=
());
-                    }
-                } else {
-                    return SKIP_BODY;
-                }
                 initLoop =3D false;
+
+                return processNextContainer(pageContext.getOut());
             }
         return EVAL_BODY_BUFFERED;
     }
 =

+    private int processNextContainer(JspWriter out) throws JspTagException=
 {
+        while (containers.hasMoreElements()) {
+            this.container =3D (JahiaContainer) containers.nextElement();
+            if (getId() !=3D null) {
+                pageContext.setAttribute(getId(), getContainerBean());
+            }
+            // maybe not the first one anymore
+            this.first =3D firstContainer =3D=3D container;
+            // checks if it's the last one
+            if (!containers.hasMoreElements()) {
+                this.last =3D true;
+            }
+
+            ServletRequest request =3D pageContext.getRequest();
+            jData =3D (JahiaData) request.getAttribute("org.jahia.data.Jah=
iaData");
+            if ("true".equals(cache)) {
+                try {
+                    String containerContent =3D getFromContainerCache(cont=
ainer, jData);
+                    if (containerContent !=3D null) {
+                        if ((this.display)) {
+                            try {
+                                out.print(containerContent);
+                            } catch (IOException ioe) {
+                                logger.error("Error displaying container o=
utput", ioe);
+                                throw new JspTagException();
+                            }
+                        }
+                        continue;
+                    }
+                } catch (JahiaInitializationException jie) {
+                    logger.error("Error initializing container rendering",=
 jie);
+                    throw new JspTagException();
+                }
+            }
+            return EVAL_BODY_BUFFERED;
+        }
+        return SKIP_BODY;
+    }
+
 =

     // loops through the next elements
     public int doAfterBody() throws JspException {
         if (this.display) {
             try {
+                if ("true".equals(cache)) {
+                    writeToContainerCache(container, jData, getBodyContent=
().getString());
+                }
                 getBodyContent().writeOut(getPreviousOut());
                 getBodyContent().clear();
                 this.counter++;
             } catch (IOException ioe) {
                 logger.error("Error displaying container output", ioe);
                 throw new JspTagException();
+            } catch (JahiaInitializationException jie) {
+                logger.error("Error displaying container output", jie);
+                throw new JspTagException();
             }
             if (containers.hasMoreElements()) {
-                this.container =3D (JahiaContainer)containers.nextElement(=
);
-                if (getId() !=3D null) {
-                    pageContext.setAttribute(getId(), getContainerBean());
-                }
-                // not the first one anymore
-                this.first =3D false;
-                // checks if it's the last one
-                if (!containers.hasMoreElements()) {
-                    this.last =3D true;
-                }
-                return EVAL_BODY_BUFFERED;
+                return processNextContainer(getPreviousOut());
             } else {
                 this.display =3D false;
             }
@@ -191,6 +239,10 @@
         firstContainer =3D null;
         counter =3D 1;
 =

+        cache =3D CACHING_DEFAULT_VALUE;
+
+        cacheKey =3D "";
+
         initLoop =3D true;
         jData =3D null;
 =

@@ -199,6 +251,39 @@
             pageContext.removeAttribute(getId());
         }
         return EVAL_PAGE;
+    }                          =

+
+    private void writeToContainerCache(JahiaContainer jahiaContainer, Jahi=
aData jahiaData,
+            String bodyContent) throws JahiaInitializationException {
+        ContainerHTMLCache containerHTMLCache =3D ServicesRegistry.getInst=
ance().getCacheService().getContainerHTMLCacheInstance();
+        ProcessingContext processingContext =3D jahiaData.getProcessingCon=
text();
+        int workflowState =3D processingContext.getEntryLoadRequest().
+                            getWorkflowState();
+        // Get the language code
+        String curLanguageCode =3D LanguageCodeConverters.localeToLanguage=
Tag(
+            processingContext.getLocale());
+        GroupCacheKey containerKey =3D containerHTMLCache.computeEntryKeyW=
ithGroups(
+                jahiaContainer, cacheKey, processingContext.getUser(),
+                curLanguageCode,
+                workflowState,
+                processingContext.getScheme());
+        containerHTMLCache.put(containerKey, bodyContent);
+    }
+
+    private String getFromContainerCache(JahiaContainer jahiaContainer, Ja=
hiaData jahiaData) throws JahiaInitializationException {
+        ContainerHTMLCache containerHTMLCache =3D ServicesRegistry.getInst=
ance().getCacheService().getContainerHTMLCacheInstance();
+        ProcessingContext processingContext =3D jahiaData.getProcessingCon=
text();
+        int workflowState =3D processingContext.getEntryLoadRequest().
+                            getWorkflowState();
+        // Get the language code
+        String curLanguageCode =3D LanguageCodeConverters.localeToLanguage=
Tag(
+            processingContext.getLocale());
+        GroupCacheKey containerKey =3D containerHTMLCache.computeEntryKey(
+                jahiaContainer, cacheKey, processingContext.getUser(),
+                curLanguageCode,
+                workflowState,
+                processingContext.getScheme());
+        return (String) containerHTMLCache.get(containerKey);
     }
 =

 }

Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/webapp/WEB-INF/etc/config/l=
isteners.registry
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/webapp/WEB-INF/etc/config/listeners.registry&rev=3D18058&r=
epname=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
--- branches/JAHIA-5-0-SP-BRANCH/core/src/webapp/WEB-INF/etc/config/listene=
rs.registry (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/webapp/WEB-INF/etc/config/listene=
rs.registry Wed Jul 25 18:27:53 2007
@@ -19,7 +19,7 @@
 TimeBasedPublishingEventListener=3Dorg.jahia.services.timebasedpublishing.=
TimeBasedPublishingEventListener
 EsiInvalidationEventListener=3Dorg.jahia.services.esi.EsiInvalidationEvent=
Listener
 SlideSiteListener=3Dorg.jahia.services.webdav.SlideSiteListener
-
+CacheEventListener=3Dorg.jahia.services.cache.CacheEventListener
 #
 # Activate the JSP Event listener if you want to be able to implement JSP
 # listeners using JSP files. In order to do this you can either modify the

Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/webapp/WEB-INF/etc/taglibs/=
content.tld
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/webapp/WEB-INF/etc/taglibs/content.tld&rev=3D18058&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
--- branches/JAHIA-5-0-SP-BRANCH/core/src/webapp/WEB-INF/etc/taglibs/conten=
t.tld (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/webapp/WEB-INF/etc/taglibs/conten=
t.tld Wed Jul 25 18:27:53 2007
@@ -269,6 +269,16 @@
         <required>false</required>
         <rtexprvalue>true</rtexprvalue>
     </attribute>
+    <attribute>
+        <name>cache</name>
+        <required>false</required>
+        <rtexprvalue>true</rtexprvalue>
+    </attribute>
+    <attribute>
+        <name>cacheKey</name>
+        <required>false</required>
+        <rtexprvalue>true</rtexprvalue>
+    </attribute>
   </tag>
 =

     <tag>
@@ -280,6 +290,11 @@
           <required>false</required>
           <rtexprvalue>true</rtexprvalue>
       </attribute>
+        <attribute>
+            <name>cacheKey</name>
+            <required>false</required>
+            <rtexprvalue>true</rtexprvalue>
+        </attribute>
     </tag>
 =

   <tag>

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

Reply via email to