import eu.svjatoslav.meviz.htmlindexer.Constants;
import eu.svjatoslav.meviz.htmlindexer.IndexingContext;
import eu.svjatoslav.meviz.htmlindexer.layouts.Layout;
-import eu.svjatoslav.meviz.htmlindexer.Utils;
import eu.svjatoslav.meviz.htmlindexer.layouts.MixedLayout;
import eu.svjatoslav.meviz.htmlindexer.metadata.Dimension;
import eu.svjatoslav.meviz.htmlindexer.metadata.DirectoryMetadata;
import java.net.URL;
import java.util.List;
+import static eu.svjatoslav.meviz.htmlindexer.Constants.METADATA_FILE_NAME;
+import static eu.svjatoslav.meviz.htmlindexer.Utils.urlEncode;
+
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, final String jspPath) {
- this.globalPrefix = globalPrefix;
- this.jspPath = jspPath;
+ /**
+ * Example: "https://www3.svjatoslav.eu/web/photos"
+ */
+ private final String contentServerRootUrl;
+
+ /**
+ * Example: "http://www3.svjatoslav.eu/web/photos"
+ */
+ private String metadataServerRootUrl;
+
+ /**
+ * Path relative to frontend server. For example, if full URL is "http://127.0.0.1:8080/photos"
+ * then relative URL would be "/photos"
+ */
+ private final String frontendServerRelativeRootUrl;
+
+ /**
+ * Example full URL: http://127.0.0.1:8080/photos/Spain
+ *
+ * @param contentServerRootUrl {@link #contentServerRootUrl}
+ * @param frontendServerRelativeRootUrl {@link #frontendServerRelativeRootUrl}
+ */
+ public WebIndexer(
+ final String contentServerRootUrl,
+ final String metadataServerRootUrl,
+ final String frontendServerRelativeRootUrl) {
+ this.contentServerRootUrl = contentServerRootUrl;
+ this.metadataServerRootUrl = metadataServerRootUrl;
+ this.frontendServerRelativeRootUrl = frontendServerRelativeRootUrl;
}
@Override
@Override
public String getDirectoryUrl(final AbstractFile directory,
final IndexingContext context) {
- return jspPath + context.getLocalUrl() + "/" + directory.fileName;
+ return frontendServerRelativeRootUrl + context.getLocalUrl() + "/" + directory.fileName;
}
- public String getHtml(String requestPath) throws
+ /**
+ * @param frontendServerRequestRelativeUrl example: /Spain
+ */
+ public String getHtml(String frontendServerRequestRelativeUrl) throws
IOException, ClassNotFoundException {
- if (requestPath == null)
- requestPath = "";
+ if (frontendServerRequestRelativeUrl == null)
+ frontendServerRequestRelativeUrl = "";
- if (requestPath.equals("/"))
- requestPath = "";
+ if (frontendServerRequestRelativeUrl.equals("/"))
+ frontendServerRequestRelativeUrl = "";
final MixedLayout layout = new MixedLayout();
- final IndexingContext context = new IndexingContext(globalPrefix,
- requestPath);
+
+ final IndexingContext context = new IndexingContext(
+ contentServerRootUrl,
+ frontendServerRequestRelativeUrl);
+
layout.init("Photos", context.getLocalPathComponents(), this, context);
- final DirectoryMetadata directory = getMetadataForPath(requestPath);
+ final DirectoryMetadata directory = getMetadataForPath(frontendServerRequestRelativeUrl);
compileHtml(layout, directory);
private DirectoryMetadata getMetadataForPath(final String requestPath)
throws ClassNotFoundException, IOException {
- final String urlString = globalPrefix + Utils.urlEncode(requestPath) + "/.thumbnails/metadata_6.dat";
+ final String url = metadataServerRootUrl + urlEncode(requestPath) + "/.thumbnails/"+ METADATA_FILE_NAME;
- for (int i = 0; true; i++)
+ for (int attempt = 0; true; attempt++)
try {
- return attemptDirectoryMetadataDownload(urlString);
+ return attemptDirectoryMetadataDownload(url);
} catch (final IOException e) {
- if (i > METADATA_LOAD_TRY_COUNT) throw e;
+ if (attempt > METADATA_LOAD_TRY_COUNT) throw e;
}
}
- private DirectoryMetadata attemptDirectoryMetadataDownload(String urlString) throws IOException, ClassNotFoundException {
- final BufferedInputStream inputStream = new BufferedInputStream(new URL(
- urlString).openStream());
+ private DirectoryMetadata attemptDirectoryMetadataDownload(String urlString)
+ throws IOException, ClassNotFoundException {
+ final BufferedInputStream inputStream = new BufferedInputStream(new URL(urlString).openStream());
final ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
- final DirectoryMetadata directory = (DirectoryMetadata) objectInputStream
- .readObject();
+ final DirectoryMetadata directory = (DirectoryMetadata) objectInputStream.readObject();
inputStream.close();
return directory;
public String getParentDirectoryUrl(final IndexingContext context) {
final StringBuilder result = new StringBuilder();
- result.append(jspPath);
+ result.append(frontendServerRelativeRootUrl);
final List<String> components = context.getLocalPathComponents();
return context.getGlobalUrl() + context.getLocalUrl() + "/"
+ Constants.THUMBNAILS_DIRECTORY_NAME + "/"
- + Utils.urlEncode(thumbnailFileName);
+ + urlEncode(thumbnailFileName);
}
}