sorted directory/file list;

dont list responseHeader.db;
StringBuffers, finals;
cleaned;


git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@733 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
borg-0300 19 years ago
parent cddd9aaa33
commit 650764ce62

@ -4,7 +4,10 @@
// (C) by Michael Peter Christen; mc@anomic.de // (C) by Michael Peter Christen; mc@anomic.de
// first published on http://www.anomic.de // first published on http://www.anomic.de
// Frankfurt, Germany, 2004 // Frankfurt, Germany, 2004
// last major change: 28.06.2003 //
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
// //
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
@ -50,6 +53,9 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import de.anomic.htmlFilter.htmlFilterContentScraper; import de.anomic.htmlFilter.htmlFilterContentScraper;
import de.anomic.htmlFilter.htmlFilterOutputStream; import de.anomic.htmlFilter.htmlFilterOutputStream;
import de.anomic.http.httpHeader; import de.anomic.http.httpHeader;
@ -64,25 +70,27 @@ import de.anomic.server.serverSwitch;
public class CacheAdmin_p { public class CacheAdmin_p {
private final static String HTML_BR = "<br>";
private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
public static String dateString(Date date) { public static String dateString(final Date date) {
return SimpleFormatter.format(date); return SimpleFormatter.format(date);
} }
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) { public static serverObjects respond(final httpHeader header, final serverObjects post, final serverSwitch env) {
plasmaSwitchboard switchboard = (plasmaSwitchboard) env; final plasmaSwitchboard switchboard = (plasmaSwitchboard) env;
serverObjects prop = new serverObjects(); final serverObjects prop = new serverObjects();
String action = ((post == null) ? "info" : post.get("action", "info")); final String action = ((post == null) ? "info" : post.get("action", "info"));
String pathString = ((post == null) ? "" : post.get("path", "/")); String pathString = ((post == null) ? "" : post.get("path", "/"));
String fileString = pathString; final String fileString = pathString;
// we dont need check the path, because we have do that in plasmaSwitchboard.java - Borg-0300 // we dont need check the path, because we have do that in plasmaSwitchboard.java - Borg-0300
File cache = new File(switchboard.getConfig("proxyCache", "DATA/HTCACHE").toString()); final File cache = new File(switchboard.getConfig("proxyCache", "DATA/HTCACHE"));
File file = new File(cache, pathString); File dir;
File dir; final File file = new File(cache, pathString);
URL url = plasmaHTCache.getURL(cache, file); final URL url = plasmaHTCache.getURL(cache, file);
if (file.isDirectory()) { if (file.isDirectory()) {
dir = file; dir = file;
@ -91,110 +99,140 @@ public class CacheAdmin_p {
pathString = (new File(pathString)).getParent().replace('\\','/'); pathString = (new File(pathString)).getParent().replace('\\','/');
} }
// generate dir listing // generate sorted dir/file listing
String[] list = dir.list(); final StringBuffer tree = new StringBuffer("Directory of<br>").append((pathString.length() == 0) ? "domain list" : linkPathString(pathString)).append("<br><br>");
File f;
StringBuffer tree = new StringBuffer(list.length * 200); final List dList = new ArrayList(50);
tree.append("Directory of<br>" + ((pathString.length() == 0) ? "domain list" : linkPathString(pathString)) + "<br><br>"); final List fList = new ArrayList(20);
if (list == null) final String[] list = dir.list();
File object;
if (list == null) {
tree.append("[empty]"); tree.append("[empty]");
else { } else {
for (int i = 0; i < list.length; i++) { for (int i = list.length - 1; i >= 0 ; i--) { // Rückwärts ist schneller
f = new File(dir, list[i]); object = new File(dir, list[i]);
if (!f.getName().equalsIgnoreCase("responseHeader.db")) if (!object.getName().equalsIgnoreCase("responseHeader.db")) {
if (f.isDirectory()) if (object.isDirectory()) {
tree.append("<img src=\"/env/grafics/folderIconSmall.gif\" align=\"top\" alt=\"Folder\">&nbsp;<a href=\"CacheAdmin_p.html?action=info&path=" + pathString + "/" + list[i] + "\" class=\"tt\">" + list[i] + "</a><br>" + serverCore.crlfString); dList.add(list[i]);
else } else {
tree.append("<img src=\"/env/grafics/fileIconSmall.gif\" align=\"top\" alt=\"File\">&nbsp;<a href=\"CacheAdmin_p.html?action=info&path=" + pathString + "/" + list[i] + "\" class=\"tt\">" + list[i] + "</a><br>" + serverCore.crlfString); fList.add(list[i]);
}
}
}
Iterator iter = dList.iterator();
String str;
if (dList.size() > 1) {
Collections.sort(dList);
try {
while (true) {
str = iter.next().toString();
tree.append("<img src=\"/env/grafics/folderIconSmall.gif\" align=\"top\" alt=\"Folder\">&nbsp;<a href=\"CacheAdmin_p.html?action=info&path=").append(pathString).append("/").append(str).append("\" class=\"tt\">").append(str).append("</a><br>").append(serverCore.crlfString);
}
} catch (java.util.NoSuchElementException e) {} // intention
}
if (fList.size() > 1) {
Collections.sort(fList);
iter = fList.iterator();
try {
while (true) {
str = iter.next().toString();
tree.append("<img src=\"/env/grafics/fileIconSmall.gif\" align=\"top\" alt=\"File\">&nbsp;<a href=\"CacheAdmin_p.html?action=info&path=").append(pathString).append("/").append(str).append("\" class=\"tt\">").append(str).append("</a><br>").append(serverCore.crlfString);
}
} catch (java.util.NoSuchElementException e) {} // intention
} }
} }
String info = ""; final StringBuffer info = new StringBuffer();
if (action.equals("info")) { if ((action.equals("info")) && (!file.isDirectory())) {
if (!(file.isDirectory())) { final String urls = htmlFilterContentScraper.urlNormalform(url);
String urls = htmlFilterContentScraper.urlNormalform(url); info.append("<b>Info for URL <a href=\"").append(urls).append("\">").append(urls).append("</a>:</b><br><br>");
info += "<b>Info for URL <a href=\"" + urls + "\">" + urls + "</a>:</b><br><br>"; try {
try { final httpHeader fileheader = switchboard.cacheManager.getCachedResponse(plasmaURL.urlHash(url));
httpHeader fileheader = switchboard.cacheManager.getCachedResponse(plasmaURL.urlHash(url)); info.append("<b>HTTP Header:</b><br>").append(formatHeader(fileheader)).append(HTML_BR);
info += "<b>HTTP Header:</b><br>" + formatHeader(fileheader) + "<br>"; final String ff = file.toString();
String ff = file.toString(); final int dotpos = ff.lastIndexOf('.');
int p = ff.lastIndexOf('.'); final String ext = (dotpos >= 0) ? ff.substring(dotpos + 1).toLowerCase() : "";
String ext = (p >= 0) ? ff.substring(p + 1).toLowerCase() : ""; if ((ext.equals("gif")) || (ext.equals("jpg")) || (ext.equals("jpeg")) || (ext.equals("png"))) {
if ((ext.equals("gif")) || (ext.equals("jpg")) || (ext.equals("jpeg")) || (ext.equals("png"))) info.append("<img src=\"" + "CacheResource_p.html?path=").append(fileString).append("\">");
info += "<img src=\"" + "CacheResource_p.html?path=" + fileString + "\">"; } else {
else { final htmlFilterContentScraper scraper = new htmlFilterContentScraper(url);
htmlFilterContentScraper scraper = new htmlFilterContentScraper(url); final OutputStream os = new htmlFilterOutputStream(null, scraper, null, false);
OutputStream os = new htmlFilterOutputStream(null, scraper, null, false); serverFileUtils.copy(file, os);
serverFileUtils.copy(file, os); os.flush();
os.flush(); final plasmaParserDocument document = switchboard.parser.transformScraper(url, "text/html", scraper);
plasmaParserDocument document = switchboard.parser.transformScraper(url, "text/html", scraper); info.append("<b>HEADLINE:</b><br>").append(scraper.getHeadline()).append(HTML_BR).append(HTML_BR);
info += "<b>HEADLINE:</b><br>" + scraper.getHeadline() + "<br><br>"; info.append("<b>HREF:</b><br>").append(formatAnchor(document.getHyperlinks())).append(HTML_BR);
info += "<b>HREF:</b><br>" + formatAnchor(document.getHyperlinks()) + "<br>"; info.append("<b>MEDIA:</b><br>").append(formatAnchor(document.getMedialinks())).append(HTML_BR);
info += "<b>MEDIA:</b><br>" + formatAnchor(document.getMedialinks()) + "<br>"; info.append("<b>EMAIL:</b><br>").append(formatAnchor(document.getEmaillinks())).append(HTML_BR);
info += "<b>EMAIL:</b><br>" + formatAnchor(document.getEmaillinks()) + "<br>"; info.append("<b>TEXT:</b><br><span class=\"small\">").append(new String(scraper.getText())).append("</span><br>");
info += "<b>TEXT:</b><br><span class=\"small\">" + new String(scraper.getText()) + "</span><br>"; info.append("<b>LINES:</b><br><span class=\"small\">");
info += "<b>LINES:</b><br><span class=\"small\">"; final String[] sentences = document.getSentences();
String[] sentences = document.getSentences(); for (int i = 0; i < sentences.length; i++) {
for (int i = 0; i < sentences.length; i++) info += sentences[i] + "<br>"; info.append(sentences[i]).append(HTML_BR);
info += "</span><br>";
} }
} catch (Exception e) { info.append("</span><br>");
info += e.toString();
e.printStackTrace();
} }
} } catch (Exception e) {
info.append("- This file is not in the cache -");
info.append(e.toString());
// e.printStackTrace();
}
} }
prop.put("cachesize", Long.toString(switchboard.cacheManager.currCacheSize/1024)); prop.put("cachesize", Long.toString(switchboard.cacheManager.currCacheSize/1024));
prop.put("cachemax", Long.toString(switchboard.cacheManager.maxCacheSize/1024)); prop.put("cachemax", Long.toString(switchboard.cacheManager.maxCacheSize/1024));
prop.put("tree", tree.toString()); prop.put("tree", tree.toString());
prop.put("info", info); prop.put("info", info.toString());
// return rewrite properties // return rewrite properties
return prop; return prop;
} }
private static String formatHeader(httpHeader header) { private static String formatHeader(final httpHeader header) {
if (header == null) return "- no header in header cache -"; final StringBuffer result = new StringBuffer();
String out = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; if (header == null) {
Iterator it = header.entrySet().iterator(); result.append("- no header in header cache -");
Map.Entry entry; } else {
while (it.hasNext()) { result.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
entry = (Map.Entry) it.next(); final Iterator iter = header.entrySet().iterator();
out += "<tr valign=\"top\"><td class=\"tt\">" + entry.getKey() + "</td><td class=\"tt\">&nbsp;=&nbsp;</td><td class=\"tt\">" + entry.getValue() + "</td></tr>"; Map.Entry entry;
while (iter.hasNext()) {
entry = (Map.Entry) iter.next();
result.append("<tr valign=\"top\"><td class=\"tt\">").append(entry.getKey()).append("</td><td class=\"tt\">&nbsp;=&nbsp;</td><td class=\"tt\">").append(entry.getValue()).append("</td></tr>");
}
result.append("</table>");
} }
out += "</table>"; return result.toString();
return out;
} }
private static String formatAnchor(Map a) { private static String formatAnchor(final Map anchor) {
String out = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; final StringBuffer result = new StringBuffer("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
Iterator i = a.entrySet().iterator(); final Iterator iter = anchor.entrySet().iterator();
String url, descr; String url, descr;
Map.Entry entry; Map.Entry entry;
while (i.hasNext()) { while (iter.hasNext()) {
entry = (Map.Entry) i.next(); entry = (Map.Entry) iter.next();
url = (String) entry.getKey(); url = (String) entry.getKey();
descr = ((String) entry.getValue()).trim(); descr = ((String) entry.getValue()).trim();
if (descr.length() == 0) descr = "-"; if (descr.length() == 0) { descr = "-"; }
out += "<tr valign=\"top\"><td><span class=\"small\">" + descr + "&nbsp;</span></td><td class=\"tt\">" + url + "</td></tr>"; result.append("<tr valign=\"top\"><td><span class=\"small\">").append(descr).append("&nbsp;</span></td><td class=\"tt\">").append(url).append("</td></tr>");
} }
out += "</table>"; return result.append("</table>").toString();
return out;
} }
private static String linkPathString(String Path){ // contributed by Alexander Schier private static String linkPathString(final String Path){ // contributed by Alexander Schier
String Elements[] = Path.split("/"); final String[] Elements = Path.split("/");
String result = ""; final StringBuffer result = new StringBuffer();
String tmpPath = ""; final StringBuffer tmpPath = new StringBuffer();
for(int i=0;i<(Elements.length-1);i++){ for(int i=0;i<(Elements.length-1);i++){
tmpPath += Elements[i] + "/"; tmpPath.append(Elements[i]).append("/");
result += "<a href=\"CacheAdmin_p.html?action=info&path=" + tmpPath + "\" class=\"tt\">" + Elements[i] + "/</a>"; result.append("<a href=\"CacheAdmin_p.html?action=info&path=").append(tmpPath).append("\" class=\"tt\">").append(Elements[i]).append("/</a>");
} }
if (Elements.length > 0) { if (Elements.length > 0) {
tmpPath += Elements[Elements.length - 1] + "/"; tmpPath.append(Elements[Elements.length - 1]).append("/");
result += "<span class=\"tt\">" + Elements[Elements.length - 1] + "/</span>"; result.append("<span class=\"tt\">").append(Elements[Elements.length - 1]).append("/</span>");
} }
return result; return result.toString();
} }
} }

Loading…
Cancel
Save