Added basic styling for cleaner rendering of missing image snapshots

For the output of the Solr snapshots writer
pull/250/head
luccioman 6 years ago
parent 746e0e788d
commit 8852c97cee

@ -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;

@ -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<Object, Object> 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("<!DOCTYPE html>\n");
writer.write("<html lang=\"en\">");
writer.write("<head>\n");
writer.write("<meta charset=\"UTF-8\">");
writer.write("<title>Documents snapshots</title>\n");
writer.write("<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"" + rootPath + "env/base.css\" />\n");
writer.write("<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"" + rootPath + "env/style.css\" />\n");
writer.write("</head>\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("<body>\n");
writeHtmlHead(writer, request);
writer.write("<body id=\"SnapshotImagesReponseWriter\">\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("<a href=\"");
writer.write(url);
writer.write("\"><img src=\"/api/snapshot.jpg?urlhash=");
writer.write("\" class=\"forceNoExternalIcon\"><img width=\"");
writer.write(String.valueOf(width));
writer.write("\" height=\"");
writer.write(String.valueOf(height));
writer.write("\" src=\"/api/snapshot.jpg?urlhash=");
writer.write(urlhash);
writer.write("&amp;width=");
writer.write(String.valueOf(width));
writer.write("&amp;height=");
writer.write(String.valueOf(heigth));
writer.write(String.valueOf(height));
writer.write("\" alt=\"");
writer.write(url);
writer.write("\"></a>\n");

Loading…
Cancel
Save