From 6de5c46702726f0477d0d9c7d31dbae052908c81 Mon Sep 17 00:00:00 2001 From: borg-0300 Date: Thu, 12 Jan 2006 18:02:54 +0000 Subject: [PATCH] new CacheAdmin (redesign); bugfix: no more '//' in cachelink; bugfix: don't left the htCachePath; git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1318 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/CacheAdmin_p.html | 21 ++--- htroot/CacheAdmin_p.java | 162 +++++++++++++++++++++------------------ htroot/env/style.css | 3 +- 3 files changed, 95 insertions(+), 91 deletions(-) diff --git a/htroot/CacheAdmin_p.html b/htroot/CacheAdmin_p.html index a0489d5d0..4185883c3 100644 --- a/htroot/CacheAdmin_p.html +++ b/htroot/CacheAdmin_p.html @@ -6,21 +6,12 @@ #%env/templates/header.template%# -

-

Local Cache


- -

-The current cache size is #[cachesize]# KB. The maximum cache size is #[cachemax]# KB.
- - - -
-#[tree]# - - -#[info]# -
- + + + + +#(info)#::#(/info)# +

Local Cache

The current cache size is #[cachesize]# KB. The maximum cache size is #[cachemax]# KB.
cache/#[path]#

#[url]#

#[info]#
#[tree]#
#%env/templates/footer.template%# diff --git a/htroot/CacheAdmin_p.java b/htroot/CacheAdmin_p.java index cbaf95ac4..22166fc78 100644 --- a/htroot/CacheAdmin_p.java +++ b/htroot/CacheAdmin_p.java @@ -49,8 +49,6 @@ import java.io.File; import java.io.OutputStream; import java.net.URL; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.Iterator; import java.util.Map; import java.util.TreeSet; @@ -68,85 +66,54 @@ import de.anomic.server.serverSwitch; public class CacheAdmin_p { - private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); - public static String dateString(final Date date) { - return SimpleFormatter.format(date); - } - public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) { final plasmaSwitchboard switchboard = (plasmaSwitchboard) env; final serverObjects prop = new serverObjects(); final String action = ((post == null) ? "info" : post.get("action", "info")); String pathString = ((post == null) ? "" : post.get("path", "/")); - while (pathString.startsWith("//")) { // where is the BUG ? - pathString = pathString.substring(1); - } - final String fileString = pathString; - - File dir; - final File file = new File(switchboard.htCachePath, pathString); - final URL url = plasmaHTCache.getURL(switchboard.htCachePath, file); - - if (file.isDirectory()) { - dir = file; - } else { - dir = file.getParentFile(); - pathString = (new File(pathString)).getParent().replace('\\','/'); - } +// String pathString = ((post == null) ? "" : post.get("path", "/").replaceAll("//", "/")); // where is the BUG ? - // generate sorted dir/file listing - final String[] list = dir.list(); - final StringBuffer tree = new StringBuffer((list == null) ? 70 : (list.length + 2) * 256); - tree.append("Directory of
").append((pathString.length() == 0) ? "domain list" : linkPathString(pathString)).append("

