294189bb21e01a9880c666f2f3e47c0ec07caef2
[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 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         public 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         public 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 }