From 14f8a3f999ca9d3cd20a0972fcc10cf751412d54 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Fri, 4 Jan 2013 20:26:30 +0100 Subject: [PATCH] improve screenshot resource --- .../scm/plugin/rest/ScreenshotResource.java | 49 +++++++++++++------ 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/scm-plugin-backend/src/main/java/sonia/scm/plugin/rest/ScreenshotResource.java b/scm-plugin-backend/src/main/java/sonia/scm/plugin/rest/ScreenshotResource.java index 224df1df8b..a4ecaf3bfc 100644 --- a/scm-plugin-backend/src/main/java/sonia/scm/plugin/rest/ScreenshotResource.java +++ b/scm-plugin-backend/src/main/java/sonia/scm/plugin/rest/ScreenshotResource.java @@ -124,11 +124,12 @@ public class ScreenshotResource */ @GET @Produces("image/jpeg") - public Response getScreenshot(@PathParam("groupId") String groupId, - @PathParam("artifactId") String artifactId, - @PathParam("number") int number, - @PathParam("size") String size) - throws IOException + public Response getScreenshot( + @PathParam("groupId") String groupId, + @PathParam("artifactId") String artifactId, + @PathParam("number") int number, + @PathParam("size") String size) + throws IOException { PluginInformation plugin = PluginUtil.getLatestPluginVersion(backend, groupId, artifactId); @@ -153,15 +154,9 @@ public class ScreenshotResource } String checksum = ChecksumUtil.createChecksum(screenshot); - StringBuilder path = new StringBuilder(PATH_IMAGE); - path.append(File.separator).append(groupId); - path.append(File.separator).append(artifactId).append(File.separator); - path.append(String.valueOf(number)).append(File.separator); - path.append(size).append(File.separator).append(checksum); - path.append(EXTENSION_IMAGE); - - File file = new File(backend.getBaseDirectory(), path.toString()); + File file = createThumbnailFile(groupId, artifactId, number, size, + checksum); if (!file.exists()) { @@ -184,7 +179,7 @@ public class ScreenshotResource * @throws IOException */ private void createThumbnail(File file, String screenshot, char size) - throws IOException + throws IOException { IOUtil.mkdirs(file.getParentFile()); @@ -207,6 +202,32 @@ public class ScreenshotResource ImageIO.write(image, FORMAT, file); } + /** + * Method description + * + * + * @param groupId + * @param artifactId + * @param number + * @param size + * @param checksum + * + * @return + */ + private File createThumbnailFile(String groupId, String artifactId, + int number, String size, String checksum) + { + StringBuilder path = new StringBuilder(PATH_IMAGE); + + path.append(File.separator).append(groupId); + path.append(File.separator).append(artifactId).append(File.separator); + path.append(String.valueOf(number)).append(File.separator); + path.append(size).append(File.separator).append(checksum); + path.append(EXTENSION_IMAGE); + + return new File(backend.getBaseDirectory(), path.toString()); + } + //~--- fields --------------------------------------------------------------- /** Field description */