[gatein-commits] gatein SVN: r5229 - in epp/portal/branches/EPP_5_1_Branch: component/web/resources/src/main/java/org/exoplatform/portal/resource and 3 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Nov 23 11:16:35 EST 2010


Author: thomas.heute at jboss.com
Date: 2010-11-23 11:16:33 -0500 (Tue, 23 Nov 2010)
New Revision: 5229

Modified:
   epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/portal/application/Image.java
   epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/portal/application/ResourceRequestFilter.java
   epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/portal/resource/CachedStylesheet.java
   epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/portal/resource/SkinService.java
   epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java
   epp/portal/branches/EPP_5_1_Branch/web/portal/src/main/webapp/WEB-INF/conf/common/common-configuration.xml
   epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/javascript/JavascriptServlet.java
Log:
JBEPP-659: CSS file are not cached (in the browser)
Rolling back


Modified: epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/portal/application/Image.java
===================================================================
--- epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/portal/application/Image.java	2010-11-23 15:06:13 UTC (rev 5228)
+++ epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/portal/application/Image.java	2010-11-23 16:16:33 UTC (rev 5229)
@@ -19,8 +19,6 @@
 
 package org.exoplatform.portal.application;
 
-import java.util.Date;
-
 /**
  * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
  * @version $Revision$
@@ -31,19 +29,10 @@
    final ImageType type;
 
    final byte[] bytes;
-   
-   final long lastModified;
 
    public Image(ImageType type, byte[] bytes)
    {
       this.type = type;
       this.bytes = bytes;
-//  Remove miliseconds because string of date retrieve from Http header doesn't have miliseconds
-      lastModified = (new Date().getTime() / 1000) * 1000;
    }
-   
-   public long getLastModified() 
-   {
-      return lastModified;
-   }
 }

Modified: epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/portal/application/ResourceRequestFilter.java
===================================================================
--- epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/portal/application/ResourceRequestFilter.java	2010-11-23 15:06:13 UTC (rev 5228)
+++ epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/portal/application/ResourceRequestFilter.java	2010-11-23 16:16:33 UTC (rev 5229)
@@ -36,7 +36,6 @@
 import java.io.OutputStream;
 import java.net.URLDecoder;
 import java.nio.charset.Charset;
-import java.util.Date;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
@@ -65,10 +64,6 @@
 
    private ConcurrentMap<String, FutureTask<Image>> mirroredImageCache = new ConcurrentHashMap<String, FutureTask<Image>>();
 
-   public static final String IF_MODIFIED_SINCE     = "If-Modified-Since";
- 
-   public static final String LAST_MODIFIED     = "Last-Modified";    
-   
    public void afterInit(FilterConfig filterConfig)
    {
       cfg = filterConfig;
@@ -82,19 +77,11 @@
       final String uri = URLDecoder.decode(httpRequest.getRequestURI(), "UTF-8");
       final HttpServletResponse httpResponse = (HttpServletResponse)response;
       ExoContainer portalContainer = getContainer();
-      final SkinService skinService = (SkinService) portalContainer.getComponentInstanceOfType(SkinService.class);
-      long ifModifiedSince = httpRequest.getDateHeader(IF_MODIFIED_SINCE);
+      SkinService skinService = (SkinService)portalContainer.getComponentInstanceOfType(SkinService.class);
 
       //
       if (uri.endsWith(".css"))
       {
-//     Check if cached resource has not been modifed, return 304 code      
-         long cssLastModified = skinService.getLastModified(uri);
-         if (isNotModified(ifModifiedSince, cssLastModified)) {
-            httpResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
-            return;
-         }
-
          final OutputStream out = response.getOutputStream();
          final BinaryOutput output = new BinaryOutput()
          {
@@ -131,9 +118,6 @@
                {
                   httpResponse.setHeader("Cache-Control", "no-cache");
                }
-
-               long lastModified = skinService.getLastModified(uri);
-               processIfModified(lastModified, httpResponse);
             }
          };
 
@@ -208,16 +192,8 @@
                      Image img = futureImg.get();
                      if (img != null)
                      {
-                        //Check if cached resource has not been modifed, return 304 code      
-                        long imgLastModified = img.getLastModified();
-                        if (isNotModified(ifModifiedSince, imgLastModified)) {
-                           httpResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
-                           return;
-                        }
                         httpResponse.setContentType(img.type.getMimeType());
                         httpResponse.setContentLength(img.bytes.length);
-                        processIfModified(imgLastModified, httpResponse);
-                        
                         OutputStream out = httpResponse.getOutputStream();
                         out.write(img.bytes);
                         out.close();
@@ -262,30 +238,6 @@
       }
    }
 
-   /**
-    * Add Last-Modified Http header to HttpServetResponse
-    */
-   public void processIfModified(long lastModified, HttpServletResponse httpResponse) {
-      httpResponse.setDateHeader(ResourceRequestFilter.LAST_MODIFIED, lastModified);
-   }
-
-   /**
-    * If cached resource has not changed since date in http header (If_Modified_Since), return true
-    * Else return false;
-    * @param ifModifedSince - String, and HttpHeader element
-    * @param lastModified
-    * @param httpResponse
-    * @return
-    */
-   public boolean isNotModified(long ifModifedSince, long lastModified) {
-      if (!PropertyManager.isDevelopping()) {
-         if (ifModifedSince >= lastModified) {
-            return true;
-         }
-      }
-      return false;
-   }
-   
    public void destroy()
    {
    }

