preload videos metadata
[meviz.git] / src / main / java / eu / svjatoslav / meviz / htmlindexer / WebIndexer.java
index d4fd7e3..6530e70 100644 (file)
@@ -16,22 +16,28 @@ 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 {
 
+               if (requestPath == null)
+                       requestPath = "";
+
                if (requestPath.equals("/"))
                        requestPath = "";
 
@@ -48,7 +54,7 @@ public class WebIndexer extends AbstractIndexer {
        }
 
        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();