tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1384119 - in /tomcat/sandbox/trunk-resources/java/org/apache/catalina: util/ConcurrentDateFormat.java webresources/FileResource.java webresources/JarResource.java webresources/ResourceBase.java
Date Wed, 12 Sep 2012 20:51:55 GMT
Author: markt
Date: Wed Sep 12 20:51:55 2012
New Revision: 1384119

URL: http://svn.apache.org/viewvc?rev=1384119&view=rev
Log:
Implement some TODOs:
 - getEtag()
 - getLastModifiedHttp()

Modified:
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/util/ConcurrentDateFormat.java
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResource.java
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/ResourceBase.java

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/util/ConcurrentDateFormat.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/util/ConcurrentDateFormat.java?rev=1384119&r1=1384118&r2=1384119&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/util/ConcurrentDateFormat.java
(original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/util/ConcurrentDateFormat.java
Wed Sep 12 20:51:55 2012
@@ -35,6 +35,19 @@ public class ConcurrentDateFormat {
     private final TimeZone timezone;
     private final Queue<SimpleDateFormat> queue = new ConcurrentLinkedQueue<>();
 
+    public static final String RFC1123_DATE = "EEE, dd MMM yyyy HH:mm:ss zzz";
+    public static final TimeZone GMT = TimeZone.getTimeZone("GMT");
+
+    private static final ConcurrentDateFormat FORMAT_RFC1123;
+
+    static {
+        FORMAT_RFC1123 = new ConcurrentDateFormat(RFC1123_DATE, Locale.US, GMT);
+    }
+
+    public static String formatRfc1123(Date date) {
+        return FORMAT_RFC1123.format(date);
+    }
+
     public ConcurrentDateFormat(String format, Locale locale,
             TimeZone timezone) {
         this.format = format;

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResource.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResource.java?rev=1384119&r1=1384118&r2=1384119&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResource.java
(original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResource.java
Wed Sep 12 20:51:55 2012
@@ -48,12 +48,6 @@ public class FileResource extends Resour
     }
 
     @Override
-    public String getLastModifiedHttp() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
     public boolean exists() {
         return resource.exists();
     }
@@ -102,12 +96,6 @@ public class FileResource extends Resour
     }
 
     @Override
-    public String getETag() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
     public InputStream getInputStream() {
         if (resource.exists()) {
             try {

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java?rev=1384119&r1=1384118&r2=1384119&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java
(original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java
Wed Sep 12 20:51:55 2012
@@ -49,12 +49,6 @@ public class JarResource extends Resourc
     }
 
     @Override
-    public String getLastModifiedHttp() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
     public boolean exists() {
         return true;
     }
@@ -101,13 +95,6 @@ public class JarResource extends Resourc
     }
 
     @Override
-    public String getETag() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-
-    @Override
     public InputStream getInputStream() {
         try {
             return base.getInputStream(resource);

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/ResourceBase.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/ResourceBase.java?rev=1384119&r1=1384118&r2=1384119&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/ResourceBase.java
(original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/ResourceBase.java
Wed Sep 12 20:51:55 2012
@@ -18,9 +18,11 @@ package org.apache.catalina.webresources
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Date;
 
 import org.apache.catalina.WebResource;
 import org.apache.catalina.WebResourceRoot;
+import org.apache.catalina.util.ConcurrentDateFormat;
 import org.apache.juli.logging.Log;
 import org.apache.tomcat.util.res.StringManager;
 
@@ -33,6 +35,7 @@ public abstract class ResourceBase imple
     private final String webAppPath;
 
     private String mimeType = null;
+    private volatile String weakETag;
 
 
     protected ResourceBase(WebResourceRoot root, String webAppPath) {
@@ -54,7 +57,32 @@ public abstract class ResourceBase imple
 
 
     @Override
+    public final String getLastModifiedHttp() {
+        return ConcurrentDateFormat.formatRfc1123(new Date(getLastModified()));
+    }
+
+    @Override
+    public final String getETag() {
+        if (weakETag == null) {
+            synchronized (this) {
+                if (weakETag == null) {
+                    long contentLength = getContentLength();
+                    long lastModified = getLastModified();
+                    if ((contentLength >= 0) || (lastModified >= 0)) {
+                        weakETag = "W/\"" + contentLength + "-" +
+                                   lastModified + "\"";
+                    }
+                }
+            }
+        }
+        return weakETag;
+    }
+
+    @Override
     public final void setMimeType(String mimeType) {
+        // TODO This is only called from the DefaultServlet. If resources are
+        //      not cached, there is no point in recording the mime type in the
+        //      WebResource
         this.mimeType = mimeType;
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message