Moved to Java 8. Code cleanup.
[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.AbstractFile;
6 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.DirectoryFile;
7 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.GeneralFile;
8 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Picture;
9
10 import java.io.File;
11 import java.io.UnsupportedEncodingException;
12
13 public abstract class AbstractIndexer {
14
15     public static boolean isImage(final String fileExtension) {
16         for (final String ext : Constants.SUPPORTED_IMAGE_EXTENSIONS)
17             if (ext.equals(fileExtension))
18                 return true;
19         return false;
20     }
21
22     public static boolean isOgv(final String fileExtension) {
23         return fileExtension.equalsIgnoreCase("ogv");
24     }
25
26     static boolean shallFileBeIndexed(final File file) {
27
28         if (file.getName().startsWith("."))
29             return false;
30         if (file.getName().startsWith("index"))
31             if (file.getName().endsWith(".html"))
32                 return false;
33
34         return true;
35     }
36
37     void compileHtml(final Layout layout,
38                      final DirectoryMetadata directory)
39             throws UnsupportedEncodingException {
40
41         for (final AbstractFile file : directory.getFiles())
42             if (file instanceof GeneralFile) {
43                 final String fileExtension = file.getFileExtension();
44
45                 if ("ogv".equals(fileExtension))
46                     layout.enlistOgv(file, directory);
47                 else if ("webm".equals(fileExtension))
48                     layout.enlistWebm(file, directory);
49                 else
50                     layout.enlistFile(file, directory);
51
52             } else if (file instanceof Picture)
53                 layout.enlistImage((Picture) file, directory);
54             else if (file instanceof DirectoryFile)
55                 layout.enlistDirectory(file, directory);
56
57     }
58
59     public abstract String getDirectoryUrl(final AbstractFile directory,
60                                            IndexingContext context);
61
62     public abstract String getParentDirectoryUrl(IndexingContext context);
63
64     public abstract String getThumbnailUrl(Picture picture,
65                                            final Dimension desiredDimension, IndexingContext context);
66
67 }