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