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