initial commit
[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((GeneralFile) 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 getThumbnailPath(Picture picture,
36                         final Dimension desiredDimension);
37
38         public static boolean isImage(final String fileExtension) {
39                 for (final String ext : Constants.SUPPORTED_IMAGE_EXTENSIONS)
40                         if (ext.equals(fileExtension))
41                                 return true;
42                 return false;
43         }
44
45         public static boolean isOgv(final String fileExtension) {
46                 return fileExtension.equalsIgnoreCase("ogv");
47         }
48
49         public static boolean shallFileBeIndexed(final File file) {
50
51                 if (file.getName().startsWith("."))
52                         return false;
53                 if (file.getName().startsWith("index"))
54                         if (file.getName().endsWith(".html"))
55                                 return false;
56
57                 return true;
58         }
59
60 }