preparations to add HTML snippets into generated HTML
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Fri, 2 Jan 2015 22:14:25 +0000 (00:14 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Fri, 2 Jan 2015 22:14:25 +0000 (00:14 +0200)
src/main/java/eu/svjatoslav/meviz/htmlindexer/AbstractIndexer.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/FilesystemIndexer.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/Layout.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/DirectoryMetadata.java

index 84a5868..fff1b68 100644 (file)
@@ -36,21 +36,21 @@ public abstract class AbstractIndexer {
 
        public void compileHtml(final Layout layout,
                        final DirectoryMetadata directory)
-                                       throws UnsupportedEncodingException {
+                       throws UnsupportedEncodingException {
 
                for (final AbstractFile file : directory.getFiles())
                        if (file instanceof GeneralFile) {
                                final String fileExtension = file.getFileExtension();
 
                                if ("ogv".equals(fileExtension))
-                                       layout.enlistOgv(file);
+                                       layout.enlistOgv(file, directory);
                                else
-                                       layout.enlistFile(file);
+                                       layout.enlistFile(file, directory);
 
                        } else if (file instanceof Picture)
-                               layout.enlistImage((Picture) file);
+                               layout.enlistImage((Picture) file, directory);
                        else if (file instanceof DirectoryFile)
-                               layout.enlistDirectory(file);
+                               layout.enlistDirectory(file, directory);
 
        }
 
index 61b9027..6c672b1 100755 (executable)
@@ -12,7 +12,6 @@ package eu.svjatoslav.meviz.htmlindexer;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -25,8 +24,6 @@ import eu.svjatoslav.meviz.htmlindexer.metadata.Dimension;
 import eu.svjatoslav.meviz.htmlindexer.metadata.DirectoryMetadata;
 import eu.svjatoslav.meviz.htmlindexer.metadata.MetadadaHelper;
 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.AbstractFile;
-import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.DirectoryFile;
-import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.GeneralFile;
 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Picture;
 
 /**
@@ -102,7 +99,7 @@ public class FilesystemIndexer extends AbstractIndexer {
 
                                if (canWriteIndexFile(indexFile)) {
 
-                                       indexForLayout(layout);
+                                       compileHtml(layout, metadata);
 
                                        IOHelper.overwriteFileIfContentDiffers(indexFile, layout
                                                        .getHtml(true, true).getBytes());
@@ -147,7 +144,7 @@ public class FilesystemIndexer extends AbstractIndexer {
                validMetadataFiles.add(thumbnailFileName);
                final File thumbnailFile = new File(
                                Utils.getThumbnailsDirectoryPath(directoryToIndex)
-                               + thumbnailFileName);
+                                               + thumbnailFileName);
 
                if (!thumbnailFile.exists()) {
 
@@ -159,25 +156,7 @@ public class FilesystemIndexer extends AbstractIndexer {
                                        desiredDimension.getAwtDimension());
                }
                return Constants.THUMBNAILS_DIRECTORY_NAME + "/"
-               + UrlParamEncoder.encode(thumbnailFileName);
-       }
-
-       public void indexForLayout(final Layout layout)
-                       throws UnsupportedEncodingException {
-
-               for (final AbstractFile abstractFile : metadata.getFiles())
-                       if (abstractFile instanceof GeneralFile) {
-
-                               if (isOgv(abstractFile.getFileExtension()))
-                                       layout.enlistOgv(abstractFile);
-                               else
-                                       layout.enlistFile(abstractFile);
-
-                       } else if (abstractFile instanceof Picture)
-                               layout.enlistImage((Picture) abstractFile);
-                       else if (abstractFile instanceof DirectoryFile)
-                               layout.enlistDirectory(abstractFile);
-
+                               + UrlParamEncoder.encode(thumbnailFileName);
        }
 
        public void initializeLayouts() {
@@ -203,7 +182,7 @@ public class FilesystemIndexer extends AbstractIndexer {
 
                metadataFile = new File(
                                Utils.getThumbnailsDirectoryPath(directoryToIndex)
-                               + Constants.METADATA_FILE_NAME);
+                                               + Constants.METADATA_FILE_NAME);
 
                metadata = MetadadaHelper.initDirectoryMetadata(metadataFile);
        }
index 8df469e..e29cb11 100755 (executable)
@@ -12,6 +12,7 @@ package eu.svjatoslav.meviz.htmlindexer;
 import java.io.UnsupportedEncodingException;
 import java.util.List;
 
+import eu.svjatoslav.meviz.htmlindexer.metadata.DirectoryMetadata;
 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.AbstractFile;
 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Picture;
 
@@ -27,24 +28,28 @@ public interface Layout {
        /**
         * Enlist directory.
         */
-       public void enlistDirectory(AbstractFile directory);
+       public void enlistDirectory(AbstractFile directory,
+                       DirectoryMetadata parentDirectoryMetadata);
 
        /**
         * Enlist simple file.
         */
-       public void enlistFile(AbstractFile file);
+       public void enlistFile(AbstractFile file,
+                       DirectoryMetadata parentDirectoryMetadata);
 
        /**
         * Enlist image file.
         */
-       public void enlistImage(Picture picture);
+       public void enlistImage(Picture picture,
+                       DirectoryMetadata parentDirectoryMetadata);
 
        /**
         * Enlist video in OGV format.
         *
         * @throws UnsupportedEncodingException
         */
-       public void enlistOgv(AbstractFile file)
+       public void enlistOgv(AbstractFile file,
+                       DirectoryMetadata parentDirectoryMetadata)
                        throws UnsupportedEncodingException;
 
        /**
index f7eee2c..08a308b 100755 (executable)
@@ -21,6 +21,7 @@ import eu.svjatoslav.meviz.htmlindexer.Constants;
 import eu.svjatoslav.meviz.htmlindexer.IndexingContext;
 import eu.svjatoslav.meviz.htmlindexer.Layout;
 import eu.svjatoslav.meviz.htmlindexer.metadata.Dimension;
+import eu.svjatoslav.meviz.htmlindexer.metadata.DirectoryMetadata;
 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.AbstractFile;
 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.GeneralFile;
 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Picture;
@@ -44,7 +45,8 @@ public class MixedLayout implements Layout {
        private IndexingContext indexingContext;
 
        @Override
-       public void enlistDirectory(final AbstractFile directory) {
+       public void enlistDirectory(final AbstractFile directory,
+                       final DirectoryMetadata parentDirectoryMetadata) {
                dirHtml.append("<TR>");
                dirHtml.append("<TD><b><a href=\""
                                + indexer.getDirectoryUrl(directory, indexingContext)
@@ -54,7 +56,8 @@ public class MixedLayout implements Layout {
        }
 
        @Override
-       public void enlistFile(final AbstractFile file) {
+       public void enlistFile(final AbstractFile file,
+                       final DirectoryMetadata parentDirectoryMetadata) {
 
                final String fullFileName = file.fileName;
 
@@ -69,7 +72,8 @@ public class MixedLayout implements Layout {
        }
 
        @Override
-       public void enlistImage(final Picture picture) {
+       public void enlistImage(final Picture picture,
+                       final DirectoryMetadata parentDirectoryMetadata) {
                try {
 
                        final Dimension imageSize = picture.getDimensions();
@@ -120,13 +124,14 @@ public class MixedLayout implements Layout {
                                                        + e.toString()
                                                        + ", thumbnail generation skipped, enlisting as ordinary file instead.",
                                        e);
-                       enlistFile(picture);
+                       enlistFile(picture, parentDirectoryMetadata);
                }
        }
 
        /** {@inheritDoc} */
        @Override
-       public void enlistOgv(final AbstractFile abstractFile)
+       public void enlistOgv(final AbstractFile abstractFile,
+                       final DirectoryMetadata parentDirectoryMetadata)
                        throws UnsupportedEncodingException {
 
                final GeneralFile file = (GeneralFile) abstractFile;
index 5c560b0..cb2c2b1 100755 (executable)
@@ -89,7 +89,10 @@ public class DirectoryMetadata implements Serializable {
                                return new GeneralFile(parentDirectory, fileName);
                        }
 
-               if (fileExtension.equals("meviz"))
+               if (fileName.endsWith(".meviz.org"))
+                       return new MevizSpecialFile(parentDirectory, fileName);
+
+               if (fileName.endsWith(".meviz.html"))
                        return new MevizSpecialFile(parentDirectory, fileName);
 
                return new GeneralFile(parentDirectory, fileName);