mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
*) cleaning up the code a little bit
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7377 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
parent
2521677a45
commit
6f4f957e50
|
@ -56,7 +56,7 @@ public class CookieTest_p {
|
|||
Map.Entry<String, String> e;
|
||||
while (it.hasNext()) {
|
||||
e = it.next();
|
||||
if (e.getKey().equals("Cookie")) {
|
||||
if ("Cookie".equals(e.getKey())) {
|
||||
final String cookies[] = e.getValue().split(";");
|
||||
for(final String cookie : cookies)
|
||||
{
|
||||
|
@ -70,7 +70,7 @@ public class CookieTest_p {
|
|||
prop.put("coockiesout", "0");
|
||||
//header.
|
||||
|
||||
} else if (post.containsKey("act") && post.get("act").equals("set_cookie")) {
|
||||
} else if (post.containsKey("act") && "set_cookie".equals(post.get("act"))) {
|
||||
final String cookieName = post.get("cookie_name").trim();
|
||||
final String cookieValue = post.get("cookie_value").trim();
|
||||
final ResponseHeader outgoingHeader = new ResponseHeader();
|
||||
|
|
|
@ -101,52 +101,46 @@ public class CrawlResults {
|
|||
}
|
||||
|
||||
if (post != null) {
|
||||
// custom number of lines
|
||||
if (post.containsKey("count")) {
|
||||
lines = Integer.parseInt(post.get("count", "500"));
|
||||
}
|
||||
|
||||
// do the commands
|
||||
if (post.containsKey("clearlist")) sb.crawlResults.clearStack(tabletype);
|
||||
|
||||
if (post.containsKey("deleteentry")) {
|
||||
final String hash = post.get("hash", null);
|
||||
if (hash != null) {
|
||||
// delete from database
|
||||
sb.indexSegments.urlMetadata(Segments.Process.LOCALCRAWLING).remove(hash.getBytes());
|
||||
// custom number of lines
|
||||
if (post.containsKey("count")) {
|
||||
lines = Integer.parseInt(post.get("count", "500"));
|
||||
}
|
||||
}
|
||||
|
||||
if (post.containsKey("deletedomain")) {
|
||||
final String hashpart = post.get("hashpart", null);
|
||||
final String domain = post.get("domain", null);
|
||||
if (hashpart != null) {
|
||||
// delete all urls for this domain from database
|
||||
try {
|
||||
sb.indexSegments.urlMetadata(Segments.Process.LOCALCRAWLING).deleteDomain(hashpart);
|
||||
sb.crawlResults.deleteDomain(tabletype, domain, hashpart);
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
|
||||
// do the commands
|
||||
if (post.containsKey("clearlist")) sb.crawlResults.clearStack(tabletype);
|
||||
|
||||
if (post.containsKey("deleteentry")) {
|
||||
final String hash = post.get("hash", null);
|
||||
if (hash != null) {
|
||||
// delete from database
|
||||
sb.indexSegments.urlMetadata(Segments.Process.LOCALCRAWLING).remove(hash.getBytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (post.containsKey("moreIndexed")) {
|
||||
lines = Integer.parseInt(post.get("showIndexed", "500"));
|
||||
}
|
||||
|
||||
if (post.get("si") != null)
|
||||
if (post.get("si").equals("0")) showInit = false; else showInit = true;
|
||||
if (post.get("se") != null)
|
||||
if (post.get("se").equals("0")) showExec = false; else showExec = true;
|
||||
if (post.get("sd") != null)
|
||||
if (post.get("sd").equals("0")) showDate = false; else showDate = true;
|
||||
if (post.get("sw") != null)
|
||||
if (post.get("sw").equals("0")) showWords = false; else showWords = true;
|
||||
if (post.get("st") != null)
|
||||
if (post.get("st").equals("0")) showTitle = false; else showTitle = true;
|
||||
if (post.get("su") != null)
|
||||
if (post.get("su").equals("0")) showURL = false; else showURL = true;
|
||||
|
||||
if (post.containsKey("deletedomain")) {
|
||||
final String hashpart = post.get("hashpart", null);
|
||||
final String domain = post.get("domain", null);
|
||||
if (hashpart != null) {
|
||||
// delete all urls for this domain from database
|
||||
try {
|
||||
sb.indexSegments.urlMetadata(Segments.Process.LOCALCRAWLING).deleteDomain(hashpart);
|
||||
sb.crawlResults.deleteDomain(tabletype, domain, hashpart);
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (post.containsKey("moreIndexed")) {
|
||||
lines = Integer.parseInt(post.get("showIndexed", "500"));
|
||||
}
|
||||
|
||||
if (post.get("si") != null) showInit = !("0".equals(post.get("si")));
|
||||
if (post.get("se") != null) showExec = !("0".equals(post.get("se")));
|
||||
if (post.get("sd") != null) showDate = !("0".equals(post.get("sd")));
|
||||
if (post.get("sw") != null) showWords = !("0".equals(post.get("sw")));
|
||||
if (post.get("st") != null) showTitle = !("0".equals(post.get("st")));
|
||||
if (post.get("su") != null) showURL = !("0".equals(post.get("su")));
|
||||
} // end != null
|
||||
|
||||
// create table
|
||||
|
@ -181,7 +175,7 @@ public class CrawlResults {
|
|||
URIMetadataRow.Components metadata;
|
||||
|
||||
int cnt = 0;
|
||||
Iterator<Map.Entry<String, InitExecEntry>> i = sb.crawlResults.results(tabletype);
|
||||
final Iterator<Map.Entry<String, InitExecEntry>> i = sb.crawlResults.results(tabletype);
|
||||
Map.Entry<String, InitExecEntry> entry;
|
||||
while (i.hasNext()) {
|
||||
entry = i.next();
|
||||
|
@ -266,7 +260,7 @@ public class CrawlResults {
|
|||
|
||||
cnt = 0;
|
||||
dark = true;
|
||||
Iterator<String> j = sb.crawlResults.domains(tabletype);
|
||||
final Iterator<String> j = sb.crawlResults.domains(tabletype);
|
||||
String domain;
|
||||
while (j.hasNext() && cnt < 100) {
|
||||
domain = j.next();
|
||||
|
|
|
@ -17,251 +17,267 @@ import de.anomic.server.serverSwitch;
|
|||
|
||||
public class get_bookmarks {
|
||||
|
||||
private static final serverObjects prop = new serverObjects();
|
||||
private static Switchboard sb = null;
|
||||
private static UserDB.Entry user = null;
|
||||
private static boolean isAdmin = false;
|
||||
|
||||
private static int R = 1; // TODO: solve the recursion problem an remove global variable
|
||||
private static final serverObjects prop = new serverObjects();
|
||||
private static Switchboard sb = null;
|
||||
private static UserDB.Entry user = null;
|
||||
private static boolean isAdmin = false;
|
||||
|
||||
final static int SORT_ALPHA = 1;
|
||||
final static int SORT_SIZE = 2;
|
||||
final static int SHOW_ALL = -1;
|
||||
final static int MAXRESULTS = 10000;
|
||||
|
||||
// file types and display types
|
||||
final static int XML = 0; // .xml
|
||||
final static int XHTML = 0; // .html (.xml)
|
||||
final static int JSON = 0; // .json
|
||||
final static int FLEXIGRID = 1; // .json .xml
|
||||
final static int XBEL = 2; // .xml
|
||||
final static int RSS = 3; // .xml (.rss)
|
||||
final static int RDF = 4; // .xml
|
||||
|
||||
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
|
||||
|
||||
prop.clear();
|
||||
sb = (Switchboard) env;
|
||||
user = sb.userDB.getUser(header);
|
||||
isAdmin = (sb.verifyAuthentication(header, true) || user != null && user.hasRight(UserDB.Entry.BOOKMARK_RIGHT));
|
||||
|
||||
// set user name
|
||||
final String username;
|
||||
if(user != null) username=user.getUserName();
|
||||
else if(isAdmin) username="admin";
|
||||
else username = "unknown";
|
||||
prop.putHTML("display_user", username);
|
||||
private static int R = 1; // TODO: solve the recursion problem an remove global variable
|
||||
|
||||
private final static int SORT_ALPHA = 1;
|
||||
private final static int SORT_SIZE = 2;
|
||||
private final static int SHOW_ALL = -1;
|
||||
|
||||
private final static int MAXRESULTS = 10000;
|
||||
|
||||
// file types and display types
|
||||
private enum DisplayType {
|
||||
XML(0), // .xml
|
||||
XHTML(0), // .html (.xml)
|
||||
JSON(0), // .json
|
||||
FLEXIGRID(1), // .json .xml
|
||||
XBEL(2), // .xml
|
||||
RSS(3), // .xml (.rss)
|
||||
RDF(4); // .xml
|
||||
|
||||
private int value;
|
||||
|
||||
DisplayType(final int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
|
||||
|
||||
prop.clear();
|
||||
sb = (Switchboard) env;
|
||||
user = sb.userDB.getUser(header);
|
||||
isAdmin = (sb.verifyAuthentication(header, true) || user != null && user.hasRight(UserDB.Entry.BOOKMARK_RIGHT));
|
||||
|
||||
// set user name
|
||||
final String username;
|
||||
if(user != null) username=user.getUserName();
|
||||
else if(isAdmin) username="admin";
|
||||
else username = "unknown";
|
||||
prop.putHTML("display_user", username);
|
||||
|
||||
// set peer address
|
||||
prop.put("display_address", sb.peers.mySeed().getPublicAddress());
|
||||
prop.put("display_peer", sb.peers.mySeed().getName());
|
||||
|
||||
int rp = MAXRESULTS; // items per page
|
||||
int page = 1; // page
|
||||
int display = 0; // default for JSON, XML or XHTML
|
||||
// String sortorder = "asc";
|
||||
// String sortname = "date";
|
||||
String qtype = "";
|
||||
String query = "";
|
||||
// set peer address
|
||||
prop.put("display_address", sb.peers.mySeed().getPublicAddress());
|
||||
prop.put("display_peer", sb.peers.mySeed().getName());
|
||||
|
||||
final int itemsPerPage; // items per page
|
||||
final int page; // page
|
||||
final int display; // default for JSON, XML or XHTML
|
||||
// String sortorder = "asc";
|
||||
// String sortname = "date";
|
||||
final String qtype;
|
||||
final String query;
|
||||
|
||||
// check for GET parameters
|
||||
if (post != null){
|
||||
if (post.containsKey("rp")) rp = Integer.parseInt(post.get("rp"));
|
||||
if (post.containsKey("page")) page = Integer.parseInt(post.get("page"));
|
||||
if (post.containsKey("query")) query = post.get("query");
|
||||
if (post.containsKey("qtype")) qtype = post.get("qtype");
|
||||
// if (post.containsKey("sortorder")) sortorder = post.get("sortorder");
|
||||
if (post.containsKey("display")) {
|
||||
if (post.get("display").equals("flexigrid") || post.get("display").equals("1")) {
|
||||
display = FLEXIGRID;
|
||||
}
|
||||
else if (post.get("display").equals("xbel") || post.get("display").equals("2")) {
|
||||
display = XBEL;
|
||||
}
|
||||
else if (post.get("display").equals("rss") || post.get("display").equals("3")) {
|
||||
display = RSS;
|
||||
}
|
||||
}
|
||||
prop.put("display", display);
|
||||
}
|
||||
// check for GET parameters
|
||||
if (post != null){
|
||||
itemsPerPage = (post.containsKey("rp")) ? Integer.parseInt(post.get("rp"), MAXRESULTS) : MAXRESULTS;
|
||||
page = (post.containsKey("page")) ? Integer.parseInt(post.get("page", "1")): 1;
|
||||
query = (post.containsKey("query")) ? post.get("query", "") : "";
|
||||
qtype = (post.containsKey("qtype")) ? post.get("qtype", "") : "";
|
||||
// if (post.containsKey("sortorder")) sortorder = post.get("sortorder");
|
||||
if (post.containsKey("display")) {
|
||||
final String d = post.get("display");
|
||||
if ("flexigrid".equals(d) || "1".equals(d)) {
|
||||
display = DisplayType.FLEXIGRID.getValue();
|
||||
} else if ("xbel".equals(d) || "2".equals(d)) {
|
||||
display = DisplayType.XBEL.getValue();
|
||||
} else if ("rss".equals(d) || "3".equals(d)) {
|
||||
display = DisplayType.RSS.getValue();
|
||||
} else {
|
||||
display = DisplayType.XML.getValue();
|
||||
}
|
||||
} else {
|
||||
display = DisplayType.XML.getValue();
|
||||
}
|
||||
prop.put("display", display);
|
||||
} else {
|
||||
query = "";
|
||||
qtype = "";
|
||||
page = 1;
|
||||
itemsPerPage = MAXRESULTS;
|
||||
display = DisplayType.XML.getValue();
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
int count = 0;
|
||||
int total = 0;
|
||||
int start = 0;
|
||||
int start = 0;
|
||||
|
||||
final Iterator<String> it;
|
||||
BookmarksDB.Bookmark bookmark;
|
||||
final Iterator<String> it;
|
||||
|
||||
switch (display) {
|
||||
case XBEL:
|
||||
String root = "/";
|
||||
if (qtype.equals("tags") && !query.equals("")) {
|
||||
prop.putHTML("display_folder", "1");
|
||||
prop.putHTML("display_folder_foldername", query);
|
||||
prop.putHTML("display_folder_folderhash", BookmarkHelper.tagHash(query));
|
||||
it = sb.bookmarksDB.getBookmarksIterator(query, isAdmin);
|
||||
count = print_XBEL(it, count);
|
||||
prop.put("display_xbel", count);
|
||||
break;
|
||||
} else if (query.length() > 0 && qtype.equals("folders")) {
|
||||
if (query.length() > 0 && query.charAt(0) == '/') { root = query; }
|
||||
else { root = "/" + query; }
|
||||
}
|
||||
prop.putHTML("display_folder", "0");
|
||||
R = root.replaceAll("[^/]","").length() - 1;
|
||||
count = recurseFolders(BookmarkHelper.getFolderList(root, sb.bookmarksDB.getTagIterator(isAdmin)),root,0,true,"");
|
||||
prop.put("display_xbel", count);
|
||||
break;
|
||||
|
||||
default:
|
||||
// default covers all non XBEL formats
|
||||
|
||||
// set bookmark iterator according to query
|
||||
if (qtype.equals("tags") && !query.equals("") && !query.equals("/")) {
|
||||
it = sb.bookmarksDB.getBookmarksIterator(query, isAdmin);
|
||||
} else {
|
||||
it = sb.bookmarksDB.getBookmarksIterator(isAdmin);
|
||||
}
|
||||
|
||||
if (rp < MAXRESULTS) {
|
||||
//skip the first entries (display next page)
|
||||
if (page > 1) {
|
||||
start = ((page-1)*rp)+1;
|
||||
}
|
||||
count = 0;
|
||||
while(count < start && it.hasNext()){
|
||||
it.next();
|
||||
count++;
|
||||
}
|
||||
total += count;
|
||||
}
|
||||
count = 0;
|
||||
while(count < rp && it.hasNext()){
|
||||
bookmark = sb.bookmarksDB.getBookmark(it.next());
|
||||
if(bookmark!=null) {
|
||||
prop.put("display_bookmarks_"+count+"_id",count);
|
||||
prop.put("display_bookmarks_"+count+"_link",bookmark.getUrl());
|
||||
prop.put("display_bookmarks_"+count+"_date", DateFormatter.formatISO8601(new Date(bookmark.getTimeStamp())));
|
||||
prop.put("display_bookmarks_"+count+"_rfc822date", HeaderFramework.formatRFC1123(new Date(bookmark.getTimeStamp())));
|
||||
prop.put("display_bookmarks_"+count+"_public", (bookmark.getPublic() ? "0" : "1"));
|
||||
prop.put("display_bookmarks_"+count+"_hash", bookmark.getUrlHash());
|
||||
prop.put("display_bookmarks_"+count+"_comma", ",");
|
||||
|
||||
// offer HTML encoded
|
||||
prop.putHTML("display_bookmarks_"+count+"_title-html", bookmark.getTitle());
|
||||
prop.putHTML("display_bookmarks_"+count+"_desc-html", bookmark.getDescription());
|
||||
prop.putHTML("display_bookmarks_"+count+"_tags-html", bookmark.getTagsString().replaceAll(",", ", "));
|
||||
prop.putHTML("display_bookmarks_"+count+"_folders-html", (bookmark.getFoldersString()));
|
||||
|
||||
// XML encoded
|
||||
prop.putXML("display_bookmarks_"+count+"_title-xml", bookmark.getTitle());
|
||||
prop.putXML("display_bookmarks_"+count+"_desc-xml", bookmark.getDescription());
|
||||
prop.putXML("display_bookmarks_"+count+"_tags-xml", bookmark.getTagsString());
|
||||
prop.putXML("display_bookmarks_"+count+"_folders-xml", (bookmark.getFoldersString()));
|
||||
|
||||
// and plain text (potentially unsecure)
|
||||
prop.put("display_bookmarks_"+count+"_title", bookmark.getTitle());
|
||||
prop.put("display_bookmarks_"+count+"_desc", bookmark.getDescription());
|
||||
prop.put("display_bookmarks_"+count+"_tags", bookmark.getTagsString());
|
||||
prop.put("display_bookmarks_"+count+"_folders", (bookmark.getFoldersString()));
|
||||
|
||||
count++;
|
||||
}
|
||||
}
|
||||
// eliminate the trailing comma for Json output
|
||||
rp--;
|
||||
prop.put("display_bookmarks_"+rp+"_comma", "");
|
||||
prop.put("display_bookmarks", count);
|
||||
|
||||
while(it.hasNext()){
|
||||
it.next();
|
||||
count++;
|
||||
}
|
||||
total += count;
|
||||
prop.put("display_page", page);
|
||||
prop.put("display_total", total);
|
||||
break;
|
||||
} // end switch
|
||||
if (display == DisplayType.XBEL.getValue()) {
|
||||
String root = "/";
|
||||
if ("tags".equals(qtype) && !"".equals(query)) {
|
||||
prop.putHTML("display_folder", "1");
|
||||
prop.putHTML("display_folder_foldername", query);
|
||||
prop.putHTML("display_folder_folderhash", BookmarkHelper.tagHash(query));
|
||||
it = sb.bookmarksDB.getBookmarksIterator(query, isAdmin);
|
||||
count = print_XBEL(it, count);
|
||||
prop.put("display_xbel", count);
|
||||
} else if (query.length() > 0 && "folders".equals(qtype)) {
|
||||
root = (query.charAt(0) == '/') ? query : "/" + query;
|
||||
}
|
||||
prop.putHTML("display_folder", "0");
|
||||
R = root.replaceAll("[^/]","").length() - 1;
|
||||
count = recurseFolders(BookmarkHelper.getFolderList(root, sb.bookmarksDB.getTagIterator(isAdmin)),root,0,true,"");
|
||||
prop.put("display_xbel", count);
|
||||
} else {
|
||||
// covers all non XBEL formats
|
||||
|
||||
// set bookmark iterator according to query
|
||||
if ("tags".equals(qtype) && !"".equals(query) && !"/".equals(query)) {
|
||||
it = sb.bookmarksDB.getBookmarksIterator(query, isAdmin);
|
||||
} else {
|
||||
it = sb.bookmarksDB.getBookmarksIterator(isAdmin);
|
||||
}
|
||||
|
||||
if (itemsPerPage < MAXRESULTS) {
|
||||
//skip the first entries (display next page)
|
||||
if (page > 1) {
|
||||
start = ((page - 1) * itemsPerPage) + 1;
|
||||
}
|
||||
count = 0;
|
||||
while (count < start && it.hasNext()) {
|
||||
it.next();
|
||||
count++;
|
||||
}
|
||||
total += count;
|
||||
}
|
||||
count = 0;
|
||||
BookmarksDB.Bookmark bookmark = null;
|
||||
while (count < itemsPerPage && it.hasNext()) {
|
||||
bookmark = sb.bookmarksDB.getBookmark(it.next());
|
||||
if (bookmark != null) {
|
||||
prop.put("display_bookmarks_"+count+"_id",count);
|
||||
prop.put("display_bookmarks_"+count+"_link",bookmark.getUrl());
|
||||
prop.put("display_bookmarks_"+count+"_date", DateFormatter.formatISO8601(new Date(bookmark.getTimeStamp())));
|
||||
prop.put("display_bookmarks_"+count+"_rfc822date", HeaderFramework.formatRFC1123(new Date(bookmark.getTimeStamp())));
|
||||
prop.put("display_bookmarks_"+count+"_public", (bookmark.getPublic() ? "0" : "1"));
|
||||
prop.put("display_bookmarks_"+count+"_hash", bookmark.getUrlHash());
|
||||
prop.put("display_bookmarks_"+count+"_comma", ",");
|
||||
|
||||
// offer HTML encoded
|
||||
prop.putHTML("display_bookmarks_"+count+"_title-html", bookmark.getTitle());
|
||||
prop.putHTML("display_bookmarks_"+count+"_desc-html", bookmark.getDescription());
|
||||
prop.putHTML("display_bookmarks_"+count+"_tags-html", bookmark.getTagsString().replaceAll(",", ", "));
|
||||
prop.putHTML("display_bookmarks_"+count+"_folders-html", (bookmark.getFoldersString()));
|
||||
|
||||
// XML encoded
|
||||
prop.putXML("display_bookmarks_"+count+"_title-xml", bookmark.getTitle());
|
||||
prop.putXML("display_bookmarks_"+count+"_desc-xml", bookmark.getDescription());
|
||||
prop.putXML("display_bookmarks_"+count+"_tags-xml", bookmark.getTagsString());
|
||||
prop.putXML("display_bookmarks_"+count+"_folders-xml", (bookmark.getFoldersString()));
|
||||
|
||||
// and plain text (potentially unsecure)
|
||||
prop.put("display_bookmarks_"+count+"_title", bookmark.getTitle());
|
||||
prop.put("display_bookmarks_"+count+"_desc", bookmark.getDescription());
|
||||
prop.put("display_bookmarks_"+count+"_tags", bookmark.getTagsString());
|
||||
prop.put("display_bookmarks_"+count+"_folders", (bookmark.getFoldersString()));
|
||||
|
||||
count++;
|
||||
}
|
||||
}
|
||||
// eliminate the trailing comma for Json output
|
||||
|
||||
prop.put("display_bookmarks_" + (itemsPerPage - 1) + "_comma", "");
|
||||
prop.put("display_bookmarks", count);
|
||||
|
||||
while(it.hasNext()){
|
||||
it.next();
|
||||
count++;
|
||||
}
|
||||
total += count;
|
||||
prop.put("display_page", page);
|
||||
prop.put("display_total", total);
|
||||
}
|
||||
|
||||
// return rewrite properties
|
||||
return prop;
|
||||
}
|
||||
|
||||
private static int recurseFolders(final Iterator<String> it, String root, int count, final boolean next, final String prev){
|
||||
private static int recurseFolders(final Iterator<String> it, String root, int count, final boolean next, final String prev){
|
||||
String fn="";
|
||||
|
||||
if(next) fn = it.next();
|
||||
if (next) fn = it.next();
|
||||
else fn = prev;
|
||||
|
||||
if(fn.equals("\uffff")) {
|
||||
int i = prev.replaceAll("[^/]","").length() - R;
|
||||
while(i>0){
|
||||
prop.put("display_xbel_"+count+"_elements", "</folder>");
|
||||
count++;
|
||||
i--;
|
||||
}
|
||||
return count;
|
||||
if ("\uffff".equals(fn)) {
|
||||
int i = prev.replaceAll("[^/]","").length() - R;
|
||||
while (i > 0) {
|
||||
prop.put("display_xbel_"+count+"_elements", "</folder>");
|
||||
count++;
|
||||
i--;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
if(fn.startsWith((root.equals("/") ? root : root+"/"))){
|
||||
prop.put("display_xbel_"+count+"_elements", "<folder id=\""+BookmarkHelper.tagHash(fn)+"\">");
|
||||
count++;
|
||||
|
||||
final String title = fn; // just to make sure fn stays untouched
|
||||
prop.put("display_xbel_"+count+"_elements", "<title>" + CharacterCoding.unicode2xml(title.replaceAll("(/.[^/]*)*/", ""), true) + "</title>");
|
||||
count++;
|
||||
final Iterator<String> bit=sb.bookmarksDB.getBookmarksIterator(fn, isAdmin);
|
||||
count = print_XBEL(bit, count);
|
||||
if(it.hasNext()){
|
||||
count = recurseFolders(it, fn, count, true, fn);
|
||||
}
|
||||
if (fn.startsWith(("/".equals(root) ? root : root + "/"))) {
|
||||
prop.put("display_xbel_"+count+"_elements", "<folder id=\""+BookmarkHelper.tagHash(fn)+"\">");
|
||||
count++;
|
||||
|
||||
final String title = fn; // just to make sure fn stays untouched
|
||||
prop.put("display_xbel_"+count+"_elements", "<title>" + CharacterCoding.unicode2xml(title.replaceAll("(/.[^/]*)*/", ""), true) + "</title>");
|
||||
count++;
|
||||
final Iterator<String> bit=sb.bookmarksDB.getBookmarksIterator(fn, isAdmin);
|
||||
count = print_XBEL(bit, count);
|
||||
if (it.hasNext()) {
|
||||
count = recurseFolders(it, fn, count, true, fn);
|
||||
}
|
||||
} else {
|
||||
if (count > 0) {
|
||||
prop.put("display_xbel_"+count+"_elements", "</folder>");
|
||||
count++;
|
||||
}
|
||||
root = root.replaceAll("(/.[^/]*$)", "");
|
||||
if(root.equals("")) root = "/";
|
||||
count = recurseFolders(it, root, count, false, fn);
|
||||
if (count > 0) {
|
||||
prop.put("display_xbel_"+count+"_elements", "</folder>");
|
||||
count++;
|
||||
}
|
||||
root = root.replaceAll("(/.[^/]*$)", "");
|
||||
if ("".equals(root)) root = "/";
|
||||
count = recurseFolders(it, root, count, false, fn);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private static int print_XBEL(final Iterator<String> bit, int count) {
|
||||
BookmarksDB.Bookmark bookmark;
|
||||
BookmarksDB.Bookmark bookmark = null;
|
||||
Date date;
|
||||
while(bit.hasNext()){
|
||||
bookmark=sb.bookmarksDB.getBookmark(bit.next());
|
||||
date=new Date(bookmark.getTimeStamp());
|
||||
prop.put("display_xbel_"+count+"_elements", "<bookmark id=\"" + bookmark.getUrlHash()
|
||||
+ "\" href=\"" + CharacterCoding.unicode2xml(bookmark.getUrl(), true)
|
||||
+ "\" added=\"" + CharacterCoding.unicode2xml(DateFormatter.formatISO8601(date), true)+"\">");
|
||||
count++;
|
||||
prop.put("display_xbel_"+count+"_elements", "<title>");
|
||||
count++;
|
||||
prop.putXML("display_xbel_"+count+"_elements", bookmark.getTitle());
|
||||
count++;
|
||||
prop.put("display_xbel_"+count+"_elements", "</title>");
|
||||
count++;
|
||||
prop.put("display_xbel_"+count+"_elements", "<info>");
|
||||
count++;
|
||||
prop.put("display_xbel_"+count+"_elements", "<metadata owner=\"Mozilla\" ShortcutURL=\""
|
||||
+ CharacterCoding.unicode2xml(bookmark.getTagsString().replaceAll("/.*,", "").toLowerCase(), true)
|
||||
+ "\"/>");
|
||||
count++;
|
||||
prop.put("display_xbel_"+count+"_elements", "<metadata owner=\"YaCy\" public=\""+Boolean.toString(bookmark.getPublic())+"\"/>");
|
||||
count++;
|
||||
prop.put("display_xbel_"+count+"_elements", "</info>");
|
||||
count++;
|
||||
prop.put("display_xbel_"+count+"_elements", "<desc>");
|
||||
count++;
|
||||
prop.putXML("display_xbel_"+count+"_elements", bookmark.getDescription());
|
||||
count++;
|
||||
prop.put("display_xbel_"+count+"_elements", "</desc>");
|
||||
count++;
|
||||
prop.put("display_xbel_"+count+"_elements", "</bookmark>");
|
||||
count++;
|
||||
}
|
||||
bookmark = sb.bookmarksDB.getBookmark(bit.next());
|
||||
date = new Date(bookmark.getTimeStamp());
|
||||
prop.put("display_xbel_"+count+"_elements", "<bookmark id=\"" + bookmark.getUrlHash()
|
||||
+ "\" href=\"" + CharacterCoding.unicode2xml(bookmark.getUrl(), true)
|
||||
+ "\" added=\"" + CharacterCoding.unicode2xml(DateFormatter.formatISO8601(date), true)+"\">");
|
||||
count++;
|
||||
prop.put("display_xbel_"+count+"_elements", "<title>");
|
||||
count++;
|
||||
prop.putXML("display_xbel_"+count+"_elements", bookmark.getTitle());
|
||||
count++;
|
||||
prop.put("display_xbel_"+count+"_elements", "</title>");
|
||||
count++;
|
||||
prop.put("display_xbel_"+count+"_elements", "<info>");
|
||||
count++;
|
||||
prop.put("display_xbel_"+count+"_elements", "<metadata owner=\"Mozilla\" ShortcutURL=\""
|
||||
+ CharacterCoding.unicode2xml(bookmark.getTagsString().replaceAll("/.*,", "").toLowerCase(), true)
|
||||
+ "\"/>");
|
||||
count++;
|
||||
prop.put("display_xbel_"+count+"_elements", "<metadata owner=\"YaCy\" public=\""+Boolean.toString(bookmark.getPublic())+"\"/>");
|
||||
count++;
|
||||
prop.put("display_xbel_"+count+"_elements", "</info>");
|
||||
count++;
|
||||
prop.put("display_xbel_"+count+"_elements", "<desc>");
|
||||
count++;
|
||||
prop.putXML("display_xbel_"+count+"_elements", bookmark.getDescription());
|
||||
count++;
|
||||
prop.put("display_xbel_"+count+"_elements", "</desc>");
|
||||
count++;
|
||||
prop.put("display_xbel_"+count+"_elements", "</bookmark>");
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
|
@ -32,13 +32,12 @@ public class feed {
|
|||
|
||||
int messageCount = 0;
|
||||
int messageMaxCount = Math.min(post.getInt("count", 100), 1000);
|
||||
|
||||
RSSFeed feed;
|
||||
channelIteration: for (String channel: channels) {
|
||||
|
||||
channelIteration: for (final String channel: channels) {
|
||||
// prevent that unauthorized access to this servlet get results from private data
|
||||
if ((!authorized) && (yacyChannel.privateChannels.contains(channel))) continue channelIteration; // allow only public channels if not authorized
|
||||
|
||||
if (channel.equals("TEST")) {
|
||||
if ("TEST".equals(channel)) {
|
||||
// for interface testing return at least one single result
|
||||
prop.putXML("channel_title", "YaCy News Testchannel");
|
||||
prop.putXML("channel_description", "");
|
||||
|
@ -54,7 +53,7 @@ public class feed {
|
|||
}
|
||||
|
||||
// read the channel
|
||||
feed = yacyChannel.channels(channel);
|
||||
final RSSFeed feed = yacyChannel.channels(channel);
|
||||
if (feed == null || feed.isEmpty()) continue channelIteration;
|
||||
|
||||
RSSMessage message = feed.getChannel();
|
||||
|
|
|
@ -47,27 +47,31 @@ public class cytag {
|
|||
public static Image respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
|
||||
|
||||
final Switchboard sb = (Switchboard)env;
|
||||
MultiProtocolURI referer = header.referer();
|
||||
final MultiProtocolURI referer = header.referer();
|
||||
|
||||
// harvest request information
|
||||
StringBuilder connect = new StringBuilder();
|
||||
connect.append('{');
|
||||
addJSON(connect, "time", DateFormatter.formatShortMilliSecond(new Date()));
|
||||
addJSON(connect, "trail", (referer == null) ? "" : referer.toNormalform(false, false));
|
||||
addJSON(connect, "nick", (post == null) ? "" : post.get("nick", ""));
|
||||
addJSON(connect, "tag", (post == null) ? "" : post.get("tag", ""));
|
||||
addJSON(connect, "icon", (post == null) ? "" : post.get("icon", ""));
|
||||
addJSON(connect, "ip", header.get(HeaderFramework.CONNECTION_PROP_CLIENTIP, ""));
|
||||
addJSON(connect, "agent", header.get("User-Agent", ""));
|
||||
appendJSON(connect, "time", DateFormatter.formatShortMilliSecond(new Date()));
|
||||
appendJSON(connect, "trail", (referer == null) ? "" : referer.toNormalform(false, false));
|
||||
appendJSON(connect, "nick", (post == null) ? "" : post.get("nick", ""));
|
||||
appendJSON(connect, "tag", (post == null) ? "" : post.get("tag", ""));
|
||||
appendJSON(connect, "icon", (post == null) ? "" : post.get("icon", ""));
|
||||
appendJSON(connect, "ip", header.get(HeaderFramework.CONNECTION_PROP_CLIENTIP, ""));
|
||||
appendJSON(connect, "agent", header.get("User-Agent", ""));
|
||||
connect.append('}');
|
||||
|
||||
if (sb.trail.size() >= 100) sb.trail.remove();
|
||||
sb.trail.add(connect.toString());
|
||||
//Log.logInfo("CYTAG", "catched trail - " + connect.toString());
|
||||
|
||||
String defaultimage = "redpillmini.png";
|
||||
if (post != null && post.get("icon", "").equals("invisible")) defaultimage = "invisible.png";
|
||||
File iconfile = new File(sb.getAppPath(), "/htroot/env/grafics/" + defaultimage);
|
||||
final String defaultimage;
|
||||
if (post != null && post.get("icon", "").equals("invisible")) {
|
||||
defaultimage = "redpillmini.png";
|
||||
} else {
|
||||
defaultimage = "invisible.png";
|
||||
}
|
||||
final File iconfile = new File(sb.getAppPath(), "/htroot/env/grafics/" + defaultimage);
|
||||
|
||||
byte[] imgb = null;
|
||||
try {
|
||||
|
@ -83,12 +87,12 @@ public class cytag {
|
|||
return image;
|
||||
}
|
||||
|
||||
private static final void addJSON(StringBuilder sb, String k, String v) {
|
||||
private static final void appendJSON(final StringBuilder sb, final String key, final String value) {
|
||||
if (sb.length() > 2) sb.append(',');
|
||||
sb.append('\"');
|
||||
sb.append(k);
|
||||
sb.append(key);
|
||||
sb.append("\":\"");
|
||||
sb.append(CharacterCoding.unicode2xml(v, true));
|
||||
sb.append(CharacterCoding.unicode2xml(value, true));
|
||||
sb.append('\"');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,10 @@
|
|||
|
||||
package de.anomic.yacy;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import net.yacy.cora.document.RSSFeed;
|
||||
import net.yacy.cora.document.RSSMessage;
|
||||
|
@ -44,19 +46,14 @@ public enum yacyChannel {
|
|||
* the following private channels are declared to prevent that an access to the feed servlet
|
||||
* gets results from news channels that are not for the public
|
||||
*/
|
||||
public static final HashSet<yacyChannel> privateChannels = new HashSet<yacyChannel>();
|
||||
static {
|
||||
privateChannels.add(yacyChannel.LOCALSEARCH);
|
||||
privateChannels.add(yacyChannel.LOCALINDEXING);
|
||||
}
|
||||
|
||||
public static final Set<yacyChannel> privateChannels = EnumSet.of(yacyChannel.LOCALSEARCH, yacyChannel.LOCALINDEXING);
|
||||
|
||||
/**
|
||||
* the following static channels object is used to organize a storage array for RSS feeds
|
||||
*/
|
||||
private static final ConcurrentHashMap<yacyChannel, RSSFeed> channels = new ConcurrentHashMap<yacyChannel, RSSFeed>();
|
||||
private static final ConcurrentMap<yacyChannel, RSSFeed> channels = new ConcurrentHashMap<yacyChannel, RSSFeed>();
|
||||
public static RSSFeed channels(final String channelName) {
|
||||
for (yacyChannel channel: yacyChannel.values()) {
|
||||
for (final yacyChannel channel : yacyChannel.values()) {
|
||||
if (channel.name().equals(channelName)) return channels(channel);
|
||||
}
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue
Block a user