2 * Meviz - Various tools collection to work with multimedia.
3 * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public License
7 * as published by the Free Software Foundation.
10 package eu.svjatoslav.meviz.htmlindexer.layouts;
12 import java.io.UnsupportedEncodingException;
13 import java.util.List;
15 import org.apache.log4j.Logger;
17 import eu.svjatoslav.commons.file.FilePathParser;
18 import eu.svjatoslav.commons.network.UrlParamEncoder;
19 import eu.svjatoslav.meviz.htmlindexer.AbstractIndexer;
20 import eu.svjatoslav.meviz.htmlindexer.Constants;
21 import eu.svjatoslav.meviz.htmlindexer.Layout;
22 import eu.svjatoslav.meviz.htmlindexer.metadata.Dimension;
23 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.AbstractFile;
24 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.GeneralFile;
25 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Picture;
27 public class MixedLayout implements Layout {
29 Logger logger = Logger.getLogger(MixedLayout.class);
31 StringBuffer dirHtml = new StringBuffer();
33 StringBuffer filesHtml = new StringBuffer();
39 public static final String encoding = "UTF-8";
41 int currentColumn = 0;
43 int horizontalColumnsLimit = 2;
45 private AbstractIndexer indexer;
47 public void columnAdded() {
49 if (currentColumn > horizontalColumnsLimit) {
53 filesHtml.append("</TR>\n");
58 public void enlistDirectory(final AbstractFile directory) {
59 dirHtml.append("<TR>");
60 dirHtml.append("<TD><b><a href=\"" + directory.fileName
61 + "/index.html\"> ==> " + directory.fileName
63 dirHtml.append("</TR>\n");
68 public void enlistFile(final AbstractFile file) {
71 final String fullFileName = file.fileName;
73 filesHtml.append("<TR>\n");
74 filesHtml.append(" <TD colspan=\""
75 + String.valueOf(horizontalColumnsLimit) + "\"><a href=\""
76 + UrlParamEncoder.encode(fullFileName) + "\">" + fullFileName
78 filesHtml.append(" ("
79 + FilePathParser.getFileSizeDescription(file.getFileLength())
81 filesHtml.append("</TR>\n");
86 public void enlistImage(final AbstractFile abstractFile) {
89 final Picture picture = (Picture) abstractFile;
91 final Dimension imageSize = picture.getDimensions();
93 final List<Dimension> recommendedDimensions = Picture
94 .getThumbnailDimensions(imageSize);
96 Dimension listingDimension = new Dimension(500, 500);
98 if (listingDimension.width > imageSize.width)
99 if (listingDimension.height > imageSize.height)
100 listingDimension = imageSize;
102 final String listingThumbnailPath = indexer.getThumbnailPath(
103 picture, listingDimension);
107 filesHtml.append("<TD><center><a href=\""
108 + UrlParamEncoder.encode(picture.fileName) + "\">\n");
110 filesHtml.append("<img border=\"0\" src=\""
111 + UrlParamEncoder.encode(listingThumbnailPath)
113 filesHtml.append("<br/><b>"
115 .getFileNameWithoutExtension(picture.fileName)
119 for (final Dimension dimension : recommendedDimensions) {
122 filesHtml.append(", ");
123 filesHtml.append("<a href=\""
124 + UrlParamEncoder.encode(indexer.getThumbnailPath(
125 picture, dimension)) + "\">");
126 filesHtml.append(dimension.width + "x" + dimension.height);
127 filesHtml.append("</a>");
130 filesHtml.append(")</TD>\n");
134 } catch (final Exception e) {
136 "Error generating thumbnails for image file: "
138 + ", thumbnail generation skipped, enlisting as ordinary file instead.",
140 enlistFile(abstractFile);
146 public void enlistOgv(final AbstractFile abstractFile)
147 throws UnsupportedEncodingException {
149 final GeneralFile file = (GeneralFile) abstractFile;
154 .append("<TR style=\"background-color: #404040; text-align: center\">\n");
155 filesHtml.append("<TD style=\"text-align: center\" colspan=\""
156 + String.valueOf(horizontalColumnsLimit) + "\">\n");
158 filesHtml.append("<video controls=\"controls\" tabindex=\"0\">\n");
160 .append("<source type=\"video/ogg\" codecs=\"theora, vorbis\" src=\""
161 + UrlParamEncoder.encode(file.fileName) + "\">\n");
162 filesHtml.append("</source>\n");
164 // if browser cannot play video directry, fall back to java Applet
166 .append("<applet code=\"com.fluendo.player.Cortado.class\" archive=\"http://theora.org/cortado.jar\" width=\"800\" height=\"600\">\n");
167 filesHtml.append(" <param name=\"url\" value=\""
168 + UrlParamEncoder.encode(file.fileName) + "\"/>\n");
169 filesHtml.append(" <param name=\"keepAspect\" value=\"true\"/>\n");
170 filesHtml.append(" <param name=\"autoPlay\" value=\"false\"/>\n");
171 filesHtml.append("</applet>\n");
173 filesHtml.append("</video>\n");
175 filesHtml.append("<br/>\n");
180 .getFileNameWithoutExtension(file.fileName)
181 + "<b/> ");
182 filesHtml.append("<a href=\"" + UrlParamEncoder.encode(file.fileName)
183 + "\">download as OGV</a>\n");
185 filesHtml.append("</TD></TR>\n");
189 public void finishRow() {
191 if (currentColumn == 0)
194 while (currentColumn <= horizontalColumnsLimit) {
195 filesHtml.append("<TD></TD>");
198 filesHtml.append("</TR>\n");
204 public String getFileNameSuffix() {
210 public String getHtml() {
212 // assemble final page HTML
213 final StringBuffer finalHtml = new StringBuffer();
216 finalHtml.append("<HTML>\n");
217 finalHtml.append("<HEAD>\n");
219 .append(" <meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\"/>\n");
220 finalHtml.append("</HEAD>\n");
222 .append("<BODY bgcolor=\"#000000\" alink=\"#50ffff\" link=\"#50ffff\" vlink=\"#ff50ff\" text=\"#ffffff\">\n");
223 finalHtml.append("<!-- " + Constants.HTML_MAGIC_STRING + " -->\n");
224 finalHtml.append("<!-- " + Constants.HTML_MEMO + " -->\n");
225 finalHtml.append("<FONT color=\"#ffffff\">\n");
226 finalHtml.append("<CENTER><H1>" + galleryTitle + "</H1>\n");
228 finalHtml.append("<H2>");
229 for (final String p : path)
230 finalHtml.append(" / " + p);
231 finalHtml.append("</H2></CENTER>\n");
233 // append directory listing
234 finalHtml.append("<TABLE>\n");
236 if (path.length > 0) {
237 finalHtml.append("<TR>");
239 .append("<TD><b><a href=\"../index.html\"> <== ..</a></b></TD>");
240 finalHtml.append("</TR>\n");
243 finalHtml.append(dirHtml.toString());
244 finalHtml.append("\n<TR><TD><br></TD></TR>\n");
245 finalHtml.append("</TABLE>\n");
247 // append file listing
250 finalHtml.append("<TABLE width=\"1100\">\n");
251 finalHtml.append(filesHtml.toString());
252 finalHtml.append("\n</TABLE>\n");
254 finalHtml.append("</font></BODY></HTML>\n");
256 return finalHtml.toString();
260 public void init(final String galleryTitle, final String[] path,
261 final AbstractIndexer indexer) {
262 this.indexer = indexer;
263 this.galleryTitle = galleryTitle;
267 public void startcolumn() {
268 if (currentColumn == 0) {
269 filesHtml.append("<TR>");