possilibity to generate HTML while embedded on the web site
[meviz.git] / src / main / java / eu / svjatoslav / meviz / htmlindexer / layouts / MixedLayout.java
index 345cd40..4c00985 100755 (executable)
@@ -18,6 +18,7 @@ import eu.svjatoslav.commons.file.FilePathParser;
 import eu.svjatoslav.commons.network.UrlParamEncoder;
 import eu.svjatoslav.meviz.htmlindexer.AbstractIndexer;
 import eu.svjatoslav.meviz.htmlindexer.Constants;
+import eu.svjatoslav.meviz.htmlindexer.IndexingContext;
 import eu.svjatoslav.meviz.htmlindexer.Layout;
 import eu.svjatoslav.meviz.htmlindexer.metadata.Dimension;
 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.AbstractFile;
@@ -34,7 +35,7 @@ public class MixedLayout implements Layout {
 
        String galleryTitle;
 
-       String[] path;
+       List<String> path;
 
        public static final String encoding = "UTF-8";
 
@@ -44,7 +45,7 @@ public class MixedLayout implements Layout {
 
        private AbstractIndexer indexer;
 
-       private String pathPrefix;
+       private IndexingContext indexingContext;
 
        public void columnAdded() {
                currentColumn++;
@@ -59,7 +60,8 @@ public class MixedLayout implements Layout {
        @Override
        public void enlistDirectory(final AbstractFile directory) {
                dirHtml.append("<TR>");
-               dirHtml.append("<TD><b><a href=\"" + indexer.getDirectoryUrl(directory)
+               dirHtml.append("<TD><b><a href=\""
+                               + indexer.getDirectoryUrl(directory, indexingContext)
                                + "\"> ==&gt; " + directory.fileName + "</a></b></TD>");
                dirHtml.append("</TR>\n");
 
@@ -73,9 +75,11 @@ public class MixedLayout implements Layout {
 
                filesHtml.append("<TR>\n");
                filesHtml.append("    <TD colspan=\""
-                               + String.valueOf(horizontalColumnsLimit) + "\"><a href=\""
-                               + UrlParamEncoder.encode(pathPrefix + fullFileName) + "\">"
-                               + fullFileName + "</a>\n");
+                               + String.valueOf(horizontalColumnsLimit)
+                               + "\"><a href=\""
+                               + indexingContext.getGlobalUrl()
+                               + UrlParamEncoder.encode(indexingContext.getLocalUrl()
+                                               + fullFileName) + "\">" + fullFileName + "</a>\n");
                filesHtml.append("&nbsp;&nbsp;("
                                + FilePathParser.getFileSizeDescription(file.getFileLength())
                                + ")</TD>\n");
@@ -100,17 +104,17 @@ public class MixedLayout implements Layout {
                                if (listingDimension.height > imageSize.height)
                                        listingDimension = imageSize;
 
-                       final String listingThumbnailPath = indexer.getThumbnailPath(
-                                       picture, listingDimension);
+                       final String listingThumbnailUrl = indexer.getThumbnailUrl(picture,
+                                       listingDimension, indexingContext);
 
                        startcolumn();
 
                        filesHtml.append("<TD><center><a href=\""
-                                       + UrlParamEncoder.encode(pathPrefix + picture.fileName)
-                                       + "\">\n");
+                                       + indexingContext.getGlobalUrl()
+                                       + UrlParamEncoder.encode(indexingContext.getLocalUrl()
+                                                       + "/" + picture.fileName) + "\">\n");
 
-                       filesHtml.append("<img border=\"0\" src=\""
-                                       + UrlParamEncoder.encode(listingThumbnailPath)
+                       filesHtml.append("<img border=\"0\" src=\"" + listingThumbnailUrl
                                        + "\"/></a>\n");
                        filesHtml.append("<br/><b>"
                                        + FilePathParser
@@ -123,8 +127,8 @@ public class MixedLayout implements Layout {
                                if (count > 1)
                                        filesHtml.append(", ");
                                filesHtml.append("<a href=\""
-                                               + UrlParamEncoder.encode(indexer.getThumbnailPath(
-                                                               picture, dimension)) + "\">");
+                                               + indexer.getThumbnailUrl(picture, dimension,
+                                                               indexingContext) + "\">");
                                filesHtml.append(dimension.width + "x" + dimension.height);
                                filesHtml.append("</a>");
                        }
@@ -160,17 +164,18 @@ 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(pathPrefix + file.fileName)
-                                               + "\">\n");
+                                               + indexingContext.getGlobalUrl()
+                                               + UrlParamEncoder.encode(indexingContext.getLocalUrl()
+                                                               + 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(pathPrefix + file.fileName)
-                                               + "\"/>\n");
+               filesHtml.append("    <param name=\"url\" value=\""
+                               + indexingContext.getGlobalUrl()
+                               + UrlParamEncoder.encode(indexingContext.getLocalUrl()
+                                               + file.fileName) + "\"/>\n");
                filesHtml.append("    <param name=\"keepAspect\" value=\"true\"/>\n");
                filesHtml.append("    <param name=\"autoPlay\" value=\"false\"/>\n");
                filesHtml.append("</applet>\n");
@@ -185,8 +190,9 @@ public class MixedLayout implements Layout {
                                                                .getFileNameWithoutExtension(file.fileName)
                                                + "<b/>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                filesHtml.append("<a href=\""
-                               + UrlParamEncoder.encode(pathPrefix + file.fileName)
-                               + "\">download as OGV</a>\n");
+                               + indexingContext.getGlobalUrl()
+                               + UrlParamEncoder.encode(indexingContext.getLocalUrl()
+                                               + file.fileName) + "\">download as OGV</a>\n");
 
                filesHtml.append("</TD></TR>\n");
 
@@ -239,10 +245,11 @@ public class MixedLayout implements Layout {
                // append directory listing
                finalHtml.append("<TABLE>\n");
 
-               if (path.length > 0) {
+               if (path.size() > 0) {
                        finalHtml.append("<TR>");
-                       finalHtml
-                                       .append("<TD><b><a href=\"../index.html\"> &lt;== ..</a></b></TD>");
+                       finalHtml.append("<TD><b><a href=\""
+                                       + indexer.getParentDirectoryUrl(indexingContext)
+                                       + "\"> &lt;== ..</a></b></TD>");
                        finalHtml.append("</TR>\n");
                }
 
@@ -263,12 +270,13 @@ public class MixedLayout implements Layout {
        }
 
        @Override
-       public void init(final String galleryTitle, final String[] path,
-                       final AbstractIndexer indexer, final String pathPrefix) {
+       public void init(final String galleryTitle, final List<String> path,
+                       final AbstractIndexer indexer, final IndexingContext indexingContext) {
+
                this.indexer = indexer;
                this.galleryTitle = galleryTitle;
                this.path = path;
-               this.pathPrefix = pathPrefix;
+               this.indexingContext = indexingContext;
 
                dirHtml = new StringBuffer();
                filesHtml = new StringBuffer();