From f1b712c29a9461e5c5591ed35462008797ac3d9c Mon Sep 17 00:00:00 2001 From: orbiter Date: Fri, 6 Mar 2009 15:39:02 +0000 Subject: [PATCH] small corrections to image loading methods in result presentation especially loading of favicons in search results. This is a fix that affects only searches in intranet/repository configurations. git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5670 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/ViewImage.java | 16 +++++++++++----- htroot/yacysearchitem.html | 2 +- htroot/yacysearchitem.java | 4 ++-- httpd.mime | 2 ++ source/de/anomic/data/URLLicense.java | 1 + 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/htroot/ViewImage.java b/htroot/ViewImage.java index 3fc7f3e0c..82efbfc1f 100644 --- a/htroot/ViewImage.java +++ b/htroot/ViewImage.java @@ -43,6 +43,13 @@ public class ViewImage { private static HashMap iconcache = new HashMap(); private static String defaulticon = "htroot/env/grafics/dfltfvcn.ico"; + private static byte[] defaulticonb; + static { + try { + defaulticonb = FileUtils.read(new File(defaulticon)); + } catch (final IOException e) { + } + } public static Image respond(final httpRequestHeader header, final serverObjects post, final serverSwitch env) { @@ -68,9 +75,6 @@ public class ViewImage { urlString = (url == null) ? null : url.toNormalform(true, true); } - if (url == null) return null; - System.out.println("loading image from " + url.toString()); - int width = post.getInt("width", 0); int height = post.getInt("height", 0); int maxwidth = post.getInt("maxwidth", 0); @@ -81,7 +85,7 @@ public class ViewImage { Image scaled = iconcache.get(urlString); if (scaled == null) { Object[] resource = null; - try { + if (url != null) try { resource = plasmaSnippetCache.getResource(url, true, timeout, false, true); } catch (IOException e) { Log.logWarning("ViewImage", "cannot load: " + e.getMessage()); @@ -90,10 +94,12 @@ public class ViewImage { if (resource == null) { if (urlString.endsWith(".ico")) { // load default favicon dfltfvcn.ico - try { + if (defaulticonb == null) try { imgb = FileUtils.read(new File(sb.getRootPath(), defaulticon)); } catch (final IOException e) { return null; + } else { + imgb = defaulticonb; } } else { return null; diff --git a/htroot/yacysearchitem.html b/htroot/yacysearchitem.html index b51776512..686dcb237 100644 --- a/htroot/yacysearchitem.html +++ b/htroot/yacysearchitem.html @@ -1,7 +1,7 @@ #(content)#::

- favicon + #[title]#

#(authorized)#::
diff --git a/htroot/yacysearchitem.java b/htroot/yacysearchitem.java index 1722b7b18..6d850f6fb 100644 --- a/htroot/yacysearchitem.java +++ b/htroot/yacysearchitem.java @@ -98,8 +98,8 @@ public class yacysearchitem { final int port=result.url().getPort(); - yacyURL faviconURL; - try { + yacyURL faviconURL = null; + if (!result.url().isLocal()) try { faviconURL = new yacyURL(result.url().getProtocol() + "://" + result.url().getHost() + ((port != -1) ? (":" + String.valueOf(port)) : "") + "/favicon.ico", null); } catch (final MalformedURLException e1) { faviconURL = null; diff --git a/httpd.mime b/httpd.mime index 418397409..e36d09c76 100644 --- a/httpd.mime +++ b/httpd.mime @@ -10,6 +10,7 @@ au = audio/basic avi = video/x-msvideo bat = text/plain bin = application/octet-stream +bmp = image/bmp bz2 = application/x-bzip2 class = application/octet-stream c = text/plain @@ -29,6 +30,7 @@ gz = application/gzip hqx = application/mac-binhex40 htm = text/html html = text/html +ico = image/bmp jar = application/java-archive java = text/plain jpe = image/jpeg diff --git a/source/de/anomic/data/URLLicense.java b/source/de/anomic/data/URLLicense.java index f28c620eb..54bdc60e3 100644 --- a/source/de/anomic/data/URLLicense.java +++ b/source/de/anomic/data/URLLicense.java @@ -56,6 +56,7 @@ public class URLLicense { public String aquireLicense(final yacyURL url) { // generate license key String license = ""; + if (url == null) return license; while (license.length() < keylen) license += Integer.toHexString(random.nextInt()); license = license.substring(0, keylen); // store reference to url with license key