Modified: epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/portal/resource/CachedStylesheet.java
===================================================================
--- epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/portal/resource/CachedStylesheet.java	2010-11-23 15:06:13 UTC (rev 5228)
+++ epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/portal/resource/CachedStylesheet.java	2010-11-23 16:16:33 UTC (rev 5229)
@@ -24,7 +24,6 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.lang.reflect.UndeclaredThrowableException;
-import java.util.Date;
 
 /**
  * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
@@ -41,8 +40,6 @@
 
    /** . */
    private final byte[] bytes;
-   
-   private long lastModified;
 
    public CachedStylesheet(String text)
    {
@@ -62,18 +59,11 @@
       //
       this.text = text;
       this.bytes = bytes;
-//  Remove miliseconds because string of date retrieve from Http header doesn't have miliseconds 
-      lastModified = (new Date().getTime() / 1000) * 1000;
    }
 
    public String getText()
    {
       return text;
-   }   
-
-   public long getLastModified()
-   {
-      return lastModified;
    }
 
    public void writeTo(BinaryOutput output) throws IOException

Modified: epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/portal/resource/SkinService.java
===================================================================
--- epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/portal/resource/SkinService.java	2010-11-23 15:06:13 UTC (rev 5228)
+++ epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/portal/resource/SkinService.java	2010-11-23 16:16:33 UTC (rev 5229)
@@ -48,7 +48,6 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Date;
 import java.util.EnumMap;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -440,9 +439,6 @@
       // Try cache first
       if (!PropertyManager.isDevelopping())
       {
-         //
-         FutureExoCache<String, CachedStylesheet, Orientation> cache = orientation == Orientation.LT ? ltCache : rtCache;
-         CachedStylesheet cachedCss = cache.get(orientation, path);
 
          if (path.startsWith("/" + portalContainerName + "/resource"))
          {
@@ -476,7 +472,6 @@
             cachedCss = new CachedStylesheet(css);
             cache.put(path, cachedCss);
          }
-
          cachedCss.writeTo(renderer.getOutput());
       }
       else
@@ -554,41 +549,6 @@
    }
 
    /**
-    * Return last modifed date of cached css
-    * Return null if cached css can not be found
-    * @param path - path must not be null
-    */
-   public long getLastModified(String path)
-   {
-      if (path == null)
-      {
-         throw new IllegalArgumentException("path must not be null");
-      }
-
-      FutureExoCache<String, CachedStylesheet, Orientation> cache = ltCache;
-      Orientation orientation = Orientation.LT;
-      if (path.endsWith("-lt.css"))
-      {
-         path = path.substring(0, path.length() - "-lt.css".length()) + ".css";
-      }
-      else if (path.endsWith("-rt.css"))
-      {
-         path = path.substring(0, path.length() - "-rt.css".length()) + ".css";
-         orientation = Orientation.RT;
-      }
-
-      CachedStylesheet cachedCSS = cache.get(orientation, path);
-      if (cachedCSS == null)
-      {
-         return Long.MAX_VALUE;
-      }
-      else
-      {
-         return cachedCSS.getLastModified();
-      }
-   }
-
-   /**
     * Remove SkinConfig from Portal Skin Configs  by module and skin name
     * @param module
     * @param skinName
@@ -918,4 +878,4 @@
       DefaultServletContainerFactory.getInstance().getServletContainer().removeWebAppListener(deployer);
       DefaultServletContainerFactory.getInstance().getServletContainer().removeWebAppListener(removal);
    }
-}
+}
\ No newline at end of file

Modified: epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java
===================================================================
--- epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java	2010-11-23 15:06:13 UTC (rev 5228)
+++ epp/portal/branches/EPP_5_1_Branch/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java	2010-11-23 16:16:33 UTC (rev 5229)
@@ -40,7 +40,6 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -65,8 +64,6 @@
    private HashMap<String, String> extendedJavascripts;
 
    private byte[] jsBytes = null;
-   
-   private long lastModified = Long.MAX_VALUE;
 
    /** . */
    private JavascriptDeployer deployer;
