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;
9 import eu.svjatoslav.commons.network.UrlParamEncoder;
10 import eu.svjatoslav.meviz.htmlindexer.layouts.MixedLayout;
11 import eu.svjatoslav.meviz.htmlindexer.metadata.Dimension;
12 import eu.svjatoslav.meviz.htmlindexer.metadata.DirectoryMetadata;
13 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.AbstractFile;
14 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Picture;
16 public class WebIndexer extends AbstractIndexer {
18 private final String localPrefix;
19 private final String globalPrefix;
21 public WebIndexer(final String globalPrefix, final String localPrefix) {
22 this.globalPrefix = globalPrefix;
23 this.localPrefix = localPrefix;
27 public String getDirectoryUrl(final AbstractFile directory) {
28 return "photos.jsp?path=/" + UrlParamEncoder.encode(directory.fileName);
31 public String getHtml(final String requestPath)
32 throws MalformedURLException, IOException, ClassNotFoundException {
34 final MixedLayout layout = new MixedLayout();
35 layout.init("Photos", new String[] {}, this, localPrefix + requestPath);
37 final DirectoryMetadata metadata = getMetadataForPath(requestPath);
39 compileHtml(layout, metadata);
41 return layout.getHtml();
44 public DirectoryMetadata getMetadataForPath(final String requestPath)
45 throws IOException, MalformedURLException, ClassNotFoundException {
47 final StringBuffer urlStringBuffer = new StringBuffer();
49 urlStringBuffer.append(globalPrefix);
50 urlStringBuffer.append(UrlParamEncoder.encode(localPrefix));
51 urlStringBuffer.append(UrlParamEncoder.encode(requestPath));
52 if (!requestPath.equals("/"))
53 urlStringBuffer.append("/");
54 urlStringBuffer.append(".thumbnails/metadata_6.dat");
56 final String urlString = urlStringBuffer.toString();
58 final BufferedInputStream in = new BufferedInputStream(new URL(
59 urlString).openStream());
61 final ObjectInputStream oin = new ObjectInputStream(in);
62 final DirectoryMetadata directory = (DirectoryMetadata) oin
70 public String getThumbnailPath(final Picture picture,
71 final Dimension desiredDimension) {
73 // in case thumbnail size was equal to original, then return original
75 if (picture.getDimensions().equals(desiredDimension))
76 return localPrefix + picture.fileName;
78 final String thumbnailFileName = picture
79 .getRelativeThumbnailFileName(desiredDimension);
81 return localPrefix + "/" + Constants.THUMBNAILS_DIRECTORY_NAME + "/"