possilibity to generate HTML while embedded on the web site
authorSvjatoslav Agejenko <n0@n0-Aspire-8920.(none)>
Sun, 27 Jan 2013 19:49:52 +0000 (21:49 +0200)
committerSvjatoslav Agejenko <n0@n0-Aspire-8920.(none)>
Sun, 27 Jan 2013 19:49:52 +0000 (21:49 +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/WebIndexer.java [new file with mode: 0644]
src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java

index cc8f159..4b1e29c 100644 (file)
@@ -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);
 
index 9c8c877..ea6489e 100755 (executable)
@@ -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() {
index 510e7ad..2dac2ff 100755 (executable)
@@ -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 (file)
index 0000000..20ec8d1
--- /dev/null
@@ -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;
+       }
+
+}
index f54b72f..40286e9 100755 (executable)
@@ -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("<TR>");
-               dirHtml.append("<TD><b><a href=\"" + directory.fileName
-                               + "/index.html\"> ==&gt; " + directory.fileName
-                               + "</a></b></TD>");
+               dirHtml.append("<TD><b><a href=\"" + indexer.getDirectoryUrl(directory) + "\"> ==&gt; "
+                               + directory.fileName + "</a></b></TD>");
                dirHtml.append("</TR>\n");
 
        }
@@ -73,8 +74,8 @@ public class MixedLayout implements Layout {
                filesHtml.append("<TR>\n");
                filesHtml.append("    <TD colspan=\""
                                + String.valueOf(horizontalColumnsLimit) + "\"><a href=\""
-                               + UrlParamEncoder.encode(fullFileName) + "\">" + fullFileName
-                               + "</a>\n");
+                               + UrlParamEncoder.encode(pathPrefix + fullFileName) + "\">"
+                               + fullFileName + "</a>\n");
                filesHtml.append("&nbsp;&nbsp;("
                                + FilePathParser.getFileSizeDescription(file.getFileLength())
                                + ")</TD>\n");
@@ -105,7 +106,8 @@ public class MixedLayout implements Layout {
                        startcolumn();
 
                        filesHtml.append("<TD><center><a href=\""
-                                       + UrlParamEncoder.encode(picture.fileName) + "\">\n");
+                                       + UrlParamEncoder.encode(pathPrefix + picture.fileName)
+                                       + "\">\n");
 
                        filesHtml.append("<img border=\"0\" src=\""
                                        + UrlParamEncoder.encode(listingThumbnailPath)
@@ -158,14 +160,17 @@ public class MixedLayout implements Layout {
                filesHtml.append("<video controls=\"controls\" tabindex=\"0\">\n");
                filesHtml
                                .append("<source type=\"video/ogg\" codecs=\"theora, vorbis\" src=\""
-                                               + UrlParamEncoder.encode(file.fileName) + "\">\n");
+                                               + UrlParamEncoder.encode(pathPrefix + file.fileName)
+                                               + "\">\n");
                filesHtml.append("</source>\n");
 
                // if browser cannot play video directry, fall back to java Applet
                filesHtml
                                .append("<applet code=\"com.fluendo.player.Cortado.class\" archive=\"http://theora.org/cortado.jar\" width=\"800\" height=\"600\">\n");
-               filesHtml.append("    <param name=\"url\" value=\""
-                               + UrlParamEncoder.encode(file.fileName) + "\"/>\n");
+               filesHtml
+                               .append("    <param name=\"url\" value=\""
+                                               + UrlParamEncoder.encode(pathPrefix + file.fileName)
+                                               + "\"/>\n");
                filesHtml.append("    <param name=\"keepAspect\" value=\"true\"/>\n");
                filesHtml.append("    <param name=\"autoPlay\" value=\"false\"/>\n");
                filesHtml.append("</applet>\n");
@@ -179,7 +184,8 @@ public class MixedLayout implements Layout {
                                                + FilePathParser
                                                                .getFileNameWithoutExtension(file.fileName)
                                                + "<b/>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
-               filesHtml.append("<a href=\"" + UrlParamEncoder.encode(file.fileName)
+               filesHtml.append("<a href=\""
+                               + UrlParamEncoder.encode(pathPrefix + file.fileName)
                                + "\">download as OGV</a>\n");
 
                filesHtml.append("</TD></TR>\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() {