From c4bdb1e7f2bb0fcc5c32443ac7f847a81e03100a Mon Sep 17 00:00:00 2001 From: orbiter Date: Sat, 6 Mar 2010 23:41:51 +0000 Subject: [PATCH] added one more option in ViewFile to show an iframe like for the orginal web page content but using the cache than the direct link to the content in the web. Upgraded the very old and previously not any more used CacheResource_p servlet to a new and working version. git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6719 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/CacheResource_p.java | 50 +++++++++++-------- htroot/ViewFile.html | 13 +++-- htroot/ViewFile.java | 15 ++++-- source/de/anomic/http/client/Cache.java | 43 ---------------- .../net/yacy/repository/LoaderDispatcher.java | 3 ++ 5 files changed, 50 insertions(+), 74 deletions(-) diff --git a/htroot/CacheResource_p.java b/htroot/CacheResource_p.java index ca15ecc7f..45f9e22e4 100644 --- a/htroot/CacheResource_p.java +++ b/htroot/CacheResource_p.java @@ -1,6 +1,5 @@ // CacheResource_p.java // ----------------------- -// part of the AnomicHTTPD caching proxy // (C) by Michael Peter Christen; mc@yacy.net // first published on http://www.anomic.de // Frankfurt, Germany, 2004 @@ -23,41 +22,48 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// You must compile this file with -// javac -classpath .:../classes CacheResource_p.java -// if the shell's current path is HTROOT -import java.io.File; import java.io.IOException; +import java.net.MalformedURLException; -import net.yacy.kelondro.util.FileUtils; +import net.yacy.kelondro.data.meta.DigestURI; +import net.yacy.kelondro.logging.Log; +import de.anomic.http.client.Cache; import de.anomic.http.server.RequestHeader; -import de.anomic.search.Switchboard; -import de.anomic.search.SwitchboardConstants; import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch; public class CacheResource_p { public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { - final Switchboard switchboard = (Switchboard) env; final serverObjects prop = new serverObjects(); - - final String path = ((post == null) ? "" : post.get("path", "")); - - // we dont need check the path, because we have do that in plasmaSwitchboard.java - Borg-0300 - final File cache = switchboard.getConfigPath(SwitchboardConstants.HTCACHE_PATH, SwitchboardConstants.HTCACHE_PATH_DEFAULT); - - final File f = new File(cache, path); - byte[] resource; - + prop.put("resource", new byte[0]); + + if (post == null) return prop; + + final String u = post.get("url", ""); + DigestURI url; + try { + url = new DigestURI(u, null); + } catch (MalformedURLException e) { + Log.logException(e); + return prop; + } + + byte[] resource = null; + // trying to load the resource body try { - resource = FileUtils.read(f); - prop.put("resource", resource); - } catch (final IOException e) { - prop.put("resource", new byte[0]); + resource = Cache.getContent(url); + } catch (IOException e) { + Log.logException(e); + return prop; } + if (resource == null) return prop; + //ResponseHeader responseHeader = Cache.getResponseHeader(url); + //String resMime = responseHeader.mime(); + + prop.put("resource", resource); return prop; } } diff --git a/htroot/ViewFile.html b/htroot/ViewFile.html index bebcf7b0f..015b87f98 100644 --- a/htroot/ViewFile.html +++ b/htroot/ViewFile.html @@ -39,7 +39,8 @@
: