fixed compilation errors
[meviz.git] / src / main / java / eu / svjatoslav / meviz / htmlindexer / FilesystemIndexRemover.java
1 package eu.svjatoslav.meviz.htmlindexer;
2
3 import eu.svjatoslav.commons.file.IOHelper;
4
5 import java.io.File;
6 import java.io.IOException;
7
8 public class FilesystemIndexRemover {
9
10     private final CommandlineHandler commandlineHandler;
11
12     public FilesystemIndexRemover(final CommandlineHandler commandlineHandler)
13             throws IOException {
14         this.commandlineHandler = commandlineHandler;
15
16         removeIndex(commandlineHandler.getWorkingDirectory());
17     }
18
19     public void removeIndex(final File workingDirectory) throws IOException {
20
21         // remove thumbnails directory from current directory
22         final File thumbnailsDirectory = Utils
23                 .getThumbnailsDirectory(workingDirectory);
24         if (thumbnailsDirectory.exists()) {
25             System.out.println("Deleting thumbnails directory: "
26                     + thumbnailsDirectory);
27             IOHelper.deleteRecursively(thumbnailsDirectory);
28         }
29
30         // recursively remove thumbnail directories from sub directories
31         for (final File subFile : workingDirectory.listFiles())
32             if (subFile.isDirectory())
33                 removeIndex(subFile);
34
35         for (final Layout layout : Utils.getLayouts()) {
36             final File indexFile = Utils.getLayoutIndexFile(layout,
37                     workingDirectory);
38
39             if (indexFile.exists())
40                 if (Utils.isMevizGeneratedIndexFile(indexFile)) {
41                     System.out.println("Deleting generated index file: "
42                             + indexFile);
43                     indexFile.delete();
44                 }
45         }
46
47     }
48
49 }