Code refactoring
[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
15 public abstract class AbstractIndexer {
16
17     public static boolean isImage(final String fileExtension) {
18         for (final String ext : SUPPORTED_IMAGE_EXTENSIONS)
19             if (ext.equals(fileExtension))
20                 return true;
21         return false;
22     }
23
24     public static boolean isVideo(final String fileExtension) {
25         for (final String ext : SUPPORTED_VIDEO_EXTENSIONS)
26             if (ext.equals(fileExtension))
27                 return true;
28         return false;
29     }
30
31     static boolean shallFileBeIndexed(final File file) {
32
33         if (file.getName().startsWith("."))
34             return false;
35         if (file.getName().startsWith("index"))
36             if (file.getName().endsWith(".html"))
37                 return false;
38
39         return true;
40     }
41
42     void compileHtml(final Layout layout,
43                      final DirectoryMetadata directory)
44             throws UnsupportedEncodingException {
45
46         for (final AbstractFile file : directory.getFiles())
47             if (file instanceof GeneralFile) {
48                 layout.enlistFile(file, directory);
49             } else if (file instanceof Picture){
50                 layout.enlistImage((Picture) file, directory);
51             } else if (file instanceof Video){
52                 layout.enlistVideo((Video) file);
53             } else if (file instanceof DirectoryFile)
54                 layout.enlistDirectory(file, directory);
55     }
56
57     public abstract String getDirectoryUrl(final AbstractFile directory,
58                                            IndexingContext context);
59
60     public abstract String getParentDirectoryUrl(IndexingContext context);
61
62     public abstract String getThumbnailUrl(Picture picture,
63                                            final Dimension desiredDimension, IndexingContext context);
64
65 }