@@ -281,18 +278,6 @@
     */
    public void writeMergedJavascript(OutputStream out) throws IOException
    {
-      jsBytes = getMergedJavascript();
-
-      //
-      out.write(jsBytes);
-   }
-   
-   /**
-    * Return merged javascript in byte array
-    * @return byte[]
-    */
-   public byte[] getMergedJavascript()
-   {
       if (jsBytes == null)
       {
          // Generate javascript in a buffer
@@ -329,15 +314,10 @@
             log.error("Error when generating minified javascript, will use normal javascript instead", e);
             jsBytes = bytes;
          }
-//         Remove miliseconds because string of date retrieve from Http header doesn't have miliseconds
-         lastModified = (new Date().getTime() / 1000) * 1000;
       }
-      return jsBytes;
-   }
 
-   public long getLastModified() 
-   {
-      return lastModified;
+      //
+      out.write(jsBytes);
    }
 
    /**
@@ -394,4 +374,4 @@
       DefaultServletContainerFactory.getInstance().getServletContainer().removeWebAppListener(removal);
    }
 
-}
+}
\ No newline at end of file

Modified: epp/portal/branches/EPP_5_1_Branch/web/portal/src/main/webapp/WEB-INF/conf/common/common-configuration.xml
===================================================================
--- epp/portal/branches/EPP_5_1_Branch/web/portal/src/main/webapp/WEB-INF/conf/common/common-configuration.xml	2010-11-23 15:06:13 UTC (rev 5228)
+++ epp/portal/branches/EPP_5_1_Branch/web/portal/src/main/webapp/WEB-INF/conf/common/common-configuration.xml	2010-11-23 16:16:33 UTC (rev 5229)
@@ -171,11 +171,11 @@
         <!-- The white list -->
         <name>white-list</name>
         <!-- We accept anything not black listed -->
-        <value>*</value>
+        <value>localhost</value>
       </values-param>
       <values-param>
         <name>black-list</name>
-        <value>*.evil.org</value>
+        <value>*</value>
       </values-param>
     </init-params>
   </component>

Modified: epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/javascript/JavascriptServlet.java
===================================================================
--- epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/javascript/JavascriptServlet.java	2010-11-23 15:06:13 UTC (rev 5228)
+++ epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/javascript/JavascriptServlet.java	2010-11-23 16:16:33 UTC (rev 5229)
@@ -19,14 +19,10 @@
 
 package org.exoplatform.portal.webui.javascript;
 
-import org.exoplatform.commons.utils.PropertyManager;
 import org.exoplatform.container.ExoContainerContext;
-import org.exoplatform.portal.application.ResourceRequestFilter;
 import org.exoplatform.web.application.javascript.JavascriptConfigService;
 
 import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Date;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
@@ -59,23 +55,14 @@
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException,
       IOException
    {
-      final JavascriptConfigService service =
+      JavascriptConfigService service =
          (JavascriptConfigService)ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(
             JavascriptConfigService.class);
-      long lastModified = service.getLastModified();
-      long ifModifiedSince = request.getDateHeader(ResourceRequestFilter.IF_MODIFIED_SINCE);
-      
+
       // Julien: should we also set charset along with the content type ?
       response.setContentType("application/x-javascript");
-      if (!PropertyManager.isDevelopping()) {
-         if (ifModifiedSince >= lastModified) {
-            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
-            return;
-         }
-      }
-      
-      byte[] jsBytes = service.getMergedJavascript();
-      response.setDateHeader(ResourceRequestFilter.LAST_MODIFIED, lastModified);
-      response.getOutputStream().write(jsBytes);      
+      ServletOutputStream stream = response.getOutputStream();
+      service.writeMergedJavascript(stream);
    }
+
 }



More information about the gatein-commits mailing list