1 package eu.svjatoslav.meviz.htmlindexer.indexer;
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.*;
10 import java.io.UnsupportedEncodingException;
12 import static eu.svjatoslav.meviz.htmlindexer.Constants.SUPPORTED_IMAGE_EXTENSIONS;
13 import static eu.svjatoslav.meviz.htmlindexer.Constants.SUPPORTED_VIDEO_EXTENSIONS;
14 import static java.util.Arrays.stream;
16 public abstract class AbstractIndexer {
18 public static boolean isImage(final String fileExtension) {
19 return stream(SUPPORTED_IMAGE_EXTENSIONS)
20 .anyMatch(ext -> ext.equals(fileExtension));
23 public static boolean isVideo(final String fileExtension) {
24 for (final String ext : SUPPORTED_VIDEO_EXTENSIONS)
25 if (ext.equals(fileExtension))
30 static boolean shallFileBeIndexed(final File file) {
32 if (file.getName().startsWith("."))
34 if (file.getName().startsWith("index"))
35 if (file.getName().endsWith(".html"))
41 void compileHtml(final Layout layout,
42 final DirectoryMetadata directory)
43 throws UnsupportedEncodingException {
45 for (final AbstractFile file : directory.getFiles())
46 if (file instanceof GeneralFile) {
47 layout.enlistFile(file, directory);
48 } else if (file instanceof Picture){
49 layout.enlistImage((Picture) file, directory);
50 } else if (file instanceof Video){
51 layout.enlistVideo((Video) file);
52 } else if (file instanceof DirectoryFile)
53 layout.enlistDirectory(file, directory);
56 public abstract String getDirectoryUrl(final AbstractFile directory,
57 IndexingContext context);
59 public abstract String getParentDirectoryUrl(IndexingContext context);
61 public abstract String getThumbnailUrl(Picture picture,
62 final Dimension desiredDimension, IndexingContext context);