Update of 
/var/cvs/contributions/CMSContainer/cmsc/portal/src/java/com/finalist/pluto/portalImpl/aggregation
In directory 
james.mmbase.org:/tmp/cvs-serv15973/cmsc/portal/src/java/com/finalist/pluto/portalImpl/aggregation

Modified Files:
        ScreenFragment.java PortletFragment.java 
Log Message:
CMSC-1030 Add expires http headers based on portlet definition and view


See also: 
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer/cmsc/portal/src/java/com/finalist/pluto/portalImpl/aggregation
See also: http://www.mmbase.org/jira/browse/CMSC-1030


Index: ScreenFragment.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer/cmsc/portal/src/java/com/finalist/pluto/portalImpl/aggregation/ScreenFragment.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- ScreenFragment.java 9 May 2008 10:06:55 -0000       1.12
+++ ScreenFragment.java 25 Jul 2008 16:08:10 -0000      1.13
@@ -3,16 +3,15 @@
 import java.io.IOException;
 import java.util.*;
 
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
+import javax.servlet.*;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import com.finalist.cmsc.beans.om.*;
+import com.finalist.cmsc.beans.om.Layout;
+import com.finalist.cmsc.beans.om.Page;
 import com.finalist.cmsc.portalImpl.PortalConstants;
 
 /**
@@ -47,12 +46,31 @@
    public void service(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
       setupRequest(request);
 
+      int expirationCache = -1;
+
       Iterator<PortletFragment> portlets = this.getChildFragments().iterator();
       while (portlets.hasNext()) {
           PortletFragment portlet = portlets.next();
          // let the Portlet do it's thing
          portlet.service(request, response);
+
+         int portletExpiration = portlet.getExpirationCache();
+         if (portletExpiration > -1) {
+            if (expirationCache == -1) {
+               expirationCache = portletExpiration;
+            }
+            else {
+               expirationCache = Math.min(expirationCache, portletExpiration);
+            }
       }
+      }
+
+
+      long expires = System.currentTimeMillis();
+      if (expirationCache > -1) {
+         expires += expirationCache * 1000; // seconds to milliseconds
+      }
+      response.setDateHeader("Expires", expires);
 
       if (page != null) {
          if (layout != null) {
@@ -70,6 +88,7 @@
       else {
          log.error("No page for ScreenFragment");
       }
+
       cleanRequest(request);
    }
 


Index: PortletFragment.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer/cmsc/portal/src/java/com/finalist/pluto/portalImpl/aggregation/PortletFragment.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- PortletFragment.java        9 Jun 2008 21:23:24 -0000       1.13
+++ PortletFragment.java        25 Jul 2008 16:08:10 -0000      1.14
@@ -18,8 +18,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import net.sf.mmapps.commons.util.HttpUtil;
-
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.pluto.PortletContainerException;
@@ -35,6 +34,7 @@
 import com.finalist.cmsc.navigation.ServerUtil;
 import com.finalist.cmsc.portalImpl.PortalConstants;
 import com.finalist.cmsc.portalImpl.headerresource.HeaderResource;
+import com.finalist.cmsc.util.HttpUtil;
 import com.finalist.pluto.portalImpl.core.*;
 import com.finalist.pluto.portalImpl.om.common.impl.PreferenceSetImpl;
 import com.finalist.pluto.portalImpl.om.entity.impl.PortletEntityImpl;
@@ -64,6 +64,7 @@
    private com.finalist.cmsc.beans.om.Portlet portlet;
    private PortletWindow portletWindow;
    private StringWriter storedWriter;
+   private int expirationCache = -1;
 
    private List<HeaderResource> headerResources;
 
@@ -72,6 +73,14 @@
          com.finalist.cmsc.beans.om.Portlet portlet, 
com.finalist.cmsc.beans.om.PortletDefinition definition, View view)
          throws Exception {
       super(layoutId, config, parent);
+
+      if (portlet == null) {
+         throw new IllegalArgumentException("Portlet is null for layoutid " + 
layoutId);
+      }
+      if (definition == null) {
+         throw new IllegalArgumentException("Portlet is null for layoutid " + 
layoutId);
+      }
+
       this.portlet = portlet;
 
       PortletEntityImpl portletEntity = new PortletEntityImpl();
@@ -80,7 +89,6 @@
 
       // for now set CMSC portlet params in the preferences of the portlet
       // entiy
-      if (portlet != null) {
          log.debug("Create - portlet: " + portlet.getId());
 
          PreferenceSetImpl ps = (PreferenceSetImpl) 
portletEntity.getPreferenceSet();
@@ -117,6 +125,33 @@
             ps.add(PortalConstants.CMSC_OM_VIEW_ID, view.getId());
             ps.add(PortalConstants.CMSC_PORTLET_VIEW_TEMPLATE, 
view.getResource());
          }
+
+
+      String expiractionFromDefinition = 
portletEntity.getPortletDefinition().getExpirationCache();
+      /* Portlet spec 1.0 PLT.18.1 Expiration Cache
+       * For a portlet that has not defined expiration cache in the deployment 
descriptor,
+       * if the expiration cache property is set it must be ignored by the 
portlet-container.
+       *
+       * Here we are doing something similar for the expiration settings or 
our Definitions, views and Portlets
+       * which are configured through the database
+       */
+      if (StringUtils.isNotBlank(expiractionFromDefinition)) {
+         try {
+            expirationCache = Integer.valueOf(expiractionFromDefinition);
+         }
+         catch(NumberFormatException nfe) {
+            log.error("Cache expiration in xml is not a number for " + 
portletEntity.getPortletDefinition().getName());
+         }
+
+         if (definition.getExpirationcache() > -1) {
+            expirationCache = definition.getExpirationcache();
+         }
+         if (view != null && view.getExpirationcache() > -1) {
+            expirationCache = Math.min(expirationCache, 
view.getExpirationcache());
+         }
+         if (portlet.getExpirationcache() > -1) {
+            expirationCache = portlet.getExpirationcache();
+         }
       }
 
       portletWindow = new PortletWindowImpl(getKey());
@@ -375,4 +410,10 @@
       headerResources.add(resource);
    }
 
+
+
+   public int getExpirationCache() {
+      return expirationCache;
+   }
+
 }
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to