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
pull/1/head
orbiter 15 years ago
parent c09a995930
commit c4bdb1e7f2

@ -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;
}
}

@ -39,7 +39,8 @@
<dt><label for="viewMode">View as</label>:</dt>
<dd>
<select id="viewMode" name="viewMode">
<option value="iframe"#(vMode-iframe)#:: selected="selected"#(/vMode-iframe)#>Original</option>
<option value="iframeWeb"#(vMode-iframeWeb)#:: selected="selected"#(/vMode-iframeWeb)#>Original from Web</option>
<option value="iframeCache"#(vMode-iframeCache)#:: selected="selected"#(/vMode-iframeCache)#>Original from Cache</option>
<option value="plain"#(vMode-plain)#:: selected="selected"#(/vMode-plain)#>Plain Text</option>
<option value="parsed"#(vMode-parsed)#:: selected="selected"#(/vMode-parsed)#>Parsed Text</option>
<option value="sentences"#(vMode-sentences)#:: selected="selected"#(/vMode-sentences)#>Parsed Sentences</option>
@ -73,7 +74,7 @@
<p>
#(viewMode)#
:: <!-- 1 -->
<fieldset><legend>Plain Content</legend>
<fieldset><legend>Original Content from Web</legend>
<p class="tt">
#[plainText]#
</p>
@ -91,10 +92,14 @@
</ol>
</fieldset>
:: <!-- 4 -->
<fieldset><legend>Original Content</legend>
<fieldset><legend>Original from Web</legend>
<iframe src="#[url]#" width="800" height="400" />
</fieldset>
:: <!-- 5 -->
<fieldset><legend>Original from Cache</legend>
<iframe src="/CacheResource_p.html?url=#[url]#" width="800" height="400" />
</fieldset>
:: <!-- 6 -->
<h3>Link List</h3><br>
<table border="0" cellpadding="2" cellspacing="1">
#{links}#
@ -106,7 +111,7 @@
<td class="tt">#[attr]#</tt></td>
</tr>#{/links}#
</table>
:: <!-- 6 -->
:: <!-- 7 -->
<fieldset><legend>Parsed Tokens</legend>
<ol>#{words}#
<li class="tt">#[word]#</li>#{/words}#

@ -62,9 +62,10 @@ public class ViewFile {
public static final int VIEW_MODE_AS_PLAIN_TEXT = 1;
public static final int VIEW_MODE_AS_PARSED_TEXT = 2;
public static final int VIEW_MODE_AS_PARSED_SENTENCES = 3;
public static final int VIEW_MODE_AS_IFRAME = 4;
public static final int VIEW_MODE_AS_LINKLIST = 5;
public static final int VIEW_MODE_AS_PARSED_WORDS = 6;
public static final int VIEW_MODE_AS_IFRAME_FROM_WEB = 4;
public static final int VIEW_MODE_AS_IFRAME_FROM_CACHE = 5;
public static final int VIEW_MODE_AS_LINKLIST = 6;
public static final int VIEW_MODE_AS_PARSED_WORDS = 7;
private static final String HIGHLIGHT_CSS = "searchHighlight";
private static final int MAX_HIGHLIGHTS = 6;
@ -259,8 +260,12 @@ public class ViewFile {
prop.put("viewMode", VIEW_MODE_AS_PLAIN_TEXT);
prop.put("viewMode_plainText", markup(wordArray, content).replaceAll("\n", "<br />").replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;"));
} else if (viewMode.equals("iframe")) {
prop.put("viewMode", VIEW_MODE_AS_IFRAME);
} else if (viewMode.equals("iframeWeb")) {
prop.put("viewMode", VIEW_MODE_AS_IFRAME_FROM_WEB);
prop.put("viewMode_url", url.toNormalform(false, true));
} else if (viewMode.equals("iframeCache")) {
prop.put("viewMode", VIEW_MODE_AS_IFRAME_FROM_CACHE);
prop.put("viewMode_url", url.toNormalform(false, true));
} else if (viewMode.equals("parsed") || viewMode.equals("sentences") || viewMode.equals("words") || viewMode.equals("links")) {

@ -182,22 +182,6 @@ public final class Cache {
return new ResponseHeader(null, hdb);
}
/**
* Returns the content of a cached resource as {@link InputStream}
* @param url the requested resource
* @return the resource content as {@link InputStream}. In no data
* is available or the cached file is not readable, <code>null</code>
* is returned.
* @throws IOException
*/
/*
public static InputStream getContentStream(final DigestURI url) throws IOException {
// load the url as resource from the cache
byte[] b = getContent(url);
if (b == null) return null;
return new ByteArrayInputStream(b);
}
*/
/**
* Returns the content of a cached resource as byte[]
@ -217,33 +201,6 @@ public final class Cache {
}
}
/**
* requesting the content length of a resource is discouraged since it may
* be performed by loading of the resource from the cache and then measuring the
* size after decompression of the content. This may use a lot of CPU resources
* and maybe cause also high IO. Please omit usage of this method as much as possible.
* @param url
* @return the size of the cached content
*/
/*
public static long getResourceContentLength(final DigestURI url) {
// first try to get the length from the response header,
// this is less costly than loading the content from its gzipped cache
ResponseHeader responseHeader = getResponseHeader(url);
if (responseHeader != null) {
long length = responseHeader.getContentLength();
if (length > 0) return length;
}
// load the url as resource from the cache (possibly decompress it),
// and get the length from the content array size
try {
return fileDB.length(url.hash().getBytes("UTF-8"));
} catch (IOException e) {
Log.logException(e);
return -1;
}
}
*/
/**
* removed response header and cached content from the database

@ -334,6 +334,9 @@ public final class LoaderDispatcher {
} else {
resContent = Cache.getContent(url);
}
// read a fresh header
responseHeader = entry.getResponseHeader();
}
// if it is still not available, report an error

Loading…
Cancel
Save