Simplified and unified video display code.
[meviz.git] / src / main / java / eu / svjatoslav / meviz / htmlindexer / AbstractIndexer.java
index 2394ece..4e3b6eb 100644 (file)
@@ -23,7 +23,7 @@ public abstract class AbstractIndexer {
         return fileExtension.equalsIgnoreCase("ogv");
     }
 
-    public static boolean shallFileBeIndexed(final File file) {
+    static boolean shallFileBeIndexed(final File file) {
 
         if (file.getName().startsWith("."))
             return false;
@@ -34,18 +34,16 @@ public abstract class AbstractIndexer {
         return true;
     }
 
-    public void compileHtml(final Layout layout,
-                            final DirectoryMetadata directory)
+    void compileHtml(final Layout layout,
+                     final DirectoryMetadata directory)
             throws UnsupportedEncodingException {
 
         for (final AbstractFile file : directory.getFiles())
             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;
+    }
 }