Use Apache Tika to handle videos.
[meviz.git] / src / main / java / eu / svjatoslav / meviz / htmlindexer / AbstractIndexer.java
1 package eu.svjatoslav.meviz.htmlindexer;
2
3 import eu.svjatoslav.meviz.htmlindexer.metadata.Dimension;
4 import eu.svjatoslav.meviz.htmlindexer.metadata.DirectoryMetadata;
5 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.*;
6
7 import java.io.File;
8 import java.io.UnsupportedEncodingException;
9
10 import static eu.svjatoslav.meviz.htmlindexer.Constants.SUPPORTED_IMAGE_EXTENSIONS;
11 import static eu.svjatoslav.meviz.htmlindexer.Constants.SUPPORTED_VIDEO_EXTENSIONS;
12
13 public abstract class AbstractIndexer {
14
15     public static boolean isImage(final String fileExtension) {
16         for (final String ext : SUPPORTED_IMAGE_EXTENSIONS)
17             if (ext.equals(fileExtension))
18                 return true;
19         return false;
20     }
21
22     public static boolean isVideo(final String fileExtension) {
23         for (final String ext : SUPPORTED_VIDEO_EXTENSIONS)
24             if (ext.equals(fileExtension))
25                 return true;
26         return false;
27     }
28
29     static boolean shallFileBeIndexed(final File file) {
30
31         if (file.getName().startsWith("."))
32             return false;
33         if (file.getName().startsWith("index"))
34             if (file.getName().endsWith(".html"))
35                 return false;
36
37         return true;
38     }
39
40     void compileHtml(final Layout layout,
41                      final DirectoryMetadata directory)
42             throws UnsupportedEncodingException {
43
44         for (final AbstractFile file : directory.getFiles())
45             if (file instanceof GeneralFile) {
46                 layout.enlistFile(file, directory);
47             } else if (file instanceof Picture){
48                 layout.enlistImage((Picture) file, directory);
49             } else if (file instanceof Video){
50                 layout.enlistVideo((Video) file);
51             } else if (file instanceof DirectoryFile)
52                 layout.enlistDirectory(file, directory);
53     }
54
55     public abstract String getDirectoryUrl(final AbstractFile directory,
56                                            IndexingContext context);
57
58     public abstract String getParentDirectoryUrl(IndexingContext context);
59
60     public abstract String getThumbnailUrl(Picture picture,
61                                            final Dimension desiredDimension, IndexingContext context);
62
63 }