added midi to wav conversion
[meviz.git] / src / main / java / eu / svjatoslav / meviz / htmlindexer / WebIndexer.java
index d4fd7e3..acc1a28 100644 (file)
@@ -16,21 +16,27 @@ import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Picture;
 
 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 = "";
@@ -40,15 +46,15 @@ public class WebIndexer extends AbstractIndexer {
                                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();
 
@@ -58,22 +64,32 @@ public class WebIndexer extends AbstractIndexer {
 
                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();
 
@@ -94,14 +110,14 @@ public class WebIndexer extends AbstractIndexer {
                // 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);
        }
 
 }