Skip to content
Permalink
Browse files

Added basic styling for cleaner rendering of missing image snapshots

For the output of the Solr snapshots writer
  • Loading branch information...
luccioman committed Oct 15, 2018
1 parent 746e0e7 commit 8852c97ceef12043d4a48af1a800ba9674ab9a0a
@@ -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 @@
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.DocList;
import org.apache.solr.search.SolrIndexSearcher;

import net.yacy.cora.util.CommonPattern;
import net.yacy.search.schema.CollectionSchema;

/**
@@ -49,17 +51,58 @@ public String getContentType(SolrQueryRequest arg0, SolrQueryResponse arg1) {
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 void write(final Writer writer, final SolrQueryRequest request, final Sol
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 void write(final Writer writer, final SolrQueryRequest request, final Sol
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");

0 comments on commit 8852c97

Please sign in to comment.
You can’t perform that action at this time.