public class WebIndexer extends AbstractIndexer {
+ private static final int METADATA_LOAD_TRY_COUNT = 10;
private final String globalPrefix;
+ private final String jspPath;
- public WebIndexer(final String globalPrefix) {
+ public WebIndexer(final String globalPrefix, final String jspPath) {
this.globalPrefix = globalPrefix;
+ this.jspPath = jspPath;
}
@Override
public String getDirectoryUrl(final AbstractFile directory,
final IndexingContext context) {
- return "photos.jsp?path=" + context.getLocalUrl() + "/"
+ return jspPath + context.getLocalUrl() + "/"
+ UrlParamEncoder.encode(directory.fileName);
}
public String getHtml(String requestPath) throws MalformedURLException,
- IOException, ClassNotFoundException {
+ IOException, ClassNotFoundException {
+
+ if (requestPath == null)
+ requestPath = "";
if (requestPath.equals("/"))
requestPath = "";
requestPath);
layout.init("Photos", context.getLocalPathComponents(), this, context);
- final DirectoryMetadata metadata = getMetadataForPath(requestPath);
+ final DirectoryMetadata directory = getMetadataForPath(requestPath);
- compileHtml(layout, metadata);
+ compileHtml(layout, directory);
- return layout.getHtml(false, false);
+ return layout.getHtml(false, false, directory);
}
public DirectoryMetadata getMetadataForPath(final String requestPath)
- throws IOException, MalformedURLException, ClassNotFoundException {
+ throws ClassNotFoundException, IOException {
final StringBuffer urlStringBuffer = new StringBuffer();
final String urlString = urlStringBuffer.toString();
- final BufferedInputStream in = new BufferedInputStream(new URL(
- urlString).openStream());
+ IOException exception = null;
+
+ for (int i = 0; i < METADATA_LOAD_TRY_COUNT; i++)
+ try {
+
+ final BufferedInputStream in = new BufferedInputStream(new URL(
+ urlString).openStream());
+
+ final ObjectInputStream oin = new ObjectInputStream(in);
+ final DirectoryMetadata directory = (DirectoryMetadata) oin
+ .readObject();
+ in.close();
- final ObjectInputStream oin = new ObjectInputStream(in);
- final DirectoryMetadata directory = (DirectoryMetadata) oin
- .readObject();
- in.close();
+ return directory;
+ } catch (final IOException e) {
+ exception = e;
+ }
- return directory;
+ throw exception;
}
@Override
public String getParentDirectoryUrl(final IndexingContext context) {
final StringBuffer result = new StringBuffer();
- result.append("photos.jsp?path=");
+ result.append(jspPath);
final List<String> components = context.getLocalPathComponents();
// file path
if (picture.getDimensions().equals(desiredDimension))
return context.getGlobalUrl() + context.getLocalUrl() + "/"
- + picture.fileName;
+ + picture.fileName;
final String thumbnailFileName = picture
.getRelativeThumbnailFileName(desiredDimension);
return context.getGlobalUrl() + context.getLocalUrl() + "/"
- + Constants.THUMBNAILS_DIRECTORY_NAME + "/"
- + UrlParamEncoder.encode(thumbnailFileName);
+ + Constants.THUMBNAILS_DIRECTORY_NAME + "/"
+ + UrlParamEncoder.encode(thumbnailFileName);
}
}