quick fix: go back to display search results favicon via <img> tag and ViewImage,

! until better solution is found !.

Reason: in IE-Browser no individual favicon is displayed with <object> tag 
(always the default) and only few individual fav's with Firefox (randomly)

hint: to be able to use <img src=ViewImage/> return of default icon was
added back to it.

relates to http://mantis.tokeek.de/view.php?id=629
pull/37/head
reger 9 years ago
parent d5fd031449
commit 67f64af4b4

@ -30,6 +30,7 @@ import java.awt.Rectangle;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.image.Raster; import java.awt.image.Raster;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Iterator; import java.util.Iterator;
@ -49,6 +50,7 @@ import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.storage.ConcurrentARC; import net.yacy.cora.storage.ConcurrentARC;
import net.yacy.cora.util.ConcurrentLog; import net.yacy.cora.util.ConcurrentLog;
import net.yacy.data.URLLicense; import net.yacy.data.URLLicense;
import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.util.MemoryControl; import net.yacy.kelondro.util.MemoryControl;
import net.yacy.kelondro.workflow.WorkflowProcessor; import net.yacy.kelondro.workflow.WorkflowProcessor;
import net.yacy.peers.graphics.EncodedImage; import net.yacy.peers.graphics.EncodedImage;
@ -60,8 +62,11 @@ import net.yacy.server.serverSwitch;
public class ViewImage { public class ViewImage {
private static Map<String, Image> iconcache = new ConcurrentARC<String, Image>(1000, private static Map<String, Image> iconcache = new ConcurrentARC<String, Image>(1000,
Math.max(10, Math.min(32, WorkflowProcessor.availableCPU * 2))); 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. * Try parsing image from post "url" parameter or from "code" parameter.
@ -132,7 +137,7 @@ public class ViewImage {
ImageInputStream imageInStream = null; ImageInputStream imageInStream = null;
InputStream inStream = null; InputStream inStream = null;
try { try {
String urlExt = MultiProtocolURL.getFileExtension(url.getFileName()); String urlExt = MultiProtocolURL.getFileExtension(url.getFileName());
if (ext != null && ext.equalsIgnoreCase(urlExt) && isBrowserRendered(urlExt)) { if (ext != null && ext.equalsIgnoreCase(urlExt) && isBrowserRendered(urlExt)) {
return openInputStream(post, sb.loader, auth, url); return openInputStream(post, sb.loader, auth, url);
} }
@ -149,10 +154,23 @@ public class ViewImage {
// read image // read image
encodedImage = parseAndScale(post, auth, urlString, ext, imageInStream); encodedImage = parseAndScale(post, auth, urlString, ext, imageInStream);
} catch(Exception e) { } catch(Exception e) {
/* Exceptions are not propagated here : many error causes are possible, network errors, /* Exceptions are not propagated here : many error causes are possible, network errors,
* incorrect or unsupported format, bad ImageIO plugin... * incorrect or unsupported format, bad ImageIO plugin...
* Instead return an empty EncodedImage. Caller is responsible for handling this correctly (500 status code response) */ * 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"));
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 { } finally {
/* /*
* imageInStream.close() method doesn't close source input * imageInStream.close() method doesn't close source input

@ -1,9 +1,7 @@
#(content)#:: #(content)#::
<div class="searchresults"> <div class="searchresults">
<h4 class="linktitle"> <h4 class="linktitle">
<object data="ViewImage.png?width=16&amp;height=16&amp;code=#[faviconCode]#&amp;isStatic=true" type="image/png" id="f#[urlhash]#" class="favicon" style="width:16px; height:16px;"> <img width="16" height="16" src="ViewImage.png?width=16&amp;height=16&amp;code=#[faviconCode]#&amp;isStatic=true" id="f#[urlhash]#" class="favicon" style="width:16px; height:16px;" alt="" />
<img width="16" height="16" src="env/grafics/dfltfvcn.ico" style="width:16px; height:16px;" alt="" />
</object>
<a href="#[link]#" target="#[target]#">#[title]#</a></h4> <a href="#[link]#" target="#[target]#">#[title]#</a></h4>
<div class="urlactions"> <div class="urlactions">
#(heuristic)#:: #(heuristic)#::
@ -38,6 +36,7 @@
#(showHostBrowser)#::&nbsp;|&nbsp;<a href="HostBrowser.html?path=#[link]#"><img src="env/grafics/minitree.png" width="15" height="8"/></a>#(/showHostBrowser)# #(showHostBrowser)#::&nbsp;|&nbsp;<a href="HostBrowser.html?path=#[link]#"><img src="env/grafics/minitree.png" width="15" height="8"/></a>#(/showHostBrowser)#
#(showVocabulary)#::<br/>#{vocabulary}##[name]#:#[terms]# #{/vocabulary}##(/showVocabulary)# #(showVocabulary)#::<br/>#{vocabulary}##[name]#:#[terms]# #{/vocabulary}##(/showVocabulary)#
#(showSnapshots)#::<a href="#[link]#">Snapshots</a>#(/showSnapshots)# #(showSnapshots)#::<a href="#[link]#">Snapshots</a>#(/showSnapshots)#
#[ranking]#
</p> </p>
</div> </div>
:: ::

Loading…
Cancel
Save