From bc5af7e323346f34d0e551b8be67e458d43271e6 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Wed, 30 Jan 2013 21:48:11 +0200 Subject: [PATCH] possilibity to generate HTML while embedded on the web site --- .../meviz/htmlindexer/WebIndexer.java | 35 ++++++++++++------- .../htmlindexer/layouts/MixedLayout.java | 4 +-- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/WebIndexer.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/WebIndexer.java index 20ec8d1..61013a4 100644 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/WebIndexer.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/WebIndexer.java @@ -6,6 +6,7 @@ import java.io.ObjectInputStream; import java.net.MalformedURLException; import java.net.URL; +import eu.svjatoslav.commons.network.UrlParamEncoder; import eu.svjatoslav.meviz.htmlindexer.layouts.MixedLayout; import eu.svjatoslav.meviz.htmlindexer.metadata.Dimension; import eu.svjatoslav.meviz.htmlindexer.metadata.DirectoryMetadata; @@ -14,7 +15,6 @@ 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; @@ -25,27 +25,38 @@ public class WebIndexer extends AbstractIndexer { @Override public String getDirectoryUrl(final AbstractFile directory) { - return "photos.jsp?path=/" + directory.fileName; + return "photos.jsp?path=/" + UrlParamEncoder.encode(directory.fileName); } - public String getHtml(final String path) throws MalformedURLException, - IOException, ClassNotFoundException { + public String getHtml(final String requestPath) + throws MalformedURLException, IOException, ClassNotFoundException { - layout.init("Photos", new String[] {}, this, localPrefix); + final MixedLayout layout = new MixedLayout(); + layout.init("Photos", new String[] {}, this, localPrefix + requestPath); - final DirectoryMetadata metadata = getMetadataForPath(); + final DirectoryMetadata metadata = getMetadataForPath(requestPath); compileHtml(layout, metadata); return layout.getHtml(); } - public DirectoryMetadata getMetadataForPath() throws IOException, - MalformedURLException, ClassNotFoundException { + public DirectoryMetadata getMetadataForPath(final String requestPath) + throws IOException, MalformedURLException, ClassNotFoundException { - final BufferedInputStream in = new BufferedInputStream( - new URL(globalPrefix + localPrefix - + ".thumbnails/metadata_6.dat").openStream()); + final StringBuffer urlStringBuffer = new StringBuffer(); + + urlStringBuffer.append(globalPrefix); + urlStringBuffer.append(UrlParamEncoder.encode(localPrefix)); + urlStringBuffer.append(UrlParamEncoder.encode(requestPath)); + if (!requestPath.equals("/")) + urlStringBuffer.append("/"); + urlStringBuffer.append(".thumbnails/metadata_6.dat"); + + final String urlString = urlStringBuffer.toString(); + + final BufferedInputStream in = new BufferedInputStream(new URL( + urlString).openStream()); final ObjectInputStream oin = new ObjectInputStream(in); final DirectoryMetadata directory = (DirectoryMetadata) oin @@ -67,7 +78,7 @@ public class WebIndexer extends AbstractIndexer { final String thumbnailFileName = picture .getRelativeThumbnailFileName(desiredDimension); - return localPrefix + Constants.THUMBNAILS_DIRECTORY_NAME + "/" + 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 40286e9..345cd40 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java @@ -59,8 +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"); } -- 2.20.1