Node node = (Node)session.getItem(path);
WebDavNamespaceContext nsContext = new WebDavNamespaceContext(session);
URI uri = new URI(TextUtil.escape(baseURI + node.getPath(), '%', true));
Resource resource;
InputStream istream;
if (ResourceUtil.isFile(node))
{
HierarchicalProperty lastModifiedProperty;
if (version != null)
{
VersionedResource versionedFile = new VersionedFileResource(uri, node, nsContext);
resource = versionedFile.getVersionHistory().getVersion(version);
lastModifiedProperty = resource.getProperty(FileResource.GETLASTMODIFIED);
istream = ((VersionResource)resource).getContentAsStream();
}
else
{
resource = new FileResource(uri, node, nsContext);
lastModifiedProperty = resource.getProperty(FileResource.GETLASTMODIFIED);
istream = ((FileResource)resource).getContentAsStream();
}
// check before any other reads
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)
{
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)
{