possibility to include header HTML
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sat, 3 Jan 2015 14:09:03 +0000 (16:09 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sat, 3 Jan 2015 14:09:03 +0000 (16:09 +0200)
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/WebIndexer.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/DirectoryMetadata.java

index 6c672b1..f7cb130 100755 (executable)
@@ -102,7 +102,7 @@ public class FilesystemIndexer extends AbstractIndexer {
                                        compileHtml(layout, metadata);
 
                                        IOHelper.overwriteFileIfContentDiffers(indexFile, layout
-                                                       .getHtml(true, true).getBytes());
+                                                       .getHtml(true, true, metadata).getBytes());
                                }
                        } catch (final Exception e) {
                                logger.error("Error writing index file. ", e);
@@ -144,7 +144,7 @@ public class FilesystemIndexer extends AbstractIndexer {
                validMetadataFiles.add(thumbnailFileName);
                final File thumbnailFile = new File(
                                Utils.getThumbnailsDirectoryPath(directoryToIndex)
-                                               + thumbnailFileName);
+                               + thumbnailFileName);
 
                if (!thumbnailFile.exists()) {
 
@@ -156,7 +156,7 @@ public class FilesystemIndexer extends AbstractIndexer {
                                        desiredDimension.getAwtDimension());
                }
                return Constants.THUMBNAILS_DIRECTORY_NAME + "/"
-                               + UrlParamEncoder.encode(thumbnailFileName);
+               + UrlParamEncoder.encode(thumbnailFileName);
        }
 
        public void initializeLayouts() {
@@ -182,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 e29cb11..b41d83a 100755 (executable)
@@ -9,6 +9,7 @@
 
 package eu.svjatoslav.meviz.htmlindexer;
 
+import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.util.List;
 
@@ -62,9 +63,13 @@ public interface Layout {
        /**
         * After necessary files have been enlisted for particular directory, use
         * this method to retrieve generated HTML result.
+        *
+        * @param metadata
+        * @throws IOException
         */
        public String getHtml(final boolean showTitle,
-                       final boolean doHtmlHeaderAndFooter);
+                       final boolean doHtmlHeaderAndFooter, DirectoryMetadata metadata)
+                       throws IOException;
 
        /**
         * Initialize layout for particular directory.
index 6530e70..acc1a28 100644 (file)
@@ -33,7 +33,7 @@ public class WebIndexer extends AbstractIndexer {
        }
 
        public String getHtml(String requestPath) throws MalformedURLException,
-                       IOException, ClassNotFoundException {
+       IOException, ClassNotFoundException {
 
                if (requestPath == null)
                        requestPath = "";
@@ -46,11 +46,11 @@ public class WebIndexer extends AbstractIndexer {
                                requestPath);
                layout.init("Photos", context.getLocalPathComponents(), this, context);
 
-               final DirectoryMetadata metadata = getMetadataForPath(requestPath);
+               final DirectoryMetadata directory = getMetadataForPath(requestPath);
 
-               compileHtml(layout, metadata);
+               compileHtml(layout, directory);
 
-               return layout.getHtml(false, false);
+               return layout.getHtml(false, false, directory);
        }
 
        public DirectoryMetadata getMetadataForPath(final String requestPath)
@@ -110,14 +110,14 @@ public class WebIndexer extends AbstractIndexer {
                // file path
                if (picture.getDimensions().equals(desiredDimension))
                        return context.getGlobalUrl() + context.getLocalUrl() + "/"
-                                       + picture.fileName;
+                       + picture.fileName;
 
                final String thumbnailFileName = picture
                                .getRelativeThumbnailFileName(desiredDimension);
 
                return context.getGlobalUrl() + context.getLocalUrl() + "/"
-                               + Constants.THUMBNAILS_DIRECTORY_NAME + "/"
-                               + UrlParamEncoder.encode(thumbnailFileName);
+               + Constants.THUMBNAILS_DIRECTORY_NAME + "/"
+               + UrlParamEncoder.encode(thumbnailFileName);
        }
 
 }
index 4e6b5bf..ddacb56 100755 (executable)
@@ -9,6 +9,7 @@
 
 package eu.svjatoslav.meviz.htmlindexer.layouts;
 
+import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.util.List;
 
@@ -81,7 +82,7 @@ public class MixedLayout implements Layout {
                                        "Error generating thumbnails for image file: "
                                                        + e.toString()
                                                        + ", thumbnail generation skipped, enlisting as ordinary file instead.",
-                                       e);
+                                                       e);
                        enlistFile(picture, parentDirectoryMetadata);
                }
        }
@@ -134,7 +135,7 @@ public class MixedLayout implements Layout {
        @Override
        public void enlistOgv(final AbstractFile abstractFile,
                        final DirectoryMetadata parentDirectoryMetadata)
-                       throws UnsupportedEncodingException {
+                                       throws UnsupportedEncodingException {
 
                final GeneralFile file = (GeneralFile) abstractFile;
 
@@ -142,22 +143,22 @@ public class MixedLayout implements Layout {
 
                // watchable video
                filesHtml
-                               .append("<video preload=\"metadata\" controls=\"controls\" tabindex=\"0\">\n");
+               .append("<video preload=\"metadata\" controls=\"controls\" tabindex=\"0\">\n");
                filesHtml
-                               .append("<source type=\"video/ogg\" codecs=\"theora, vorbis\" src=\""
-                                               + indexingContext.getGlobalUrl()
-                                               + UrlParamEncoder.encode(indexingContext.getLocalUrl()
-                                                               + "/" + file.fileName) + "\">\n");
+               .append("<source type=\"video/ogg\" codecs=\"theora, vorbis\" src=\""
+                               + indexingContext.getGlobalUrl()
+                               + UrlParamEncoder.encode(indexingContext.getLocalUrl()
+                                               + "/" + file.fileName) + "\">\n");
                filesHtml.append("</source>\n");
                filesHtml.append("</video>\n");
                filesHtml.append("<br/>\n");
 
                // video title
                filesHtml
-                               .append("Video: <b>"
-                                               + FilePathParser
-                                                               .getFileNameWithoutExtension(file.fileName)
-                                               + "<b/>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
+               .append("Video: <b>"
+                               + FilePathParser
+                               .getFileNameWithoutExtension(file.fileName)
+                               + "<b/>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
 
                // video download link
                filesHtml.append("<a href=\""
@@ -177,42 +178,43 @@ public class MixedLayout implements Layout {
                return "";
        }
 
-       /** {@inheritDoc} */
+       /**
+        * {@inheritDoc}
+        *
+        * @throws IOException
+        */
        @Override
        public String getHtml(final boolean showTitle,
-                       final boolean doHtmlHeaderAndFooter) {
+                       final boolean doHtmlHeaderAndFooter,
+                       final DirectoryMetadata directory) {
 
                // assemble final page HTML
-               final StringBuffer finalHtml = new StringBuffer();
+               final StringBuffer html = new StringBuffer();
 
                if (doHtmlHeaderAndFooter) {
                        // page header
-                       finalHtml.append("<HTML>\n");
-                       finalHtml.append("<HEAD>\n");
-                       finalHtml
-                                       .append("    <meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\"/>\n");
-                       finalHtml.append("</HEAD>\n");
-                       finalHtml
-                                       .append("<BODY bgcolor=\"#000000\" alink=\"#50ffff\" link=\"#50ffff\" vlink=\"#ff50ff\" text=\"#ffffff\">\n");
-                       finalHtml.append("<!-- " + Constants.HTML_MAGIC_STRING + " -->\n");
-                       finalHtml.append("<!-- " + Constants.HTML_MEMO + " -->\n");
-                       finalHtml.append("<font color=\"#ffffff\">\n");
+                       html.append("<HTML>\n");
+                       html.append("<HEAD>\n");
+                       html.append("    <meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\"/>\n");
+                       html.append("</HEAD>\n");
+                       html.append("<BODY bgcolor=\"#000000\" alink=\"#50ffff\" link=\"#50ffff\" vlink=\"#ff50ff\" text=\"#ffffff\">\n");
+                       html.append("<!-- " + Constants.HTML_MAGIC_STRING + " -->\n");
+                       html.append("<!-- " + Constants.HTML_MEMO + " -->\n");
+                       html.append("<font color=\"#ffffff\">\n");
                }
 
                if (showTitle)
-                       finalHtml
-                                       .append("<CENTER><H1>" + galleryTitle + "</H1></CENTER>\n");
-
-               showCurrentPath(finalHtml);
+                       html.append("<CENTER><H1>" + galleryTitle + "</H1></CENTER>\n");
 
-               listDirectories(finalHtml);
-
-               finalHtml.append(filesHtml.toString());
+               html.append(showCurrentPath());
+               html.append(listDirectories());
+               html.append(directory.getHeaderMevizMetadataHtml());
+               html.append(filesHtml.toString());
 
                if (doHtmlHeaderAndFooter)
-                       finalHtml.append("</font></BODY></HTML>\n");
+                       html.append("</font></BODY></HTML>\n");
 
-               return finalHtml.toString();
+               return html.toString();
        }
 
        private String getImageThumbnailUrl(final Picture picture) {
@@ -241,27 +243,33 @@ public class MixedLayout implements Layout {
                filesHtml = new StringBuffer();
        }
 
-       private void listDirectories(final StringBuffer finalHtml) {
-               finalHtml.append("<TABLE>\n");
+       private String listDirectories() {
+               final StringBuilder html = new StringBuilder();
+               html.append("<TABLE>\n");
 
                if (path.size() > 0) {
-                       finalHtml.append("<TR>");
-                       finalHtml.append("<TD><b><a href=\""
+                       html.append("<TR>");
+                       html.append("<TD><b><a href=\""
                                        + indexer.getParentDirectoryUrl(indexingContext)
                                        + "\"><h2> &lt;== parent directory</h2></a></b></TD>");
-                       finalHtml.append("</TR>\n");
+                       html.append("</TR>\n");
                }
 
-               finalHtml.append(dirHtml.toString());
-               finalHtml.append("\n<TR><TD><br></TD></TR>\n");
-               finalHtml.append("</TABLE>\n");
+               html.append(dirHtml.toString());
+               html.append("\n<TR><TD><br></TD></TR>\n");
+               html.append("</TABLE>\n");
+
+               return html.toString();
        }
 
-       private void showCurrentPath(final StringBuffer finalHtml) {
-               finalHtml.append("<CENTER><H2>");
+       private String showCurrentPath() {
+               final StringBuilder html = new StringBuilder();
+               html.append("<CENTER><H2>");
                for (final String p : path)
-                       finalHtml.append(" / " + p);
-               finalHtml.append("</H2></CENTER>\n");
+                       html.append(" / " + p);
+               html.append("</H2></CENTER>\n");
+
+               return html.toString();
        }
 
 }
index cb2c2b1..84fad12 100755 (executable)
@@ -98,7 +98,7 @@ public class DirectoryMetadata implements Serializable {
                return new GeneralFile(parentDirectory, fileName);
        }
 
-       public AbstractFile getFile(final String fileName) throws IOException {
+       public AbstractFile getFile(final String fileName) {
                return fileNameToFileMap.get(fileName);
        }
 
@@ -112,6 +112,15 @@ public class DirectoryMetadata implements Serializable {
                return files;
        }
 
+       public String getHeaderMevizMetadataHtml() {
+               final AbstractFile headerFile = getFile("header.meviz.html");
+               if (headerFile == null)
+                       return "";
+
+               final MevizSpecialFile mevizSpecialFile = (MevizSpecialFile) headerFile;
+               return mevizSpecialFile.getFileContent();
+       }
+
        public Dimension getImageDimensions(final String fileName)
                        throws IOException, ImageFormatError {