1 package eu.svjatoslav.meviz.htmlindexer;
3 import java.io.BufferedInputStream;
4 import java.io.IOException;
5 import java.io.ObjectInputStream;
6 import java.net.MalformedURLException;
10 import eu.svjatoslav.commons.network.UrlParamEncoder;
11 import eu.svjatoslav.meviz.htmlindexer.layouts.MixedLayout;
12 import eu.svjatoslav.meviz.htmlindexer.metadata.Dimension;
13 import eu.svjatoslav.meviz.htmlindexer.metadata.DirectoryMetadata;
14 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.AbstractFile;
15 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Picture;
17 public class WebIndexer extends AbstractIndexer {
19 private final String globalPrefix;
21 public WebIndexer(final String globalPrefix) {
22 this.globalPrefix = globalPrefix;
26 public String getDirectoryUrl(final AbstractFile directory,
27 final IndexingContext context) {
28 return "photos.jsp?path=" + context.getLocalUrl() + "/"
29 + UrlParamEncoder.encode(directory.fileName);
32 public String getHtml(String requestPath) throws MalformedURLException,
33 IOException, ClassNotFoundException {
35 if (requestPath.equals("/"))
38 final MixedLayout layout = new MixedLayout();
39 final IndexingContext context = new IndexingContext(globalPrefix,
41 layout.init("Photos", context.getLocalPathComponents(), this, context);
43 final DirectoryMetadata metadata = getMetadataForPath(requestPath);
45 compileHtml(layout, metadata);
47 return layout.getHtml();
50 public DirectoryMetadata getMetadataForPath(final String requestPath)
51 throws IOException, MalformedURLException, ClassNotFoundException {
53 final StringBuffer urlStringBuffer = new StringBuffer();
55 urlStringBuffer.append(globalPrefix);
56 urlStringBuffer.append(UrlParamEncoder.encode(requestPath));
57 urlStringBuffer.append("/.thumbnails/metadata_6.dat");
59 final String urlString = urlStringBuffer.toString();
61 final BufferedInputStream in = new BufferedInputStream(new URL(
62 urlString).openStream());
64 final ObjectInputStream oin = new ObjectInputStream(in);
65 final DirectoryMetadata directory = (DirectoryMetadata) oin
73 public String getParentDirectoryUrl(final IndexingContext context) {
74 final StringBuffer result = new StringBuffer();
76 result.append("photos.jsp?path=");
78 final List<String> components = context.getLocalPathComponents();
80 for (final String pathComponent : components.subList(0,
81 components.size() - 1)) {
83 result.append(pathComponent);
86 return result.toString();
90 public String getThumbnailUrl(final Picture picture,
91 final Dimension desiredDimension, final IndexingContext context) {
93 // in case thumbnail size was equal to original, then return original
95 if (picture.getDimensions().equals(desiredDimension))
96 return context.getGlobalUrl() + context.getLocalUrl() + "/"
99 final String thumbnailFileName = picture
100 .getRelativeThumbnailFileName(desiredDimension);
102 return context.getGlobalUrl() + context.getLocalUrl() + "/"
103 + Constants.THUMBNAILS_DIRECTORY_NAME + "/"
104 + UrlParamEncoder.encode(thumbnailFileName);