From 67f64af4b4fde9c16f4726c1554660f9d1df4a03 Mon Sep 17 00:00:00 2001 From: reger Date: Mon, 21 Dec 2015 01:05:59 +0100 Subject: [PATCH] quick fix: go back to display search results favicon via tag and ViewImage, ! until better solution is found !. Reason: in IE-Browser no individual favicon is displayed with tag (always the default) and only few individual fav's with Firefox (randomly) hint: to be able to use return of default icon was added back to it. relates to http://mantis.tokeek.de/view.php?id=629 --- htroot/ViewImage.java | 32 +++++++++++++++++++++++++------- htroot/yacysearchitem.html | 5 ++--- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/htroot/ViewImage.java b/htroot/ViewImage.java index 249c09432..cf95f6200 100644 --- a/htroot/ViewImage.java +++ b/htroot/ViewImage.java @@ -30,6 +30,7 @@ import java.awt.Rectangle; import java.awt.image.BufferedImage; import java.awt.image.Raster; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.Iterator; @@ -49,6 +50,7 @@ import net.yacy.cora.protocol.RequestHeader; import net.yacy.cora.storage.ConcurrentARC; import net.yacy.cora.util.ConcurrentLog; import net.yacy.data.URLLicense; +import net.yacy.kelondro.util.FileUtils; import net.yacy.kelondro.util.MemoryControl; import net.yacy.kelondro.workflow.WorkflowProcessor; import net.yacy.peers.graphics.EncodedImage; @@ -60,8 +62,11 @@ import net.yacy.server.serverSwitch; public class ViewImage { - private static Map iconcache = new ConcurrentARC(1000, - Math.max(10, Math.min(32, WorkflowProcessor.availableCPU * 2))); + private static Map iconcache = new ConcurrentARC(1000, + Math.max(10, Math.min(32, WorkflowProcessor.availableCPU * 2))); + + private static String defaulticon = "htroot/env/grafics/dfltfvcn.ico"; + private static byte[] defaulticonb = null; /** * Try parsing image from post "url" parameter or from "code" parameter. @@ -132,7 +137,7 @@ public class ViewImage { ImageInputStream imageInStream = null; InputStream inStream = null; try { - String urlExt = MultiProtocolURL.getFileExtension(url.getFileName()); + String urlExt = MultiProtocolURL.getFileExtension(url.getFileName()); if (ext != null && ext.equalsIgnoreCase(urlExt) && isBrowserRendered(urlExt)) { return openInputStream(post, sb.loader, auth, url); } @@ -149,10 +154,23 @@ public class ViewImage { // read image encodedImage = parseAndScale(post, auth, urlString, ext, imageInStream); } catch(Exception e) { - /* Exceptions are not propagated here : many error causes are possible, network errors, - * incorrect or unsupported format, bad ImageIO plugin... - * Instead return an empty EncodedImage. Caller is responsible for handling this correctly (500 status code response) */ - encodedImage = new EncodedImage(new byte[0], ext, post.getBoolean("isStatic")); + /* Exceptions are not propagated here : many error causes are possible, network errors, + * incorrect or unsupported format, bad ImageIO plugin... + * Instead return an empty EncodedImage. Caller is responsible for handling this correctly (500 status code response) */ + + if ("favicon.ico".equalsIgnoreCase(url.getFileName())) { // but on missing favicon just present a default (occures frequently by call from searchitem.html) + // currently yacysearchitem assigns "hosturl/favicon.ico" (to look for the filename should not much interfere with other situatios) + if (defaulticonb == null) { // load the default icon once + try { + defaulticonb = FileUtils.read(new File(sb.getAppPath(), defaulticon)); + } catch (final IOException initicon) { + defaulticonb = new byte[0]; + } + } + encodedImage = new EncodedImage(defaulticonb, ext, post.getBoolean("isStatic")); + } else { + encodedImage = new EncodedImage(new byte[0], ext, post.getBoolean("isStatic")); + } } finally { /* * imageInStream.close() method doesn't close source input diff --git a/htroot/yacysearchitem.html b/htroot/yacysearchitem.html index 0a69ff421..da1a4e4fa 100644 --- a/htroot/yacysearchitem.html +++ b/htroot/yacysearchitem.html @@ -1,9 +1,7 @@ #(content)#::

- - - + #[title]#

#(heuristic)#:: @@ -38,6 +36,7 @@ #(showHostBrowser)#:: | #(/showHostBrowser)# #(showVocabulary)#::
#{vocabulary}##[name]#:#[terms]# #{/vocabulary}##(/showVocabulary)# #(showSnapshots)#::Snapshots#(/showSnapshots)# + #[ranking]#

::