"); - if (list == null) { - tree.append("[empty]"); - } else { - final TreeSet dList = new TreeSet(); - final TreeSet fList = new TreeSet(); - File object; - int size = list.length - 1; - for (int i = size; i >= 0 ; i--) { // Rueckwaerts ist schneller - object = new File(dir, list[i]); - if (!object.getName().equalsIgnoreCase("responseHeader.db")) { - if (object.isDirectory()) { - dList.add(list[i]); - } else { - fList.add(list[i]); - } - } - } - Iterator iter = dList.iterator(); - String str; - while (iter.hasNext()) { - str = iter.next().toString(); - tree.append("\"Folder\" ").append(str).append("
").append(serverCore.crlfString); - } - iter = fList.iterator(); - while (iter.hasNext()) { - str = iter.next().toString(); - tree.append("\"File\" ").append(str).append("
").append(serverCore.crlfString); + // don't left the htCachePath + File file = new File(switchboard.htCachePath, pathString); + try { + if (!file.getCanonicalPath().startsWith(switchboard.htCachePath.getCanonicalPath())) { + pathString = "/"; + file = new File(switchboard.htCachePath, pathString); } + } catch (Exception e) { + pathString = "/"; + file = new File(switchboard.htCachePath, pathString); } + final StringBuffer path = new StringBuffer(256); + final StringBuffer tree = new StringBuffer(); final StringBuffer info = new StringBuffer(); + + final URL url = plasmaHTCache.getURL(switchboard.htCachePath, file); + + String urlstr = ""; if (action.equals("info") && !file.isDirectory()) { + prop.put("info", 0); + path.append((pathString.length() == 0) ? linkPathString("/", true) : linkPathString(pathString, false)); + + urlstr = htmlFilterContentScraper.urlNormalform(url); + prop.put("info_url", urlstr); + info.ensureCapacity(40000); - final String urls = htmlFilterContentScraper.urlNormalform(url); - info.append("Info for URL ").append(urls).append("

"); try { final httpHeader fileheader = switchboard.cacheManager.getCachedResponse(plasmaURL.urlHash(url)); info.append("HTTP Header:
").append(formatHeader(fileheader)).append("
"); final String ff = file.toString(); final int dotpos = ff.lastIndexOf('.'); final String ext = (dotpos >= 0) ? ff.substring(dotpos + 1).toLowerCase() : ""; - if (ext.equals("gif") || ext.equals("jpg") || ext.equals("jpeg") || ext.equals("png")) { - info.append(""); + if (ext.equals("gif") || ext.equals("jpg") || + ext.equals("png") || ext.equals("jpeg")) { + info.append(""); } else { final htmlFilterContentScraper scraper = new htmlFilterContentScraper(url); final OutputStream os = new htmlFilterOutputStream(null, scraper, null, false); serverFileUtils.copy(file, os); -// os.flush(); final plasmaParserDocument document = switchboard.parser.transformScraper(url, "text/html", scraper); info.append("HEADLINE:
").append(scraper.getHeadline()).append("
").append("
") .append("HREF:
").append(formatAnchor(document.getHyperlinks())).append("
") @@ -161,16 +128,61 @@ public class CacheAdmin_p { info.append("
"); } } catch (Exception e) { - info.append("- This file is not cached -"); + info.append("- This file is not cached -

"); info.append(e.toString()); e.printStackTrace(); - } + } + } else { + prop.put("info", 1); + + File dir; + if (file.isDirectory()) { + dir = file; + } else { + dir = file.getParentFile(); + pathString = (new File(pathString)).getParent().replace('\\','/'); + } + + // generate sorted dir/file listing + final String[] list = dir.list(); + tree.ensureCapacity((list == null) ? 70 : (list.length + 1) * 256); + path.append((pathString.length() == 0) ? linkPathString("/", true) : linkPathString(pathString, true)); + if (list == null) { + tree.append("[empty]"); + } else { + final TreeSet dList = new TreeSet(); + final TreeSet fList = new TreeSet(); + File object; + int size = list.length - 1; + for (int i = size; i >= 0 ; i--) { // Rueckwaerts ist schneller + object = new File(dir, list[i]); + if (!object.getName().equalsIgnoreCase("responseHeader.db")) { + if (object.isDirectory()) { + dList.add(list[i]); + } else { + fList.add(list[i]); + } + } + } + Iterator iter = dList.iterator(); + String str; + while (iter.hasNext()) { + str = iter.next().toString(); + tree.append("\"Folder\" ").append(str).append("
").append(serverCore.crlfString); + } + iter = fList.iterator(); + while (iter.hasNext()) { + str = iter.next().toString(); + tree.append("\"File\" ").append(str).append("
").append(serverCore.crlfString); + } + } } prop.put("cachesize", Long.toString(switchboard.cacheManager.currCacheSize/1024)); prop.put("cachemax", Long.toString(switchboard.cacheManager.maxCacheSize/1024)); - prop.put("tree", tree.toString()); - prop.put("info", info.toString()); + prop.put("path", path.toString()); + prop.put("info_info", info.toString()); + prop.put("info_tree", tree.toString()); // return rewrite properties return prop; } @@ -194,7 +206,7 @@ public class CacheAdmin_p { private static String formatAnchor(Map anchor) { final StringBuffer result = new StringBuffer((anchor.entrySet().size() + 1) * 256); - result.append(""); + result.append("
"); final Iterator iter = anchor.entrySet().iterator(); String url, descr; Map.Entry entry; @@ -203,22 +215,22 @@ public class CacheAdmin_p { url = (String) entry.getKey(); descr = ((String) entry.getValue()).trim(); if (descr.length() == 0) { descr = "-"; } - result.append(""); + result.append(""); } return result.append("
").append(descr).append(" ").append(url).append("
").append(descr).append(" ").append(url).append("
").toString(); } - private static String linkPathString(String Path){ // contributed by Alexander Schier - final String[] Elements = Path.split("/"); - final StringBuffer result = new StringBuffer(Elements.length * 256); - final StringBuffer tmpPath = new StringBuffer(256); - for(int i=0;i<(Elements.length-1);i++){ - tmpPath.append(Elements[i]).append("/"); - result.append("").append(Elements[i]).append("/"); - } - if (Elements.length > 0) { - tmpPath.append(Elements[Elements.length - 1]).append("/"); - result.append("").append(Elements[Elements.length - 1]).append("/"); + private static String linkPathString(String path, boolean dir){ + final String[] elements = path.split("/"); + final StringBuffer tmpstr = new StringBuffer(256); + final StringBuffer result = new StringBuffer(elements.length + 1 * 128); + int i, e; + if (dir) { e = elements.length; } else { e = elements.length - 1; } + for(i = 0; i < e; i++) { + if (!elements[i].equals("")) { + tmpstr.append(elements[i]).append("/"); + result.append("").append(elements[i]).append("/"); + } } return result.toString(); } diff --git a/htroot/env/style.css b/htroot/env/style.css index 0e8d0ef23..394421f3e 100644 --- a/htroot/env/style.css +++ b/htroot/env/style.css @@ -81,7 +81,8 @@ font-size:11px; *.tt { font-family:Courier,Terminal,sans-serif; font-size:8pt; -line-height:9px; +line-height:10px; +vertical-align:top; } .Menu { width: 140;