added content disposition header to getContent method for raw download

This commit is contained in:
Sebastian Sdorra
2011-09-16 14:59:08 +02:00
parent 7aa955e212
commit 004a6ab74d

View File

@@ -161,8 +161,8 @@ public class RepositoryResource
{ {
AssertUtil.assertIsNotNull(path); AssertUtil.assertIsNotNull(path);
BlameResult blamePagingResult = blameViewerUtil.getBlame(id, BlameResult blamePagingResult = blameViewerUtil.getBlame(id, revision,
revision, path); path);
if (blamePagingResult != null) if (blamePagingResult != null)
{ {
@@ -298,10 +298,11 @@ public class RepositoryResource
@GET @GET
@Path("{id}/content") @Path("{id}/content")
@Produces({ MediaType.APPLICATION_OCTET_STREAM }) @Produces({ MediaType.APPLICATION_OCTET_STREAM })
public StreamingOutput getContent(@PathParam("id") String id, public Response getContent(@PathParam("id") String id,
@QueryParam("revision") String revision, @QueryParam("revision") String revision,
@QueryParam("path") String path) @QueryParam("path") String path)
{ {
Response response = null;
StreamingOutput output = null; StreamingOutput output = null;
Repository repository = repositoryManager.get(id); Repository repository = repositoryManager.get(id);
@@ -315,20 +316,28 @@ public class RepositoryResource
if (browser != null) if (browser != null)
{ {
output = new BrowserStreamingOutput(browser, revision, path); output = new BrowserStreamingOutput(browser, revision, path);
String contentDispositionName = getContentDispositionName(path);
response = Response.ok(output).header("Content-Disposition",
contentDispositionName).build();
} }
else if (logger.isWarnEnabled()) else if (logger.isWarnEnabled())
{ {
logger.warn("could not find repository browser for respository {}", logger.warn("could not find repository browser for respository {}",
repository.getId()); repository.getId());
response = Response.status(Response.Status.NOT_FOUND).build();
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.error("could not retrive content", ex); logger.error("could not retrive content", ex);
response =
Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} }
} }
return output; return response;
} }
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
@@ -461,6 +470,27 @@ public class RepositoryResource
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param path
*
* @return
*/
private String getContentDispositionName(String path)
{
String name = path;
int index = path.lastIndexOf("/");
if (index >= 0)
{
name = path.substring(0, index);
}
return "attachment; filename=\"".concat(name).concat("\"");
}
/** /**
* Method description * Method description
* *