Node node = (Node)session.getItem(path);
WebDavNamespaceContext nsContext = new WebDavNamespaceContext(session);
URI uri = new URI(TextUtil.escape(baseURI + node.getPath(), '%', true));
Resource resource;
if (ResourceUtil.isFile(node))
{
HierarchicalProperty lastModifiedProperty;
String resourceEntityTag;
if (version != null)
{
VersionedResource versionedFile = new VersionedFileResource(uri, node, nsContext);
resource = versionedFile.getVersionHistory().getVersion(version);
lastModifiedProperty = resource.getProperty(FileResource.GETLASTMODIFIED);
}
else
{
resource = new FileResource(uri, node, nsContext);
lastModifiedProperty = resource.getProperty(FileResource.GETLASTMODIFIED);
}
resourceEntityTag = ResourceUtil.generateEntityTag(node, lastModifiedProperty.getValue());
// check before any other reads
if (ifNoneMatch != null)
{
if ("*".equals(ifNoneMatch))
{
return Response.notModified().entity("Not Modified").build();
}
for (String eTag : ifNoneMatch.split(","))
{
if (resourceEntityTag.equals(eTag))
{
return Response.notModified().entity("Not Modified").build();
}
}
}
else if (ifModifiedSince != null)
{
DateFormat dateFormat = new SimpleDateFormat(WebDavConst.DateFormat.MODIFICATION, Locale.US);
Date lastModifiedDate = dateFormat.parse(lastModifiedProperty.getValue());
dateFormat = new SimpleDateFormat(WebDavConst.DateFormat.IF_MODIFIED_SINCE_PATTERN, Locale.US);
Date ifModifiedSinceDate = dateFormat.parse(ifModifiedSince);
if (ifModifiedSinceDate.getTime() >= lastModifiedDate.getTime())
{
return Response.notModified().entity("Not Modified").build();
}
}
HierarchicalProperty contentLengthProperty = resource.getProperty(FileResource.GETCONTENTLENGTH);
long contentLength = new Long(contentLengthProperty.getValue());
// content length is not present
if (contentLength == 0)
{
istream = openStream(resource, version != null);
return Response.ok().header(ExtHttpHeaders.ACCEPT_RANGES, "bytes").entity(istream).build();
}
HierarchicalProperty mimeTypeProperty = resource.getProperty(FileResource.GETCONTENTTYPE);
String contentType = mimeTypeProperty.getValue();
// no ranges request
if (ranges.size() == 0)
{