From 4e5e467eaf6e4edda1dd5707e5402065c7509c79 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sun, 5 Jan 2020 17:56:44 +0200 Subject: [PATCH] Code refactoring. Generate image thumbnails with same extension as original image. --- .../indexer/FilesystemIndexer.java | 20 +++++++++---------- .../metadata/fileTypes/Picture.java | 11 +++++----- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/indexer/FilesystemIndexer.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/indexer/FilesystemIndexer.java index 6add6be..a26f157 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/indexer/FilesystemIndexer.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/indexer/FilesystemIndexer.java @@ -25,6 +25,11 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import static eu.svjatoslav.meviz.htmlindexer.Constants.THUMBNAILS_DIRECTORY_NAME; +import static eu.svjatoslav.meviz.htmlindexer.Utils.getThumbnailsDirectoryPath; +import static eu.svjatoslav.meviz.htmlindexer.Utils.urlEncode; +import static eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Picture.makeThumbnail; + /** * Main class of HTML indexer. */ @@ -83,7 +88,6 @@ public class FilesystemIndexer extends AbstractIndexer { } private void generateHtmlFromMetadata(final HashSet layouts) { - // Generate HTML from metadata for (final Layout layout : layouts) try { final File indexFile = Utils.getLayoutIndexFile(layout, @@ -113,7 +117,7 @@ public class FilesystemIndexer extends AbstractIndexer { @Override public String getDirectoryUrl(final AbstractFile directory, final IndexingContext context) { - return Utils.urlEncode(directory.fileName) + "/index.html"; + return urlEncode(directory.fileName) + "/index.html"; } @Override @@ -135,20 +139,16 @@ public class FilesystemIndexer extends AbstractIndexer { validMetadataFiles.add(thumbnailFileName); final File thumbnailFile = new File( - Utils.getThumbnailsDirectoryPath(directoryToIndex) - + thumbnailFileName); + getThumbnailsDirectoryPath(directoryToIndex) + thumbnailFileName); if (!thumbnailFile.exists()) { final File originalFile = new File( directoryToIndex.getAbsolutePath() + "/" + picture.fileName); - // generate new thumbnail - Picture.makeThumbnail(originalFile, thumbnailFile, - desiredDimension.getAwtDimension()); + makeThumbnail(originalFile, thumbnailFile, desiredDimension.getAwtDimension()); } - return Constants.THUMBNAILS_DIRECTORY_NAME + "/" - + Utils.urlEncode(thumbnailFileName); + return THUMBNAILS_DIRECTORY_NAME + "/" + urlEncode(thumbnailFileName); } private void initializeLayouts() { @@ -173,7 +173,7 @@ public class FilesystemIndexer extends AbstractIndexer { private void loadOrCreateMetadata() { metadataFile = new File( - Utils.getThumbnailsDirectoryPath(directoryToIndex) + getThumbnailsDirectoryPath(directoryToIndex) + Constants.METADATA_FILE_NAME); metadata = MetadadaHelper.initDirectoryMetadata(metadataFile); diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/Picture.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/Picture.java index ae22071..9f35743 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/Picture.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/Picture.java @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.List; import static eu.svjatoslav.meviz.htmlindexer.Utils.getBufferedImage; +import static java.awt.image.BufferedImage.TYPE_INT_RGB; public class Picture extends AbstractFile { @@ -122,7 +123,7 @@ public class Picture extends AbstractFile { final BufferedImage bufferedImage = new BufferedImage( scaledImage.getWidth(null), scaledImage.getHeight(null), - BufferedImage.TYPE_INT_RGB); + TYPE_INT_RGB); final Graphics2D g = bufferedImage.createGraphics(); g.drawImage(scaledImage, 0, 0, null); @@ -158,9 +159,9 @@ public class Picture extends AbstractFile { // compute new thumbnails hash number final String forMagicHash = fileName + " " - + String.valueOf(targetDimension.width) + " " - + String.valueOf(targetDimension.height) + " " - + String.valueOf(getFileLength()) + " " + + targetDimension.width + " " + + targetDimension.height + " " + + getFileLength() + " " + Constants.THUMBNAIL_VERSION; // System.out.println("Computing hash from: " + forMagicHash); @@ -177,7 +178,7 @@ public class Picture extends AbstractFile { */ public String getRelativeThumbnailFileName(final Dimension targetDimension) { return FilePathParser.getFileNameWithoutExtension(fileName) + " (" - + computeThumbnailHash(targetDimension) + ").jpeg"; + + computeThumbnailHash(targetDimension) + ")." + getFileExtension(); } @Override -- 2.20.1