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