diff --git a/htroot/env/base.css b/htroot/env/base.css index 71c481513..08e0759d9 100644 --- a/htroot/env/base.css +++ b/htroot/env/base.css @@ -906,6 +906,14 @@ div.BlogCommentPrevNext { text-align: center; } +/* SnapshotImagesReponseWriter.java */ +body#SnapshotImagesReponseWriter img { + word-break: break-all; /* prevent snapshot image alternate text (original URL) to overflow over image width */ + overflow: hidden; /* prevent snapshot image alternate text (original URL) to overflow over image height */ + display: inline-block; /* constant width and heigth even for snapshot image in error */ + background-color: #eeeeee; /* light background colour to distinguish snapshots images in error */ +} + /* other ------------------------------------*/ ul#menu { padding:0; diff --git a/source/net/yacy/cora/federate/solr/responsewriter/SnapshotImagesReponseWriter.java b/source/net/yacy/cora/federate/solr/responsewriter/SnapshotImagesReponseWriter.java index ed497a600..46f65ccb1 100644 --- a/source/net/yacy/cora/federate/solr/responsewriter/SnapshotImagesReponseWriter.java +++ b/source/net/yacy/cora/federate/solr/responsewriter/SnapshotImagesReponseWriter.java @@ -3,6 +3,7 @@ package net.yacy.cora.federate.solr.responsewriter; import java.io.IOException; import java.io.Writer; import java.util.HashSet; +import java.util.Map; import java.util.Set; import org.apache.lucene.document.Document; @@ -16,6 +17,7 @@ import org.apache.solr.search.DocIterator; import org.apache.solr.search.DocList; import org.apache.solr.search.SolrIndexSearcher; +import net.yacy.cora.util.CommonPattern; import net.yacy.search.schema.CollectionSchema; /** @@ -49,17 +51,58 @@ public class SnapshotImagesReponseWriter implements QueryResponseWriter, Embedde public void init(@SuppressWarnings("rawtypes") NamedList n) { } + /** + * Compute the root path as a relative URL prefix from the original servlet + * request URI if provided in the Solr request context, otherwise return a + * regular "/". Using relative URLs when possible makes deployment behind a + * reverse proxy more reliable and convenient as no URL rewriting is needed. + * + * @param request the Solr request. + * @return the root context path to use as a prefix for resources URLs such as + * stylesheets + */ + private String getRootPath(final SolrQueryRequest request) { + String rootPath = "/"; + if (request != null) { + final Map context = request.getContext(); + if (context != null) { + final Object requestUriObj = context.get("requestURI"); + if (requestUriObj instanceof String) { + String servletRequestUri = (String) requestUriObj; + if (servletRequestUri.startsWith("/")) { + servletRequestUri = servletRequestUri.substring(1); + + final String[] pathParts = CommonPattern.SLASH.split(servletRequestUri); + if (pathParts.length > 1) { + final StringBuilder sb = new StringBuilder(); + for (int i = 1; i < pathParts.length; i++) { + sb.append("../"); + } + rootPath = sb.toString(); + } + } + } + } + } + return rootPath; + } + /** * Append the response HTML head to the writer. * @param writer an open output writer. Must not be null. + * @param request the Solr request * @throws IOException when a write error occurred */ - private void writeHtmlHead(final Writer writer) throws IOException { + private void writeHtmlHead(final Writer writer, final SolrQueryRequest request) throws IOException { + final String rootPath = getRootPath(request); + writer.write("\n"); writer.write(""); writer.write("\n"); writer.write(""); writer.write("Documents snapshots\n"); + writer.write("\n"); + writer.write("\n"); writer.write("\n"); } @@ -69,12 +112,12 @@ public class SnapshotImagesReponseWriter implements QueryResponseWriter, Embedde assert values.get("responseHeader") != null; assert values.get("response") != null; - writeHtmlHead(writer); - writer.write("\n"); + writeHtmlHead(writer, request); + writer.write("\n"); final SolrParams originalParams = request.getOriginalParams(); final int width = originalParams.getInt("width", DEFAULT_WIDTH); - final int heigth = originalParams.getInt("height", DEFAULT_HEIGTH); + final int height = originalParams.getInt("height", DEFAULT_HEIGTH); DocList response = ((ResultContext) values.get("response")).getDocList(); final int sz = response.size(); @@ -88,12 +131,16 @@ public class SnapshotImagesReponseWriter implements QueryResponseWriter, Embedde String url = doc.getField(CollectionSchema.sku.getSolrFieldName()).stringValue(); writer.write("\"");\n");