import java.net.MalformedURLException;
import java.net.URL;
+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;
public class WebIndexer extends AbstractIndexer {
- private final MixedLayout layout = new MixedLayout();
private final String localPrefix;
private final String globalPrefix;
@Override
public String getDirectoryUrl(final AbstractFile directory) {
- return "photos.jsp?path=/" + directory.fileName;
+ return "photos.jsp?path=/" + UrlParamEncoder.encode(directory.fileName);
}
- public String getHtml(final String path) throws MalformedURLException,
- IOException, ClassNotFoundException {
+ public String getHtml(final String requestPath)
+ throws MalformedURLException, IOException, ClassNotFoundException {
- layout.init("Photos", new String[] {}, this, localPrefix);
+ final MixedLayout layout = new MixedLayout();
+ layout.init("Photos", new String[] {}, this, localPrefix + requestPath);
- final DirectoryMetadata metadata = getMetadataForPath();
+ final DirectoryMetadata metadata = getMetadataForPath(requestPath);
compileHtml(layout, metadata);
return layout.getHtml();
}
- public DirectoryMetadata getMetadataForPath() throws IOException,
- MalformedURLException, ClassNotFoundException {
+ public DirectoryMetadata getMetadataForPath(final String requestPath)
+ throws IOException, MalformedURLException, ClassNotFoundException {
- final BufferedInputStream in = new BufferedInputStream(
- new URL(globalPrefix + localPrefix
- + ".thumbnails/metadata_6.dat").openStream());
+ 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");
+
+ final String urlString = urlStringBuffer.toString();
+
+ final BufferedInputStream in = new BufferedInputStream(new URL(
+ urlString).openStream());
final ObjectInputStream oin = new ObjectInputStream(in);
final DirectoryMetadata directory = (DirectoryMetadata) oin
final String thumbnailFileName = picture
.getRelativeThumbnailFileName(desiredDimension);
- return localPrefix + Constants.THUMBNAILS_DIRECTORY_NAME + "/"
+ return localPrefix + "/" + Constants.THUMBNAILS_DIRECTORY_NAME + "/"
+ thumbnailFileName;
}