/**
- * Get the ETag associated with a file.
- *
- * @param resourceAttributes The resource information
- */
- protected String getETag(ResourceAttributes resourceAttributes) {
- String result = null;
- if ((result = resourceAttributes.getETag(true)) != null) {
- return result;
- } else if ((result = resourceAttributes.getETag()) != null) {
- return result;
- } else {
- return "W/\"" + resourceAttributes.getContentLength() + "-"
- + resourceAttributes.getLastModified() + "\"";
- }
- }
-
-
- /**
* URL rewriter.
*
* @param path Path which has to be rewiten
ranges = parseRange(request, response, cacheEntry.attributes);
// ETag header
- response.setHeader("ETag", getETag(cacheEntry.attributes));
+ response.setHeader("ETag", cacheEntry.attributes.getETag());
// Last-Modified header
response.setHeader("Last-Modified",
// Ignore
}
- String eTag = getETag(resourceAttributes);
+ String eTag = resourceAttributes.getETag();
long lastModified = resourceAttributes.getLastModified();
if (headerValueTime == (-1L)) {
ResourceAttributes resourceAttributes)
throws IOException {
- String eTag = getETag(resourceAttributes);
+ String eTag = resourceAttributes.getETag();
String headerValue = request.getHeader("If-Match");
if (headerValue != null) {
if (headerValue.indexOf('*') == -1) {
// The entity has not been modified since the date
// specified by the client. This is not an error case.
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
- response.setHeader("ETag", getETag(resourceAttributes));
+ response.setHeader("ETag", resourceAttributes.getETag());
return false;
}
ResourceAttributes resourceAttributes)
throws IOException {
- String eTag = getETag(resourceAttributes);
+ String eTag = resourceAttributes.getETag();
String headerValue = request.getHeader("If-None-Match");
if (headerValue != null) {
if ( ("GET".equals(request.getMethod()))
|| ("HEAD".equals(request.getMethod())) ) {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
- response.setHeader("ETag", getETag(resourceAttributes));
+ response.setHeader("ETag", eTag);
return false;
} else {
contentType);
}
generatedXML.writeProperty(null, "getetag",
- getETag(cacheEntry.attributes));
+ cacheEntry.attributes.getETag());
generatedXML.writeElement(null, "resourcetype",
XMLWriter.NO_CONTENT);
} else {
propertiesNotFound.addElement(property);
} else {
generatedXML.writeProperty
- (null, "getetag", getETag(cacheEntry.attributes));
+ (null, "getetag", cacheEntry.attributes.getETag());
}
} else if (property.equals("getlastmodified")) {
if (cacheEntry.context != null) {
/**
+ * ETag.
+ */
+ public static final String ALTERNATE_ETAG = "etag";
+
+
+ /**
* Collection type.
*/
public static final String COLLECTION_TYPE = "<collection/>";
/**
* Get ETag.
*
- * @return Weak ETag
+ * @return strong ETag if available, else weak ETag.
*/
public String getETag() {
- return getETag(false);
- }
-
-
- /**
- * Get ETag.
- *
- * @param strong If true, the strong ETag will be returned
- * @return ETag
- */
- public String getETag(boolean strong) {
String result = null;
if (attributes != null) {
Attribute attribute = attributes.get(ETAG);
}
}
}
- if (strong) {
- // The strong ETag must always be calculated by the resources
- result = strongETag;
- } else {
- // The weakETag is contentLenght + lastModified
- if (weakETag == null) {
- weakETag = "W/\"" + getContentLength() + "-"
- + getLastModified() + "\"";
+ 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 + "\"";
+ }
+ }
+ result = weakETag;
}
- result = weakETag;
}
return result;
}
long contentLength = getContentLength();
if (contentLength < 0) return null;
return new BasicAttribute(ALTERNATE_CONTENT_LENGTH, new Long(contentLength));
+ } else if (attrID.equals(ETAG)) {
+ String etag = getETag();
+ if (etag == null) return null;
+ return new BasicAttribute(ETAG, etag);
+ } else if (attrID.equals(ALTERNATE_ETAG)) {
+ String etag = getETag();
+ if (etag == null) return null;
+ return new BasicAttribute(ALTERNATE_ETAG, etag);
}
} else {
return attributes.get(attrID);
attributes.addElement(new BasicAttribute(CONTENT_LENGTH, contentLengthLong));
attributes.addElement(new BasicAttribute(ALTERNATE_CONTENT_LENGTH, contentLengthLong));
}
+ String etag = getETag();
+ if (etag != null) {
+ attributes.addElement(new BasicAttribute(ETAG, etag));
+ attributes.addElement(new BasicAttribute(ALTERNATE_ETAG, etag));
+ }
return new RecyclableNamingEnumeration(attributes);
} else {
return attributes.getAll();
attributeIDs.addElement(CONTENT_LENGTH);
attributeIDs.addElement(ALTERNATE_CONTENT_LENGTH);
}
+ String etag = getETag();
+ if (etag != null) {
+ attributeIDs.addElement(ETAG);
+ attributeIDs.addElement(ALTERNATE_ETAG);
+ }
return new RecyclableNamingEnumeration(attributeIDs);
} else {
return attributes.getIDs();
if (getName() != null) size++;
if (getResourceType() != null) size += 2;
if (getContentLength() >= 0) size += 2;
+ if (getETag() != null) size += 2;
return size;
} else {
return attributes.size();