possilibity to generate HTML while embedded on the web site
authorSvjatoslav Agejenko <n0@n0-Aspire-8920.(none)>
Wed, 30 Jan 2013 19:48:11 +0000 (21:48 +0200)
committerSvjatoslav Agejenko <n0@n0-Aspire-8920.(none)>
Wed, 30 Jan 2013 19:48:11 +0000 (21:48 +0200)
src/main/java/eu/svjatoslav/meviz/htmlindexer/WebIndexer.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java

index 20ec8d1..61013a4 100644 (file)
@@ -6,6 +6,7 @@ import java.io.ObjectInputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
 
 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;
 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 {
 
 
 public class WebIndexer extends AbstractIndexer {
 
-       private final MixedLayout layout = new MixedLayout();
        private final String localPrefix;
        private final String globalPrefix;
 
        private final String localPrefix;
        private final String globalPrefix;
 
@@ -25,27 +25,38 @@ public class WebIndexer extends AbstractIndexer {
 
        @Override
        public String getDirectoryUrl(final AbstractFile directory) {
 
        @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();
        }
 
 
                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
 
                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);
 
                final String thumbnailFileName = picture
                                .getRelativeThumbnailFileName(desiredDimension);
 
-               return localPrefix + Constants.THUMBNAILS_DIRECTORY_NAME + "/"
+               return localPrefix + "/" + Constants.THUMBNAILS_DIRECTORY_NAME + "/"
                                + thumbnailFileName;
        }
 
                                + thumbnailFileName;
        }
 
index 40286e9..345cd40 100755 (executable)
@@ -59,8 +59,8 @@ public class MixedLayout implements Layout {
        @Override
        public void enlistDirectory(final AbstractFile directory) {
                dirHtml.append("<TR>");
        @Override
        public void enlistDirectory(final AbstractFile directory) {
                dirHtml.append("<TR>");
-               dirHtml.append("<TD><b><a href=\"" + indexer.getDirectoryUrl(directory) + "\"> ==&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");
 
        }
                dirHtml.append("</TR>\n");
 
        }