From 2456c6f80f725ffbf6278f4834d131f73cd295f7 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sun, 27 Jan 2013 21:49:52 +0200 Subject: [PATCH] possilibity to generate HTML while embedded on the web site --- .../meviz/htmlindexer/AbstractIndexer.java | 4 +- .../meviz/htmlindexer/FilesystemIndexer.java | 7 +- .../svjatoslav/meviz/htmlindexer/Layout.java | 2 +- .../meviz/htmlindexer/WebIndexer.java | 74 +++++++++++++++++++ .../htmlindexer/layouts/MixedLayout.java | 32 +++++--- 5 files changed, 105 insertions(+), 14 deletions(-) create mode 100644 src/main/java/eu/svjatoslav/meviz/htmlindexer/WebIndexer.java diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/AbstractIndexer.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/AbstractIndexer.java index cc8f159..4b1e29c 100644 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/AbstractIndexer.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/AbstractIndexer.java @@ -21,7 +21,7 @@ public abstract class AbstractIndexer { final String fileExtension = file.getFileExtension(); if ("ogv".equals(fileExtension)) - layout.enlistOgv((GeneralFile) file); + layout.enlistOgv(file); else layout.enlistFile(file); @@ -32,6 +32,8 @@ public abstract class AbstractIndexer { } + public abstract String getDirectoryUrl(final AbstractFile directory); + public abstract String getThumbnailPath(Picture picture, final Dimension desiredDimension); diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/FilesystemIndexer.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/FilesystemIndexer.java index 9c8c877..ea6489e 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/FilesystemIndexer.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/FilesystemIndexer.java @@ -148,6 +148,11 @@ public class FilesystemIndexer extends AbstractIndexer { } } + @Override + public String getDirectoryUrl(final AbstractFile directory) { + return directory.fileName + "/index.html"; + } + public String[] getSubPath(final File file) { final String[] subPath = new String[pathElements.length + 1]; @@ -209,7 +214,7 @@ public class FilesystemIndexer extends AbstractIndexer { layouts.add(new MixedLayout()); for (final Layout layout : layouts) - layout.init(indexingOptions.galleryTitle, pathElements, this); + layout.init(indexingOptions.galleryTitle, pathElements, this, ""); } public void initializeThumbnailsDirectory() { diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/Layout.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/Layout.java index 510e7ad..2dac2ff 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/Layout.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/Layout.java @@ -62,5 +62,5 @@ public interface Layout { * Initialize layout for particular directory. */ public void init(String galleryTitle, String[] path, - final AbstractIndexer indexer); + final AbstractIndexer indexer, final String pathPrefix); } diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/WebIndexer.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/WebIndexer.java new file mode 100644 index 0000000..20ec8d1 --- /dev/null +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/WebIndexer.java @@ -0,0 +1,74 @@ +package eu.svjatoslav.meviz.htmlindexer; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.net.MalformedURLException; +import java.net.URL; + +import eu.svjatoslav.meviz.htmlindexer.layouts.MixedLayout; +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.Picture; + +public class WebIndexer extends AbstractIndexer { + + private final MixedLayout layout = new MixedLayout(); + private final String localPrefix; + private final String globalPrefix; + + public WebIndexer(final String globalPrefix, final String localPrefix) { + this.globalPrefix = globalPrefix; + this.localPrefix = localPrefix; + } + + @Override + public String getDirectoryUrl(final AbstractFile directory) { + return "photos.jsp?path=/" + directory.fileName; + } + + public String getHtml(final String path) throws MalformedURLException, + IOException, ClassNotFoundException { + + layout.init("Photos", new String[] {}, this, localPrefix); + + final DirectoryMetadata metadata = getMetadataForPath(); + + compileHtml(layout, metadata); + + return layout.getHtml(); + } + + public DirectoryMetadata getMetadataForPath() throws IOException, + MalformedURLException, ClassNotFoundException { + + final BufferedInputStream in = new BufferedInputStream( + new URL(globalPrefix + localPrefix + + ".thumbnails/metadata_6.dat").openStream()); + + final ObjectInputStream oin = new ObjectInputStream(in); + final DirectoryMetadata directory = (DirectoryMetadata) oin + .readObject(); + in.close(); + + return directory; + } + + @Override + public String getThumbnailPath(final Picture picture, + final Dimension desiredDimension) { + + // in case thumbnail size was equal to original, then return original + // file path + if (picture.getDimensions().equals(desiredDimension)) + return localPrefix + picture.fileName; + + final String thumbnailFileName = picture + .getRelativeThumbnailFileName(desiredDimension); + + return localPrefix + Constants.THUMBNAILS_DIRECTORY_NAME + "/" + + thumbnailFileName; + } + +} diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java index f54b72f..40286e9 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java @@ -44,6 +44,8 @@ public class MixedLayout implements Layout { private AbstractIndexer indexer; + private String pathPrefix; + public void columnAdded() { currentColumn++; if (currentColumn > horizontalColumnsLimit) { @@ -57,9 +59,8 @@ public class MixedLayout implements Layout { @Override public void enlistDirectory(final AbstractFile directory) { dirHtml.append(""); - dirHtml.append(" ==> " + directory.fileName - + ""); + dirHtml.append(" ==> " + + directory.fileName + ""); dirHtml.append("\n"); } @@ -73,8 +74,8 @@ public class MixedLayout implements Layout { filesHtml.append("\n"); filesHtml.append(" " + fullFileName - + "\n"); + + UrlParamEncoder.encode(pathPrefix + fullFileName) + "\">" + + fullFileName + "\n"); filesHtml.append("  (" + FilePathParser.getFileSizeDescription(file.getFileLength()) + ")\n"); @@ -105,7 +106,8 @@ public class MixedLayout implements Layout { startcolumn(); filesHtml.append("
\n"); + + UrlParamEncoder.encode(pathPrefix + picture.fileName) + + "\">\n"); filesHtml.append("\n"); filesHtml .append("\n"); + + UrlParamEncoder.encode(pathPrefix + file.fileName) + + "\">\n"); filesHtml.append("\n"); // if browser cannot play video directry, fall back to java Applet filesHtml .append("\n"); - filesHtml.append(" \n"); + filesHtml + .append(" \n"); filesHtml.append(" \n"); filesHtml.append(" \n"); filesHtml.append("\n"); @@ -179,7 +184,8 @@ public class MixedLayout implements Layout { + FilePathParser .getFileNameWithoutExtension(file.fileName) + "            "); - filesHtml.append("download as OGV\n"); filesHtml.append("\n"); @@ -258,10 +264,14 @@ public class MixedLayout implements Layout { @Override public void init(final String galleryTitle, final String[] path, - final AbstractIndexer indexer) { + final AbstractIndexer indexer, final String pathPrefix) { this.indexer = indexer; this.galleryTitle = galleryTitle; this.path = path; + this.pathPrefix = pathPrefix; + + dirHtml = new StringBuffer(); + filesHtml = new StringBuffer(); } public void startcolumn() { -- 2.20.1