}
- public abstract String getDirectoryUrl(final AbstractFile directory);
+ public abstract String getDirectoryUrl(final AbstractFile directory,
+ IndexingContext context);
- public abstract String getThumbnailPath(Picture picture,
- final Dimension desiredDimension);
+ public abstract String getParentDirectoryUrl(IndexingContext context);
+
+ public abstract String getThumbnailUrl(Picture picture,
+ final Dimension desiredDimension, IndexingContext context);
public static boolean isImage(final String fileExtension) {
for (final String ext : Constants.SUPPORTED_IMAGE_EXTENSIONS)
import java.io.FileReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import org.apache.log4j.Logger;
import eu.svjatoslav.commons.file.IOHelper;
+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;
private final IndexingOptions indexingOptions;
- private final String[] pathElements;
+ private final List<String> pathElements;
private HashSet<Layout> layouts;
public FilesystemIndexer(final File directoryToIndex,
- final IndexingOptions indexingOptions, final String[] pathElements)
- throws IOException, ImageFormatError {
+ final IndexingOptions indexingOptions,
+ final List<String> pathElements) throws IOException,
+ ImageFormatError {
this.directoryToIndex = directoryToIndex;
this.indexingOptions = indexingOptions;
}
}
- @Override
- public String getDirectoryUrl(final AbstractFile directory) {
- return directory.fileName + "/index.html";
- }
+ public List<String> getChildPath(final File file) {
- public String[] getSubPath(final File file) {
+ final List<String> result = new ArrayList<String>();
+ result.addAll(pathElements);
+ result.add(file.getName());
- final String[] subPath = new String[pathElements.length + 1];
+ return result;
+ }
- for (int i = 0; i < pathElements.length; i++)
- subPath[i] = pathElements[i];
+ @Override
+ public String getDirectoryUrl(final AbstractFile directory,
+ final IndexingContext context) {
+ return directory.fileName + "/index.html";
+ }
- subPath[pathElements.length] = file.getName();
- return subPath;
+ @Override
+ public String getParentDirectoryUrl(final IndexingContext context) {
+ return "../index.html";
}
@Override
- public String getThumbnailPath(final Picture picture,
- final Dimension desiredDimension) {
+ public String getThumbnailUrl(final Picture picture,
+ final Dimension desiredDimension, final IndexingContext context) {
// in case thumbnail size was equal to original, then return original
// file path
Picture.makeThumbnail(originalFile, thumbnailFile,
desiredDimension.getAwtDimension());
}
- return Constants.THUMBNAILS_DIRECTORY_NAME + "/" + thumbnailFileName;
+ return Constants.THUMBNAILS_DIRECTORY_NAME + "/"
+ + UrlParamEncoder.encode(thumbnailFileName);
}
public void indexForLayout(final Layout layout)
layouts.add(new MixedLayout());
for (final Layout layout : layouts)
- layout.init(indexingOptions.galleryTitle, pathElements, this, "");
+ layout.init(indexingOptions.galleryTitle, pathElements, this,
+ new IndexingContext("", ""));
}
public void initializeThumbnailsDirectory() {
if (file.isDirectory())
new FilesystemIndexer(file, indexingOptions,
- getSubPath(file));
+ getChildPath(file));
}
}
}
--- /dev/null
+package eu.svjatoslav.meviz.htmlindexer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class IndexingContext {
+
+ private final String localUrl;
+ private final String globalUrl;
+
+ public IndexingContext(final String globalUrl, final String localUrl) {
+ this.globalUrl = globalUrl;
+ this.localUrl = localUrl;
+ }
+
+ public String getGlobalUrl() {
+ return globalUrl;
+ }
+
+ public List<String> getLocalPathComponents() {
+
+ final List<String> result = new ArrayList<String>();
+
+ final String[] strings = localUrl.split("/");
+
+ for (final String pathElement : strings)
+ if (pathElement.length() > 0)
+ result.add(pathElement);
+
+ return result;
+ }
+
+ public String getLocalUrl() {
+ return localUrl;
+ }
+
+}
package eu.svjatoslav.meviz.htmlindexer;
import java.io.UnsupportedEncodingException;
+import java.util.List;
import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.AbstractFile;
/**
* Initialize layout for particular directory.
*/
- public void init(String galleryTitle, String[] path,
- final AbstractIndexer indexer, final String pathPrefix);
+ public void init(String galleryTitle, List<String> path,
+ final AbstractIndexer indexer, IndexingContext context);
}
package eu.svjatoslav.meviz.htmlindexer;
+import java.util.ArrayList;
+
import eu.svjatoslav.meviz.Module;
public class Main implements Module {
}
new FilesystemIndexer(indexingOptions.workingDirectory,
- indexingOptions, new String[] {});
+ indexingOptions, new ArrayList<String>());
}
import java.io.ObjectInputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.List;
import eu.svjatoslav.commons.network.UrlParamEncoder;
import eu.svjatoslav.meviz.htmlindexer.layouts.MixedLayout;
public class WebIndexer extends AbstractIndexer {
- private final String localPrefix;
private final String globalPrefix;
- public WebIndexer(final String globalPrefix, final String localPrefix) {
+ public WebIndexer(final String globalPrefix) {
this.globalPrefix = globalPrefix;
- this.localPrefix = localPrefix;
}
@Override
- public String getDirectoryUrl(final AbstractFile directory) {
- return "photos.jsp?path=/" + UrlParamEncoder.encode(directory.fileName);
+ public String getDirectoryUrl(final AbstractFile directory,
+ final IndexingContext context) {
+ return "photos.jsp?path=" + context.getLocalUrl() + "/"
+ + UrlParamEncoder.encode(directory.fileName);
}
- public String getHtml(final String requestPath)
- throws MalformedURLException, IOException, ClassNotFoundException {
+ public String getHtml(String requestPath) throws MalformedURLException,
+ IOException, ClassNotFoundException {
+
+ if (requestPath.equals("/"))
+ requestPath = "";
final MixedLayout layout = new MixedLayout();
- layout.init("Photos", new String[] {}, this, localPrefix + requestPath);
+ final IndexingContext context = new IndexingContext(globalPrefix,
+ requestPath);
+ layout.init("Photos", context.getLocalPathComponents(), this, context);
final DirectoryMetadata metadata = getMetadataForPath(requestPath);
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");
+ urlStringBuffer.append("/.thumbnails/metadata_6.dat");
final String urlString = urlStringBuffer.toString();
}
@Override
- public String getThumbnailPath(final Picture picture,
- final Dimension desiredDimension) {
+ public String getParentDirectoryUrl(final IndexingContext context) {
+ final StringBuffer result = new StringBuffer();
+
+ result.append("photos.jsp?path=");
+
+ final List<String> components = context.getLocalPathComponents();
+
+ for (final String pathComponent : components.subList(0,
+ components.size() - 1)) {
+ result.append("/");
+ result.append(pathComponent);
+ }
+
+ return result.toString();
+ }
+
+ @Override
+ public String getThumbnailUrl(final Picture picture,
+ final Dimension desiredDimension, final IndexingContext context) {
// in case thumbnail size was equal to original, then return original
// file path
if (picture.getDimensions().equals(desiredDimension))
- return localPrefix + picture.fileName;
+ return context.getGlobalUrl() + context.getLocalUrl() + "/"
+ + picture.fileName;
final String thumbnailFileName = picture
.getRelativeThumbnailFileName(desiredDimension);
- return localPrefix + "/" + Constants.THUMBNAILS_DIRECTORY_NAME + "/"
- + thumbnailFileName;
+ return context.getGlobalUrl() + context.getLocalUrl() + "/"
+ + Constants.THUMBNAILS_DIRECTORY_NAME + "/"
+ + UrlParamEncoder.encode(thumbnailFileName);
}
}
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;
String galleryTitle;
- String[] path;
+ List<String> path;
public static final String encoding = "UTF-8";
private AbstractIndexer indexer;
- private String pathPrefix;
+ private IndexingContext indexingContext;
public void columnAdded() {
currentColumn++;
@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)
+ "\"> ==> " + directory.fileName + "</a></b></TD>");
dirHtml.append("</TR>\n");
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(" ("
+ FilePathParser.getFileSizeDescription(file.getFileLength())
+ ")</TD>\n");
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
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>");
}
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");
.getFileNameWithoutExtension(file.fileName)
+ "<b/> ");
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");
// 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\"> <== ..</a></b></TD>");
+ finalHtml.append("<TD><b><a href=\""
+ + indexer.getParentDirectoryUrl(indexingContext)
+ + "\"> <== ..</a></b></TD>");
finalHtml.append("</TR>\n");
}
}
@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();