From ddbd9cbd9c6835c7f130445337fa3b507264eb77 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sat, 15 Sep 2018 00:35:55 +0300 Subject: [PATCH] Simplified and unified video display code. --- .gitignore | 1 + meviz.iml | 16 ---- .../meviz/htmlindexer/AbstractIndexer.java | 22 ++++- .../svjatoslav/meviz/htmlindexer/Layout.java | 10 +- .../htmlindexer/layouts/MixedLayout.java | 96 ++++++------------- 5 files changed, 49 insertions(+), 96 deletions(-) delete mode 100644 meviz.iml diff --git a/.gitignore b/.gitignore index 260935a..4de04cd 100755 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /.project /target/ /.idea/ +/meviz.iml diff --git a/meviz.iml b/meviz.iml deleted file mode 100644 index 7399dd5..0000000 --- a/meviz.iml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/AbstractIndexer.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/AbstractIndexer.java index 5036721..4e3b6eb 100644 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/AbstractIndexer.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/AbstractIndexer.java @@ -42,10 +42,8 @@ public abstract class AbstractIndexer { if (file instanceof GeneralFile) { final String fileExtension = file.getFileExtension(); - if ("ogv".equals(fileExtension)) - layout.enlistOgv(file, directory); - else if ("webm".equals(fileExtension)) - layout.enlistWebm(file, directory); + if (isVideo(fileExtension)) + layout.enlistVideo(file); else layout.enlistFile(file, directory); @@ -64,4 +62,20 @@ public abstract class AbstractIndexer { public abstract String getThumbnailUrl(Picture picture, final Dimension desiredDimension, IndexingContext context); + public static String getVideoType(String fileExtension) { + switch (fileExtension){ + case "ogv": + return "video/ogg"; + case "webm": + return "video/webm"; + case "mp4": + return "video/mp4"; + default: + return null; + } + } + + public boolean isVideo(String fileExtension){ + return getVideoType(fileExtension) != null; + } } diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/Layout.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/Layout.java index 25bfd4f..c1e6d23 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/Layout.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/Layout.java @@ -14,7 +14,6 @@ import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.AbstractFile; import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Picture; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.util.List; /** @@ -45,13 +44,9 @@ public interface Layout { DirectoryMetadata parentDirectoryMetadata); /** - * Enlist video in OGV format. - * - * @throws UnsupportedEncodingException + * Enlist video file. */ - void enlistOgv(AbstractFile file, - DirectoryMetadata parentDirectoryMetadata) - ; + void enlistVideo(AbstractFile file); /** * Return layout specific suffix that will be appended between @@ -76,5 +71,4 @@ public interface Layout { void init(String galleryTitle, List path, final AbstractIndexer indexer, IndexingContext context); - void enlistWebm(AbstractFile file, DirectoryMetadata directory); } diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java index acc3c4e..7963582 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java @@ -10,17 +10,23 @@ package eu.svjatoslav.meviz.htmlindexer.layouts; import eu.svjatoslav.commons.file.FilePathParser; -import eu.svjatoslav.meviz.htmlindexer.*; +import eu.svjatoslav.meviz.htmlindexer.AbstractIndexer; +import eu.svjatoslav.meviz.htmlindexer.Constants; +import eu.svjatoslav.meviz.htmlindexer.IndexingContext; +import eu.svjatoslav.meviz.htmlindexer.Layout; import eu.svjatoslav.meviz.htmlindexer.metadata.Dimension; import eu.svjatoslav.meviz.htmlindexer.metadata.DirectoryMetadata; import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.AbstractFile; -import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.GeneralFile; import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Picture; import org.apache.log4j.Logger; import java.io.IOException; import java.util.List; +import static eu.svjatoslav.commons.file.FilePathParser.getFileNameWithoutExtension; +import static eu.svjatoslav.meviz.htmlindexer.AbstractIndexer.getVideoType; +import static eu.svjatoslav.meviz.htmlindexer.Utils.urlEncode; + public class MixedLayout implements Layout { public static final String encoding = "UTF-8"; @@ -58,7 +64,7 @@ public class MixedLayout implements Layout { filesHtml.append("
" + fullFileName + "\n"); filesHtml.append("  (" + FilePathParser.getFileSizeDescription(file.getFileLength()) @@ -109,7 +115,7 @@ public class MixedLayout implements Layout { // clickable image thumbnail filesHtml.append("\n"); filesHtml.append("" - + FilePathParser.getFileNameWithoutExtension(picture.fileName) + + getFileNameWithoutExtension(picture.fileName) + "
"); // links to thumbnails of various sizes @@ -126,48 +132,6 @@ public class MixedLayout implements Layout { filesHtml.append("
"); } - /** - * {@inheritDoc} - */ - @Override - public void enlistOgv(final AbstractFile abstractFile, - final DirectoryMetadata parentDirectoryMetadata) { - - final GeneralFile file = (GeneralFile) abstractFile; - - filesHtml.append("
"); - - // watchable video - filesHtml - .append("\n"); - filesHtml.append("
\n"); - - // video title - filesHtml - .append("Video: " - + FilePathParser - .getFileNameWithoutExtension(file.fileName) - + "            "); - - // video download link - filesHtml.append("
download as OGV file"); - - filesHtml.append("
\n"); - - filesHtml.append("\n"); - - } - /** * {@inheritDoc} */ @@ -278,39 +242,35 @@ public class MixedLayout implements Layout { } @Override - public void enlistWebm(AbstractFile abstractFile, - DirectoryMetadata directory) { - final GeneralFile file = (GeneralFile) abstractFile; + public void enlistVideo(AbstractFile file) { - filesHtml.append("
"); + filesHtml.append("
\n"); // watchable video + filesHtml.append(" \n"); - String fileUrl = indexingContext.getGlobalUrl() - + Utils.urlEncode(indexingContext.getLocalUrl() + "/" - + file.fileName); - - filesHtml.append("\n"); - filesHtml.append("
\n"); + filesHtml.append("
\n"); // video title - filesHtml - .append("Video: " - + FilePathParser - .getFileNameWithoutExtension(file.fileName) + filesHtml.append(" Video: " + + getFileNameWithoutExtension(file.fileName) + "            "); // video download link - filesHtml.append("download as WebM file"); + filesHtml.append(" download\n"); filesHtml.append("
\n"); filesHtml.append("\n"); } + + + private String getFileUrl(AbstractFile file) { + return indexingContext.getGlobalUrl() + + urlEncode(indexingContext.getLocalUrl() + "/" + + file.fileName); + } } -- 2.20.1