From e8efa6faec8dc89d2b57bdc807f2f56ce3afe3b1 Mon Sep 17 00:00:00 2001 From: markt Date: Fri, 24 Oct 2008 21:23:08 +0000 Subject: [PATCH] Apply Remy's patch for 45735 and align trunk with 6.0.x. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@707751 13f79535-47bb-0310-9956-ffa450edef68 --- .../naming/resources/ResourceAttributes.java | 57 ++++++++++++---------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/java/org/apache/naming/resources/ResourceAttributes.java b/java/org/apache/naming/resources/ResourceAttributes.java index 7e116de44..858dbf685 100644 --- a/java/org/apache/naming/resources/ResourceAttributes.java +++ b/java/org/apache/naming/resources/ResourceAttributes.java @@ -710,38 +710,43 @@ public class ResourceAttributes implements Attributes { /** * Get ETag. * - * @return strong ETag if available, else weak ETag. + * @return Weak ETag */ public String getETag() { - String result = null; - if (attributes != null) { - Attribute attribute = attributes.get(ETAG); - if (attribute != null) { - try { - result = attribute.get().toString(); - } catch (NamingException e) { - ; // No value for the attribute - } - } - } - if (result == null) { - if (strongETag != null) { - // The strong ETag must always be calculated by the resources - result = strongETag; - } else { - // The weakETag is contentLength + lastModified - if (weakETag == null) { - long contentLength = getContentLength(); - long lastModified = getLastModified(); - if ((contentLength >= 0) || (lastModified >= 0)) { - weakETag = "W/\"" + contentLength + "-" - + lastModified + "\""; + return getETag(false); + } + + + /** + * Get ETag. + * + * @param strong If true, the strong ETag will be returned + * @return ETag + */ + public String getETag(boolean strong) { + if (strong) { + // The strong ETag must always be calculated by the resources + if (strongETag != null) + return strongETag; + if (attributes != null) { + Attribute attribute = attributes.get(ETAG); + if (attribute != null) { + try { + strongETag = attribute.get().toString(); + } catch (NamingException e) { + ; // No value for the attribute } } - result = weakETag; } + return strongETag; + } else { + // The weakETag is contentLenght + lastModified + if (weakETag == null) { + weakETag = "W/\"" + getContentLength() + "-" + + getLastModified() + "\""; + } + return weakETag; } - return result; } -- 2.11.0