Fixed numberbug in Blog, see http://forum.yacy-websuche.de/viewtopic.php?f=6&t=639. This wont fix existing Blogentrys (comes later).

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4443 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
lulabad 17 years ago
parent 141db7ba48
commit 40a0591942

@ -1,394 +1,390 @@
// Blog.java // Blog.java
// ----------------------- // -----------------------
// part of YACY // part of YACY
// (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
// //
// This File is contributed by Jan Sandbrink // This File is contributed by Jan Sandbrink
// Contains contributions from Marc Nause [MN] // Contains contributions from Marc Nause [MN]
// last change: 06.05.2006 // last change: 06.05.2006
// //
// 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
// the Free Software Foundation; either version 2 of the License, or // the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// //
// Using this software in any meaning (reading, learning, copying, compiling, // Using this software in any meaning (reading, learning, copying, compiling,
// running) means that you agree that the Author(s) is (are) not responsible // running) means that you agree that the Author(s) is (are) not responsible
// for cost, loss of data or any harm that may be caused directly or indirectly // for cost, loss of data or any harm that may be caused directly or indirectly
// by usage of this softare or this documentation. The usage of this software // by usage of this softare or this documentation. The usage of this software
// is on your own risk. The installation and usage (starting/running) of this // is on your own risk. The installation and usage (starting/running) of this
// software may allow other people or application to access your computer and // software may allow other people or application to access your computer and
// any attached devices and is highly dependent on the configuration of the // any attached devices and is highly dependent on the configuration of the
// software which must be done by the user of the software; the author(s) is // software which must be done by the user of the software; the author(s) is
// (are) also not responsible for proper configuration and usage of the // (are) also not responsible for proper configuration and usage of the
// software, even if provoked by documentation provided together with // software, even if provoked by documentation provided together with
// the software. // the software.
// //
// Any changes to this file according to the GPL as documented in the file // Any changes to this file according to the GPL as documented in the file
// gpl.txt aside this file in the shipment you received can be done to the // gpl.txt aside this file in the shipment you received can be done to the
// lines that follows this copyright notice here, but changes must not be // lines that follows this copyright notice here, but changes must not be
// done inside the copyright notive above. A re-distribution must contain // done inside the copyright notive above. A re-distribution must contain
// the intact and unchanged copyright notice. // the intact and unchanged copyright notice.
// Contributions and changes to the program code must be marked as such. // Contributions and changes to the program code must be marked as such.
// You must compile this file with // You must compile this file with
// javac -classpath .:../classes Blog.java // javac -classpath .:../classes Blog.java
// if the shell's current path is HTROOT // if the shell's current path is HTROOT
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import de.anomic.data.blogBoard; import de.anomic.data.blogBoard;
import de.anomic.data.userDB; import de.anomic.data.userDB;
import de.anomic.http.httpHeader; import de.anomic.http.httpHeader;
import de.anomic.http.httpc; import de.anomic.http.httpc;
import de.anomic.plasma.plasmaSwitchboard; import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverObjects; import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch; import de.anomic.server.serverSwitch;
import de.anomic.server.logging.serverLog; import de.anomic.server.logging.serverLog;
import de.anomic.yacy.yacyCore; import de.anomic.yacy.yacyCore;
import de.anomic.yacy.yacyNewsPool; import de.anomic.yacy.yacyNewsPool;
import de.anomic.yacy.yacyNewsRecord; import de.anomic.yacy.yacyNewsRecord;
public class Blog { public class Blog {
private static final String DEFAULT_PAGE = "blog_default"; private static final String DEFAULT_PAGE = "blog_default";
private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
// TODO: make userdefined date/time-strings (localisation) // TODO: make userdefined date/time-strings (localisation)
public static String dateString(Date date) { public static String dateString(Date date) {
return SimpleFormatter.format(date); return SimpleFormatter.format(date);
} }
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) { public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) {
final plasmaSwitchboard switchboard = (plasmaSwitchboard) env; final plasmaSwitchboard switchboard = (plasmaSwitchboard) env;
final serverObjects prop = new serverObjects(); final serverObjects prop = new serverObjects();
blogBoard.entry page = null; blogBoard.entry page = null;
final boolean authenticated = switchboard.adminAuthenticated(header) >= 2; final boolean authenticated = switchboard.adminAuthenticated(header) >= 2;
final int display = ((post == null) || (!authenticated)) ? 0 : post.getInt("display", 0); final int display = ((post == null) || (!authenticated)) ? 0 : post.getInt("display", 0);
prop.put("display", display); prop.put("display", display);
boolean hasRights = switchboard.verifyAuthentication(header, true); boolean hasRights = switchboard.verifyAuthentication(header, true);
final boolean xml = ((String)header.get(httpHeader.CONNECTION_PROP_PATH)).endsWith(".xml"); final boolean xml = ((String)header.get(httpHeader.CONNECTION_PROP_PATH)).endsWith(".xml");
final String address = yacyCore.seedDB.mySeed().getPublicAddress(); final String address = yacyCore.seedDB.mySeed().getPublicAddress();
if(hasRights) { if(hasRights) {
prop.put("mode_admin", "1"); prop.put("mode_admin", "1");
} else { } else {
prop.put("mode_admin", "0"); prop.put("mode_admin", "0");
} }
if (post == null) { if (post == null) {
prop.putHTML("peername", yacyCore.seedDB.mySeed().getName()); prop.putHTML("peername", yacyCore.seedDB.mySeed().getName());
prop.put("address", address); prop.put("address", address);
return putBlogDefault(prop, switchboard, address, 0, 10, hasRights, xml); return putBlogDefault(prop, switchboard, address, 0, 10, hasRights, xml);
} }
final int start = post.getInt("start",0); //indicates from where entries should be shown final int start = post.getInt("start",0); //indicates from where entries should be shown
final int num = post.getInt("num",10); //indicates how many entries should be shown final int num = post.getInt("num",10); //indicates how many entries should be shown
if(!hasRights){ if(!hasRights){
final userDB.Entry userentry = switchboard.userDB.proxyAuth((String)header.get("Authorization", "xxxxxx")); final userDB.Entry userentry = switchboard.userDB.proxyAuth((String)header.get("Authorization", "xxxxxx"));
if(userentry != null && userentry.hasRight(userDB.Entry.BLOG_RIGHT)){ if(userentry != null && userentry.hasRight(userDB.Entry.BLOG_RIGHT)){
hasRights=true; hasRights=true;
} else if(post.containsKey("login")) { } else if(post.containsKey("login")) {
//opens login window if login link is clicked - contrib [MN] //opens login window if login link is clicked - contrib [MN]
prop.put("AUTHENTICATE","admin log-in"); prop.put("AUTHENTICATE","admin log-in");
} }
} }
String pagename = post.get("page", DEFAULT_PAGE); String pagename = post.get("page", DEFAULT_PAGE);
final String ip = (String)header.get(httpHeader.CONNECTION_PROP_CLIENTIP, "127.0.0.1"); final String ip = (String)header.get(httpHeader.CONNECTION_PROP_CLIENTIP, "127.0.0.1");
String StrAuthor = post.get("author", ""); String StrAuthor = post.get("author", "");
if (StrAuthor.equals("anonymous")) { if (StrAuthor.equals("anonymous")) {
StrAuthor = switchboard.blogDB.guessAuthor(ip); StrAuthor = switchboard.blogDB.guessAuthor(ip);
if (StrAuthor == null || StrAuthor.length() == 0) { if (StrAuthor == null || StrAuthor.length() == 0) {
if (de.anomic.yacy.yacyCore.seedDB.mySeed() == null) { if (de.anomic.yacy.yacyCore.seedDB.mySeed() == null) {
StrAuthor = "anonymous"; StrAuthor = "anonymous";
} else { } else {
StrAuthor = de.anomic.yacy.yacyCore.seedDB.mySeed().get("Name", "anonymous"); StrAuthor = de.anomic.yacy.yacyCore.seedDB.mySeed().get("Name", "anonymous");
} }
} }
} }
byte[] author; byte[] author;
try { try {
author = StrAuthor.getBytes("UTF-8"); author = StrAuthor.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
author = StrAuthor.getBytes(); author = StrAuthor.getBytes();
} }
if(hasRights && post.containsKey("delete") && post.get("delete").equals("sure")) { if(hasRights && post.containsKey("delete") && post.get("delete").equals("sure")) {
page = switchboard.blogDB.read(pagename); page = switchboard.blogDB.read(pagename);
final Iterator<String> i = page.comments().iterator(); final Iterator<String> i = page.comments().iterator();
while(i.hasNext()) { while(i.hasNext()) {
switchboard.blogCommentDB.delete(i.next()); switchboard.blogCommentDB.delete(i.next());
} }
switchboard.blogDB.delete(pagename); switchboard.blogDB.delete(pagename);
pagename = DEFAULT_PAGE; pagename = DEFAULT_PAGE;
} }
if (post.containsKey("discard")) { if (post.containsKey("discard")) {
pagename = DEFAULT_PAGE; pagename = DEFAULT_PAGE;
} }
if (post.containsKey("submit") && (hasRights)) { if (post.containsKey("submit") && (hasRights)) {
// store a new/edited blog-entry // store a new/edited blog-entry
byte[] content; byte[] content;
try { try {
content = post.get("content", "").getBytes("UTF-8"); content = post.get("content", "").getBytes("UTF-8");
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
content = post.get("content", "").getBytes(); content = post.get("content", "").getBytes();
} }
Date date = null; Date date = null;
ArrayList<String> comments = null; ArrayList<String> comments = null;
//set name for new entry or date for old entry //set name for new entry or date for old entry
if(pagename.equals(DEFAULT_PAGE)) { if(pagename.equals(DEFAULT_PAGE)) {
pagename = String.valueOf(System.currentTimeMillis()); pagename = String.valueOf(System.currentTimeMillis());
} else { } else {
page = switchboard.blogDB.read(pagename); page = switchboard.blogDB.read(pagename);
comments = page.comments(); comments = page.comments();
date = page.date(); date = page.date();
} }
final String commentMode = post.get("commentMode", "1"); final String commentMode = post.get("commentMode", "1");
final String StrSubject = post.get("subject", ""); final String StrSubject = post.get("subject", "");
byte[] subject; byte[] subject;
try { try {
subject = StrSubject.getBytes("UTF-8"); subject = StrSubject.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
subject = StrSubject.getBytes(); subject = StrSubject.getBytes();
} }
switchboard.blogDB.write(switchboard.blogDB.newEntry(pagename, subject, author, ip, date, content, comments, commentMode)); switchboard.blogDB.write(switchboard.blogDB.newEntry(pagename, subject, author, ip, date, content, comments, commentMode));
// create a news message // create a news message
final HashMap<String, String> map = new HashMap<String, String>(); final HashMap<String, String> map = new HashMap<String, String>();
map.put("page", pagename); map.put("page", pagename);
map.put("subject", StrSubject.replace(',', ' ')); map.put("subject", StrSubject.replace(',', ' '));
map.put("author", StrAuthor.replace(',', ' ')); map.put("author", StrAuthor.replace(',', ' '));
yacyCore.newsPool.publishMyNews(yacyNewsRecord.newRecord(yacyNewsPool.CATEGORY_BLOG_ADD, map)); yacyCore.newsPool.publishMyNews(yacyNewsRecord.newRecord(yacyNewsPool.CATEGORY_BLOG_ADD, map));
} }
page = switchboard.blogDB.read(pagename); //maybe "if(page == null)" page = switchboard.blogDB.read(pagename); //maybe "if(page == null)"
if (post.containsKey("edit")) { if (post.containsKey("edit")) {
//edit an entry //edit an entry
if(hasRights) { if(hasRights) {
try { try {
prop.put("mode", "1"); //edit prop.put("mode", "1"); //edit
prop.put("mode_commentMode", page.getCommentMode()); prop.put("mode_commentMode", page.getCommentMode());
prop.putHTML("mode_author", new String(page.author(),"UTF-8"), xml); prop.putHTML("mode_author", new String(page.author(),"UTF-8"), xml);
prop.put("mode_pageid", page.key()); prop.put("mode_pageid", page.key());
prop.putHTML("mode_subject", new String(page.subject(), "UTF-8"), xml); prop.putHTML("mode_subject", new String(page.subject(), "UTF-8"), xml);
prop.put("mode_page-code", new String(page.page(), "UTF-8")); prop.put("mode_page-code", new String(page.page(), "UTF-8"));
} catch (UnsupportedEncodingException e) {} } catch (UnsupportedEncodingException e) {}
} }
else { else {
prop.put("mode", "3"); //access denied (no rights) prop.put("mode", "3"); //access denied (no rights)
} }
} }
else if(post.containsKey("preview")) { else if(post.containsKey("preview")) {
//preview the page //preview the page
if(hasRights) { if(hasRights) {
prop.put("mode", "2");//preview prop.put("mode", "2");//preview
prop.put("mode_commentMode", post.getInt("commentMode", 1)); prop.put("mode_commentMode", post.getInt("commentMode", 1));
prop.putHTML("mode_pageid", pagename, xml); prop.putHTML("mode_pageid", pagename, xml);
try { try {
prop.putHTML("mode_author", new String(author, "UTF-8"), xml); prop.putHTML("mode_author", new String(author, "UTF-8"), xml);
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
prop.putHTML("mode_author", new String(author), xml); prop.putHTML("mode_author", new String(author), xml);
} }
prop.putHTML("mode_subject", post.get("subject",""), xml); prop.putHTML("mode_subject", post.get("subject",""), xml);
prop.put("mode_date", dateString(new Date())); prop.put("mode_date", dateString(new Date()));
prop.putWiki("mode_page", post.get("content", "")); prop.putWiki("mode_page", post.get("content", ""));
prop.putHTML("mode_page-code", post.get("content", ""), xml); prop.putHTML("mode_page-code", post.get("content", ""), xml);
} }
else { else {
prop.put("mode", "3"); //access denied (no rights) prop.put("mode", "3"); //access denied (no rights)
} }
} }
else if(post.get("delete", "").equals("try")) { else if(post.get("delete", "").equals("try")) {
if(hasRights) { if(hasRights) {
prop.put("mode", "4"); prop.put("mode", "4");
prop.put("mode_pageid", pagename); prop.put("mode_pageid", pagename);
try { try {
prop.putHTML("mode_author",new String(page.author(), "UTF-8"), xml); prop.putHTML("mode_author",new String(page.author(), "UTF-8"), xml);
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
prop.putHTML("mode_author",new String(page.author()), xml); prop.putHTML("mode_author",new String(page.author()), xml);
} }
try { try {
prop.putHTML("mode_subject",new String(page.subject(),"UTF-8"), xml); prop.putHTML("mode_subject",new String(page.subject(),"UTF-8"), xml);
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
prop.putHTML("mode_subject",new String(page.subject()), xml); prop.putHTML("mode_subject",new String(page.subject()), xml);
} }
} }
else prop.put("mode", "3"); //access denied (no rights) else prop.put("mode", "3"); //access denied (no rights)
} }
else if (post.containsKey("import")) { else if (post.containsKey("import")) {
prop.put("mode", "5"); prop.put("mode", "5");
prop.put("mode_state", "0"); prop.put("mode_state", "0");
} }
else if (post.containsKey("xmlfile")) { else if (post.containsKey("xmlfile")) {
prop.put("mode", "5"); prop.put("mode", "5");
if(switchboard.blogDB.importXML(post.get("xmlfile$file"))) { if(switchboard.blogDB.importXML(post.get("xmlfile$file"))) {
prop.put("mode_state", "1"); prop.put("mode_state", "1");
} }
else { else {
prop.put("mode_state", "2"); prop.put("mode_state", "2");
} }
} }
else { else {
// show blog-entry/entries // show blog-entry/entries
prop.put("mode", "0"); //viewing prop.put("mode", "0"); //viewing
if(pagename.equals(DEFAULT_PAGE)) { if(pagename.equals(DEFAULT_PAGE)) {
// XXX: where are "peername" and "address" used in the template? // XXX: where are "peername" and "address" used in the template?
// XXX: "clientname" is already set to the peername, no need for a new setting // XXX: "clientname" is already set to the peername, no need for a new setting
prop.putHTML("peername", yacyCore.seedDB.mySeed().getName(), xml); prop.putHTML("peername", yacyCore.seedDB.mySeed().getName(), xml);
prop.put("address", address); prop.put("address", address);
//index all entries //index all entries
putBlogDefault(prop, switchboard, address, start, num, hasRights, xml); putBlogDefault(prop, switchboard, address, start, num, hasRights, xml);
} }
else { else {
//only show 1 entry //only show 1 entry
prop.put("mode_entries", "1"); prop.put("mode_entries", "1");
putBlogEntry(prop, page, address, 0, hasRights, xml); putBlogEntry(prop, page, address, 0, hasRights, xml);
} }
} }
// return rewrite properties // return rewrite properties
return prop; return prop;
} }
private static serverObjects putBlogDefault( private static serverObjects putBlogDefault(
final serverObjects prop, final serverObjects prop,
final plasmaSwitchboard switchboard, final plasmaSwitchboard switchboard,
final String address, final String address,
int start, int start,
int num, int num,
final boolean hasRights, final boolean hasRights,
final boolean xml) final boolean xml)
{ {
try { try {
final Iterator<String> i = switchboard.blogDB.keys(false); final Iterator<String> i = switchboard.blogDB.keys(false);
String pageid; String pageid;
int count = 0; //counts how many entries are shown to the user int count = 0; //counts how many entries are shown to the user
if(xml) num = 0; if(xml) num = 0;
final int nextstart = start+num; //indicates the starting offset for next results final int nextstart = start+num; //indicates the starting offset for next results
int prevstart = start-num; //indicates the starting offset for previous results int prevstart = start-num; //indicates the starting offset for previous results
boolean prev = false; //indicates if there were previous comments to the ones that are dispalyed boolean prev = false; //indicates if there were previous comments to the ones that are dispalyed
if (start > 0) prev = true; if (start > 0) prev = true;
while(i.hasNext() && (num == 0 || num > count)) { while(i.hasNext() && (num == 0 || num > count)) {
pageid = i.next(); pageid = i.next();
if(0 < start--) continue; if(0 < start--) continue;
putBlogEntry( putBlogEntry(
prop, prop,
switchboard.blogDB.read(pageid), switchboard.blogDB.read(pageid),
address, address,
count++, count++,
hasRights, hasRights,
xml); xml);
} }
prop.put("mode_entries", count); prop.put("mode_entries", count);
if(i.hasNext()) { if(i.hasNext()) {
prop.put("mode_moreentries", "1"); //more entries are availible prop.put("mode_moreentries", "1"); //more entries are availible
prop.put("mode_moreentries_start", nextstart); prop.put("mode_moreentries_start", nextstart);
prop.put("mode_moreentries_num", num); prop.put("mode_moreentries_num", num);
} else { } else {
prop.put("moreentries", "0"); prop.put("moreentries", "0");
} }
if(prev) { if(prev) {
prop.put("mode_preventries", "1"); prop.put("mode_preventries", "1");
if (prevstart < 0) prevstart = 0; if (prevstart < 0) prevstart = 0;
prop.put("mode_preventries_start", prevstart); prop.put("mode_preventries_start", prevstart);
prop.put("mode_preventries_num", num); prop.put("mode_preventries_num", num);
} else prop.put("mode_preventries", "0"); } else prop.put("mode_preventries", "0");
} catch (IOException e) { serverLog.logSevere("BLOG", "Error reading blog-DB", e); } } catch (IOException e) { serverLog.logSevere("BLOG", "Error reading blog-DB", e); }
return prop; return prop;
} }
private static serverObjects putBlogEntry( private static serverObjects putBlogEntry(
final serverObjects prop, final serverObjects prop,
final blogBoard.entry entry, final blogBoard.entry entry,
final String address, final String address,
final int number, final int number,
final boolean hasRights, final boolean hasRights,
final boolean xml) final boolean xml)
{ {
// subject // subject
try { try {
prop.putHTML("mode_entries_" + number + "_subject", new String(entry.subject(),"UTF-8"), xml); prop.putHTML("mode_entries_" + number + "_subject", new String(entry.subject(),"UTF-8"), xml);
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
prop.putHTML("mode_entries_" + number + "_subject", new String(entry.subject()), xml); prop.putHTML("mode_entries_" + number + "_subject", new String(entry.subject()), xml);
} }
// author // author
try { try {
prop.putHTML("mode_entries_" + number + "_author", new String(entry.author(),"UTF-8"), xml); prop.putHTML("mode_entries_" + number + "_author", new String(entry.author(),"UTF-8"), xml);
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
prop.putHTML("mode_entries_" + number + "_author", new String(entry.author()), xml); prop.putHTML("mode_entries_" + number + "_author", new String(entry.author()), xml);
} }
// comments // comments
if(entry.getCommentMode() == 0) { if(entry.getCommentMode() == 0) {
prop.put("mode_entries_" + number + "_commentsactive", "0"); prop.put("mode_entries_" + number + "_commentsactive", "0");
} else { } else {
prop.put("mode_entries_" + number + "_commentsactive", "1"); prop.put("mode_entries_" + number + "_commentsactive", "1");
prop.put("mode_entries_" + number + "_commentsactive_pageid", entry.key()); prop.put("mode_entries_" + number + "_commentsactive_pageid", entry.key());
prop.put("mode_entries_" + number + "_commentsactive_address", address); prop.put("mode_entries_" + number + "_commentsactive_address", address);
try { prop.put("mode_entries_" + number + "_commentsactive_comments", entry.commentsSize());
prop.put("mode_entries_" + number + "_commentsactive_comments", new String(entry.commentsSize(),"UTF-8")); }
} catch (UnsupportedEncodingException e) {
prop.put("mode_entries_" + number + "_commentsactive_comments", new String(entry.commentsSize())); prop.put("mode_entries_" + number + "_date", dateString(entry.date()));
} prop.put("mode_entries_" + number + "_rfc822date", httpc.dateString(entry.date()));
} prop.put("mode_entries_" + number + "_pageid", entry.key());
prop.put("mode_entries_" + number + "_address", address);
prop.put("mode_entries_" + number + "_date", dateString(entry.date())); prop.put("mode_entries_" + number + "_ip", entry.ip());
prop.put("mode_entries_" + number + "_rfc822date", httpc.dateString(entry.date()));
prop.put("mode_entries_" + number + "_pageid", entry.key()); if(xml) {
prop.put("mode_entries_" + number + "_address", address); prop.put("mode_entries_" + number + "_page", entry.page());
prop.put("mode_entries_" + number + "_ip", entry.ip()); prop.put("mode_entries_" + number + "_timestamp", entry.timestamp());
} else {
if(xml) { prop.putWiki("mode_entries_" + number + "_page", entry.page());
prop.put("mode_entries_" + number + "_page", entry.page()); }
prop.put("mode_entries_" + number + "_timestamp", entry.timestamp());
} else { if(hasRights) {
prop.putWiki("mode_entries_" + number + "_page", entry.page()); prop.put("mode_entries_" + number + "_admin", "1");
} prop.put("mode_entries_" + number + "_admin_pageid",entry.key());
} else {
if(hasRights) { prop.put("mode_entries_" + number + "_admin", "0");
prop.put("mode_entries_" + number + "_admin", "1"); }
prop.put("mode_entries_" + number + "_admin_pageid",entry.key());
} else { return prop;
prop.put("mode_entries_" + number + "_admin", "0"); }
} }
return prop;
}
}

@ -1,391 +1,387 @@
// Blog.java // Blog.java
// ----------------------- // -----------------------
// part of YACY // part of YACY
// (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
// //
// This File is contributed by Jan Sandbrink // This File is contributed by Jan Sandbrink
// Contains contributions from Marc Nause [MN] // Contains contributions from Marc Nause [MN]
// last change: 06.05.2006 // last change: 06.05.2006
// //
// 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
// the Free Software Foundation; either version 2 of the License, or // the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// //
// Using this software in any meaning (reading, learning, copying, compiling, // Using this software in any meaning (reading, learning, copying, compiling,
// running) means that you agree that the Author(s) is (are) not responsible // running) means that you agree that the Author(s) is (are) not responsible
// for cost, loss of data or any harm that may be caused directly or indirectly // for cost, loss of data or any harm that may be caused directly or indirectly
// by usage of this softare or this documentation. The usage of this software // by usage of this softare or this documentation. The usage of this software
// is on your own risk. The installation and usage (starting/running) of this // is on your own risk. The installation and usage (starting/running) of this
// software may allow other people or application to access your computer and // software may allow other people or application to access your computer and
// any attached devices and is highly dependent on the configuration of the // any attached devices and is highly dependent on the configuration of the
// software which must be done by the user of the software; the author(s) is // software which must be done by the user of the software; the author(s) is
// (are) also not responsible for proper configuration and usage of the // (are) also not responsible for proper configuration and usage of the
// software, even if provoked by documentation provided together with // software, even if provoked by documentation provided together with
// the software. // the software.
// //
// Any changes to this file according to the GPL as documented in the file // Any changes to this file according to the GPL as documented in the file
// gpl.txt aside this file in the shipment you received can be done to the // gpl.txt aside this file in the shipment you received can be done to the
// lines that follows this copyright notice here, but changes must not be // lines that follows this copyright notice here, but changes must not be
// done inside the copyright notive above. A re-distribution must contain // done inside the copyright notive above. A re-distribution must contain
// the intact and unchanged copyright notice. // the intact and unchanged copyright notice.
// Contributions and changes to the program code must be marked as such. // Contributions and changes to the program code must be marked as such.
// You must compile this file with // You must compile this file with
// javac -classpath .:../Classes Blacklist_p.java // javac -classpath .:../Classes Blacklist_p.java
// if the shell's current path is HTROOT // if the shell's current path is HTROOT
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import de.anomic.data.blogBoard; import de.anomic.data.blogBoard;
import de.anomic.data.blogBoardComments; import de.anomic.data.blogBoardComments;
import de.anomic.data.messageBoard; import de.anomic.data.messageBoard;
import de.anomic.data.userDB; import de.anomic.data.userDB;
import de.anomic.data.blogBoard.entry; import de.anomic.data.blogBoard.entry;
import de.anomic.http.httpHeader; import de.anomic.http.httpHeader;
import de.anomic.plasma.plasmaSwitchboard; import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverFileUtils; import de.anomic.server.serverFileUtils;
import de.anomic.server.serverObjects; import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch; import de.anomic.server.serverSwitch;
import de.anomic.server.logging.serverLog; import de.anomic.server.logging.serverLog;
import de.anomic.yacy.yacyCore; import de.anomic.yacy.yacyCore;
public class BlogComments { public class BlogComments {
private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
// TODO: make userdefined date/time-strings (localisation) // TODO: make userdefined date/time-strings (localisation)
public static String dateString(Date date) { public static String dateString(Date date) {
return SimpleFormatter.format(date); return SimpleFormatter.format(date);
} }
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) { public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) {
plasmaSwitchboard switchboard = (plasmaSwitchboard) env; plasmaSwitchboard switchboard = (plasmaSwitchboard) env;
serverObjects prop = new serverObjects(); serverObjects prop = new serverObjects();
blogBoard.entry page = null; blogBoard.entry page = null;
boolean hasRights = switchboard.verifyAuthentication(header, true); boolean hasRights = switchboard.verifyAuthentication(header, true);
if (hasRights) prop.put("mode_admin", "1"); if (hasRights) prop.put("mode_admin", "1");
else prop.put("mode_admin", "0"); else prop.put("mode_admin", "0");
if (post == null) { if (post == null) {
post = new serverObjects(); post = new serverObjects();
post.put("page", "blog_default"); post.put("page", "blog_default");
} }
if(!hasRights){ if(!hasRights){
userDB.Entry userentry = switchboard.userDB.proxyAuth((String)header.get("Authorization", "xxxxxx")); userDB.Entry userentry = switchboard.userDB.proxyAuth((String)header.get("Authorization", "xxxxxx"));
if(userentry != null && userentry.hasRight(userDB.Entry.BLOG_RIGHT)){ if(userentry != null && userentry.hasRight(userDB.Entry.BLOG_RIGHT)){
hasRights=true; hasRights=true;
} }
//opens login window if login link is clicked - contrib [MN] //opens login window if login link is clicked - contrib [MN]
else if(post.containsKey("login")){ else if(post.containsKey("login")){
prop.put("AUTHENTICATE","admin log-in"); prop.put("AUTHENTICATE","admin log-in");
} }
} }
String pagename = post.get("page", "blog_default"); String pagename = post.get("page", "blog_default");
String ip = post.get("CLIENTIP", "127.0.0.1"); String ip = post.get("CLIENTIP", "127.0.0.1");
String StrAuthor = post.get("author", "anonymous"); String StrAuthor = post.get("author", "anonymous");
if (StrAuthor.equals("anonymous")) { if (StrAuthor.equals("anonymous")) {
StrAuthor = switchboard.blogDB.guessAuthor(ip); StrAuthor = switchboard.blogDB.guessAuthor(ip);
if (StrAuthor == null || StrAuthor.length() == 0) { if (StrAuthor == null || StrAuthor.length() == 0) {
if (de.anomic.yacy.yacyCore.seedDB.mySeed() == null) { if (de.anomic.yacy.yacyCore.seedDB.mySeed() == null) {
StrAuthor = "anonymous"; StrAuthor = "anonymous";
} }
else { else {
StrAuthor = de.anomic.yacy.yacyCore.seedDB.mySeed().get("Name", "anonymous"); StrAuthor = de.anomic.yacy.yacyCore.seedDB.mySeed().get("Name", "anonymous");
} }
} }
} }
byte[] author; byte[] author;
try { try {
author = StrAuthor.getBytes("UTF-8"); author = StrAuthor.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
author = StrAuthor.getBytes(); author = StrAuthor.getBytes();
} }
page = switchboard.blogDB.read(pagename); //maybe "if(page == null)" page = switchboard.blogDB.read(pagename); //maybe "if(page == null)"
// comments not allowed // comments not allowed
if (page.getCommentMode() == 0) { if (page.getCommentMode() == 0) {
prop.put("mode_allow", 0); prop.put("mode_allow", 0);
} else { } else {
prop.put("mode_allow", 1); prop.put("mode_allow", 1);
} }
if (post.containsKey("submit") && page.getCommentMode() != 0) { if (post.containsKey("submit") && page.getCommentMode() != 0) {
// store a new/edited blog-entry // store a new/edited blog-entry
byte[] content; byte[] content;
if(!post.get("content", "").equals("")) if(!post.get("content", "").equals(""))
{ {
if(post.get("subject", "").equals("")) post.putHTML("subject", "no title"); if(post.get("subject", "").equals("")) post.putHTML("subject", "no title");
try { try {
content = post.get("content", "").getBytes("UTF-8"); content = post.get("content", "").getBytes("UTF-8");
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
content = post.get("content", "").getBytes(); content = post.get("content", "").getBytes();
} }
Date date = null; Date date = null;
//set name for new entry or date for old entry //set name for new entry or date for old entry
String StrSubject = post.get("subject", ""); String StrSubject = post.get("subject", "");
byte[] subject; byte[] subject;
try { try {
subject = StrSubject.getBytes("UTF-8"); subject = StrSubject.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
subject = StrSubject.getBytes(); subject = StrSubject.getBytes();
} }
String commentID = String.valueOf(System.currentTimeMillis()); String commentID = String.valueOf(System.currentTimeMillis());
entry blogEntry = switchboard.blogDB.read(pagename); entry blogEntry = switchboard.blogDB.read(pagename);
blogEntry.addComment(commentID); blogEntry.addComment(commentID);
switchboard.blogDB.write(blogEntry); switchboard.blogDB.write(blogEntry);
switchboard.blogCommentDB.write(switchboard.blogCommentDB.newEntry(commentID, subject, author, ip, date, content)); switchboard.blogCommentDB.write(switchboard.blogCommentDB.newEntry(commentID, subject, author, ip, date, content));
prop.put("LOCATION","BlogComments.html?page=" + pagename); prop.put("LOCATION","BlogComments.html?page=" + pagename);
messageBoard.entry msgEntry = null; messageBoard.entry msgEntry = null;
try { try {
switchboard.messageDB.write(msgEntry = switchboard.messageDB.newEntry( switchboard.messageDB.write(msgEntry = switchboard.messageDB.newEntry(
"blogComment", "blogComment",
StrAuthor, StrAuthor,
yacyCore.seedDB.mySeed().hash, yacyCore.seedDB.mySeed().hash,
yacyCore.seedDB.mySeed().getName(), yacyCore.seedDB.mySeed().hash, yacyCore.seedDB.mySeed().getName(), yacyCore.seedDB.mySeed().hash,
"new blog comment: " + new String(blogEntry.subject(),"UTF-8"), content)); "new blog comment: " + new String(blogEntry.subject(),"UTF-8"), content));
} catch (UnsupportedEncodingException e1) { } catch (UnsupportedEncodingException e1) {
switchboard.messageDB.write(msgEntry = switchboard.messageDB.newEntry( switchboard.messageDB.write(msgEntry = switchboard.messageDB.newEntry(
"blogComment", "blogComment",
StrAuthor, StrAuthor,
yacyCore.seedDB.mySeed().hash, yacyCore.seedDB.mySeed().hash,
yacyCore.seedDB.mySeed().getName(), yacyCore.seedDB.mySeed().hash, yacyCore.seedDB.mySeed().getName(), yacyCore.seedDB.mySeed().hash,
"new blog comment: " + new String(blogEntry.subject()), content)); "new blog comment: " + new String(blogEntry.subject()), content));
} }
messageForwardingViaEmail(env, msgEntry); messageForwardingViaEmail(env, msgEntry);
// finally write notification // finally write notification
File notifierSource = new File(switchboard.getRootPath(), switchboard.getConfig("htRootPath","htroot") + "/env/grafics/message.gif"); File notifierSource = new File(switchboard.getRootPath(), switchboard.getConfig("htRootPath","htroot") + "/env/grafics/message.gif");
File notifierDest = new File(switchboard.getConfigPath("htDocsPath", "DATA/HTDOCS"), "notifier.gif"); File notifierDest = new File(switchboard.getConfigPath("htDocsPath", "DATA/HTDOCS"), "notifier.gif");
try { try {
serverFileUtils.copy(notifierSource, notifierDest); serverFileUtils.copy(notifierSource, notifierDest);
} catch (IOException e) { } catch (IOException e) {
serverLog.logSevere("MESSAGE", "NEW MESSAGE ARRIVED! (error: " + e.getMessage() + ")"); serverLog.logSevere("MESSAGE", "NEW MESSAGE ARRIVED! (error: " + e.getMessage() + ")");
} }
} }
} }
if(hasRights && post.containsKey("delete") && post.containsKey("page") && post.containsKey("comment")) { if(hasRights && post.containsKey("delete") && post.containsKey("page") && post.containsKey("comment")) {
if(page.removeComment((String) post.get("comment"))) { if(page.removeComment((String) post.get("comment"))) {
switchboard.blogCommentDB.delete((String) post.get("comment")); switchboard.blogCommentDB.delete((String) post.get("comment"));
} }
} }
if(hasRights && post.containsKey("allow") && post.containsKey("page") && post.containsKey("comment")) { if(hasRights && post.containsKey("allow") && post.containsKey("page") && post.containsKey("comment")) {
blogBoardComments.CommentEntry entry = switchboard.blogCommentDB.read((String) post.get("comment")); blogBoardComments.CommentEntry entry = switchboard.blogCommentDB.read((String) post.get("comment"));
entry.allow(); entry.allow();
switchboard.blogCommentDB.write(entry); switchboard.blogCommentDB.write(entry);
} }
if(post.containsKey("preview") && page.getCommentMode() != 0) { if(post.containsKey("preview") && page.getCommentMode() != 0) {
//preview the page //preview the page
prop.put("mode", "1");//preview prop.put("mode", "1");//preview
prop.put("mode_pageid", pagename); prop.put("mode_pageid", pagename);
prop.put("mode_allow_pageid", pagename); prop.put("mode_allow_pageid", pagename);
try { try {
prop.putHTML("mode_author", new String(author, "UTF-8")); prop.putHTML("mode_author", new String(author, "UTF-8"));
prop.putHTML("mode_allow_author", new String(author, "UTF-8")); prop.putHTML("mode_allow_author", new String(author, "UTF-8"));
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
prop.putHTML("mode_author", new String(author)); prop.putHTML("mode_author", new String(author));
prop.putHTML("mode_allow_author", new String(author)); prop.putHTML("mode_allow_author", new String(author));
} }
prop.putHTML("mode_subject", post.get("subject","")); prop.putHTML("mode_subject", post.get("subject",""));
prop.put("mode_date", dateString(new Date())); prop.put("mode_date", dateString(new Date()));
prop.putWiki("mode_page", post.get("content", "")); prop.putWiki("mode_page", post.get("content", ""));
prop.put("mode_page-code", post.get("content", "")); prop.put("mode_page-code", post.get("content", ""));
} }
else { else {
// show blog-entry/entries // show blog-entry/entries
prop.put("mode", "0"); //viewing prop.put("mode", "0"); //viewing
if(pagename.equals("blog_default")) { if(pagename.equals("blog_default")) {
prop.put("LOCATION","Blog.html"); prop.put("LOCATION","Blog.html");
} }
else { else {
//show 1 blog entry //show 1 blog entry
prop.put("mode_pageid", page.key()); prop.put("mode_pageid", page.key());
prop.put("mode_allow_pageid", pagename); prop.put("mode_allow_pageid", pagename);
try { try {
prop.putHTML("mode_subject", new String(page.subject(),"UTF-8")); prop.putHTML("mode_subject", new String(page.subject(),"UTF-8"));
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
prop.putHTML("mode_subject", new String(page.subject())); prop.putHTML("mode_subject", new String(page.subject()));
} }
try { try {
prop.putHTML("mode_author", new String(page.author(),"UTF-8")); prop.putHTML("mode_author", new String(page.author(),"UTF-8"));
prop.putHTML("mode_allow_author", new String(author, "UTF-8")); prop.putHTML("mode_allow_author", new String(author, "UTF-8"));
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
prop.putHTML("mode_author", new String(page.author())); prop.putHTML("mode_author", new String(page.author()));
prop.putHTML("mode_allow_author", new String(author)); prop.putHTML("mode_allow_author", new String(author));
} }
try { prop.put("mode_comments", page.commentsSize());
prop.put("mode_comments", new String(page.commentsSize(),"UTF-8")); prop.put("mode_date", dateString(page.date()));
} catch (UnsupportedEncodingException e) { prop.putWiki("mode_page", page.page());
prop.put("mode_comments", new String(page.commentsSize())); if(hasRights) {
} prop.put("mode_admin", "1");
prop.put("mode_date", dateString(page.date())); prop.put("mode_admin_pageid", page.key());
prop.putWiki("mode_page", page.page()); }
if(hasRights) { //show all commments
prop.put("mode_admin", "1"); try {
prop.put("mode_admin_pageid", page.key()); Iterator<String> i = page.comments().iterator();
} int commentMode = page.getCommentMode();
//show all commments String pageid;
try { blogBoardComments.CommentEntry entry;
Iterator<String> i = page.comments().iterator(); boolean xml = false;
int commentMode = page.getCommentMode(); if(post.containsKey("xml")) {
String pageid; xml = true;
blogBoardComments.CommentEntry entry; }
boolean xml = false; int count = 0; //counts how many entries are shown to the user
if(post.containsKey("xml")) { int start = post.getInt("start",0); //indicates from where entries should be shown
xml = true; int num = post.getInt("num",10); //indicates how many entries should be shown
} boolean prev = false; //indicates if there were previous comments to the ones that are dispalyed
int count = 0; //counts how many entries are shown to the user if(xml) num = 0;
int start = post.getInt("start",0); //indicates from where entries should be shown if (start < 0) start = 0;
int num = post.getInt("num",10); //indicates how many entries should be shown if (start > 1) prev = true;
boolean prev = false; //indicates if there were previous comments to the ones that are dispalyed int nextstart = start+num; //indicates the starting offset for next results
if(xml) num = 0; int prevstart = start-num; //indicates the starting offset for previous results
if (start < 1) start = 1; // dirrrty fix for incorrect comment count, need to find reason while(i.hasNext() && count < num) {
if (start > 1) prev = true;
int nextstart = start+num; //indicates the starting offset for next results pageid = i.next();
int prevstart = start-num; //indicates the starting offset for previous results
while(i.hasNext() && count < num) { if(start > 0) {
start--;
pageid = i.next(); continue;
}
if(start > 0) {
start--; entry = switchboard.blogCommentDB.read(pageid);
continue;
} if (commentMode == 2 && !hasRights && !entry.isAllowed())
continue;
entry = switchboard.blogCommentDB.read(pageid);
prop.put("mode", "0");
if (commentMode == 2 && !hasRights && !entry.isAllowed()) prop.put("mode_entries_"+count+"_pageid", entry.key());
continue; if(!xml) {
prop.putHTML("mode_entries_"+count+"_subject", new String(entry.subject(),"UTF-8"));
prop.put("mode", "0"); prop.putHTML("mode_entries_"+count+"_author", new String(entry.author(),"UTF-8"));
prop.put("mode_entries_"+count+"_pageid", entry.key()); prop.putWiki("mode_entries_"+count+"_page", entry.page());
if(!xml) { }
prop.putHTML("mode_entries_"+count+"_subject", new String(entry.subject(),"UTF-8")); else {
prop.putHTML("mode_entries_"+count+"_author", new String(entry.author(),"UTF-8")); prop.putHTML("mode_entries_"+count+"_subject", new String(entry.subject(),"UTF-8"));
prop.putWiki("mode_entries_"+count+"_page", entry.page()); prop.putHTML("mode_entries_"+count+"_author", new String(entry.author(),"UTF-8"));
} prop.put("mode_entries_"+count+"_page", entry.page());
else { prop.put("mode_entries_"+count+"_timestamp", entry.timestamp());
prop.putHTML("mode_entries_"+count+"_subject", new String(entry.subject(),"UTF-8")); }
prop.putHTML("mode_entries_"+count+"_author", new String(entry.author(),"UTF-8")); prop.put("mode_entries_"+count+"_date", dateString(entry.date()));
prop.put("mode_entries_"+count+"_page", entry.page()); prop.put("mode_entries_"+count+"_ip", entry.ip());
prop.put("mode_entries_"+count+"_timestamp", entry.timestamp()); if(hasRights) {
} prop.put("mode_entries_"+count+"_admin", "1");
prop.put("mode_entries_"+count+"_date", dateString(entry.date())); prop.put("mode_entries_"+count+"_admin_pageid", page.key());
prop.put("mode_entries_"+count+"_ip", entry.ip()); prop.put("mode_entries_"+count+"_admin_commentid", pageid);
if(hasRights) { if(!entry.isAllowed()) {
prop.put("mode_entries_"+count+"_admin", "1"); prop.put("mode_entries_"+count+"_admin_moderate", "1");
prop.put("mode_entries_"+count+"_admin_pageid", page.key()); prop.put("mode_entries_"+count+"_admin_moderate_pageid", page.key());
prop.put("mode_entries_"+count+"_admin_commentid", pageid); prop.put("mode_entries_"+count+"_admin_moderate_commentid", pageid);
if(!entry.isAllowed()) {
prop.put("mode_entries_"+count+"_admin_moderate", "1"); }
prop.put("mode_entries_"+count+"_admin_moderate_pageid", page.key()); }
prop.put("mode_entries_"+count+"_admin_moderate_commentid", pageid); else prop.put("mode_entries_"+count+"_admin", 0);
++count;
} }
} prop.put("mode_entries", count);
else prop.put("mode_entries_"+count+"_admin", 0); if(i.hasNext()) {
++count; prop.put("mode_moreentries", "1"); //more entries are availible
} prop.put("mode_moreentries_start", nextstart);
prop.put("mode_entries", count); prop.put("mode_moreentries_num", num);
if(i.hasNext()) { prop.put("mode_moreentries_pageid", page.key());
prop.put("mode_moreentries", "1"); //more entries are availible }
prop.put("mode_moreentries_start", nextstart); else prop.put("mode_moreentries", "0");
prop.put("mode_moreentries_num", num); if(prev) {
prop.put("mode_moreentries_pageid", page.key()); prop.put("mode_preventries", "1");
} if (prevstart < 0) prevstart = 0;
else prop.put("mode_moreentries", "0"); prop.put("mode_preventries_start", prevstart);
if(prev) { prop.put("mode_preventries_num", num);
prop.put("mode_preventries", "1"); prop.put("mode_preventries_pageid", page.key());
if (prevstart < 0) prevstart = 0; } else prop.put("mode_preventries", "0");
prop.put("mode_preventries_start", prevstart); } catch (IOException e) {
prop.put("mode_preventries_num", num);
prop.put("mode_preventries_pageid", page.key()); }
} else prop.put("mode_preventries", "0"); }
} catch (IOException e) { }
} // return rewrite properties
} return prop;
} }
// return rewrite properties private static void messageForwardingViaEmail(serverSwitch env, messageBoard.entry msgEntry) {
return prop; try {
} if (!Boolean.valueOf(env.getConfig("msgForwardingEnabled","false")).booleanValue()) return;
private static void messageForwardingViaEmail(serverSwitch env, messageBoard.entry msgEntry) { // getting the recipient address
try { String sendMailTo = env.getConfig("msgForwardingTo","root@localhost").trim();
if (!Boolean.valueOf(env.getConfig("msgForwardingEnabled","false")).booleanValue()) return;
// getting the sendmail configuration
// getting the recipient address String sendMailStr = env.getConfig("msgForwardingCmd","/usr/bin/sendmail")+" "+sendMailTo;
String sendMailTo = env.getConfig("msgForwardingTo","root@localhost").trim(); String[] sendMail = sendMailStr.trim().split(" ");
// getting the sendmail configuration // building the message text
String sendMailStr = env.getConfig("msgForwardingCmd","/usr/bin/sendmail")+" "+sendMailTo; StringBuffer emailTxt = new StringBuffer();
String[] sendMail = sendMailStr.trim().split(" "); emailTxt.append("To: ")
.append(sendMailTo)
// building the message text .append("\nFrom: ")
StringBuffer emailTxt = new StringBuffer(); .append("yacy@")
emailTxt.append("To: ") .append(yacyCore.seedDB.mySeed().getName())
.append(sendMailTo) .append("\nSubject: [YaCy] ")
.append("\nFrom: ") .append(msgEntry.subject().replace('\n', ' '))
.append("yacy@") .append("\nDate: ")
.append(yacyCore.seedDB.mySeed().getName()) .append(msgEntry.date())
.append("\nSubject: [YaCy] ") .append("\n")
.append(msgEntry.subject().replace('\n', ' ')) .append("\nMessage from: ")
.append("\nDate: ") .append(msgEntry.author())
.append(msgEntry.date()) .append("/")
.append("\n") .append(msgEntry.authorHash())
.append("\nMessage from: ") .append("\nMessage to: ")
.append(msgEntry.author()) .append(msgEntry.recipient())
.append("/") .append("/")
.append(msgEntry.authorHash()) .append(msgEntry.recipientHash())
.append("\nMessage to: ") .append("\nCategory: ")
.append(msgEntry.recipient()) .append(msgEntry.category())
.append("/") .append("\n===================================================================\n")
.append(msgEntry.recipientHash()) .append(new String(msgEntry.message()));
.append("\nCategory: ")
.append(msgEntry.category()) Process process=Runtime.getRuntime().exec(sendMail);
.append("\n===================================================================\n") PrintWriter email = new PrintWriter(process.getOutputStream());
.append(new String(msgEntry.message())); email.print(new String(emailTxt));
email.close();
Process process=Runtime.getRuntime().exec(sendMail); } catch (Exception e) {
PrintWriter email = new PrintWriter(process.getOutputStream()); yacyCore.log.logWarning("message: message forwarding via email failed. ",e);
email.print(new String(emailTxt)); }
email.close(); }
} catch (Exception e) { }
yacyCore.log.logWarning("message: message forwarding via email failed. ",e);
}
}
}

@ -1,348 +1,344 @@
// wikiBoard.java // wikiBoard.java
// ------------------------------------- // -------------------------------------
// (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: 20.07.2004 // last major change: 20.07.2004
// //
// 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
// the Free Software Foundation; either version 2 of the License, or // the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// //
// Using this software in any meaning (reading, learning, copying, compiling, // Using this software in any meaning (reading, learning, copying, compiling,
// running) means that you agree that the Author(s) is (are) not responsible // running) means that you agree that the Author(s) is (are) not responsible
// for cost, loss of data or any harm that may be caused directly or indirectly // for cost, loss of data or any harm that may be caused directly or indirectly
// by usage of this softare or this documentation. The usage of this software // by usage of this softare or this documentation. The usage of this software
// is on your own risk. The installation and usage (starting/running) of this // is on your own risk. The installation and usage (starting/running) of this
// software may allow other people or application to access your computer and // software may allow other people or application to access your computer and
// any attached devices and is highly dependent on the configuration of the // any attached devices and is highly dependent on the configuration of the
// software which must be done by the user of the software; the author(s) is // software which must be done by the user of the software; the author(s) is
// (are) also not responsible for proper configuration and usage of the // (are) also not responsible for proper configuration and usage of the
// software, even if provoked by documentation provided together with // software, even if provoked by documentation provided together with
// the software. // the software.
// //
// Any changes to this file according to the GPL as documented in the file // Any changes to this file according to the GPL as documented in the file
// gpl.txt aside this file in the shipment you received can be done to the // gpl.txt aside this file in the shipment you received can be done to the
// lines that follows this copyright notice here, but changes must not be // lines that follows this copyright notice here, but changes must not be
// done inside the copyright notive above. A re-distribution must contain // done inside the copyright notive above. A re-distribution must contain
// the intact and unchanged copyright notice. // the intact and unchanged copyright notice.
// Contributions and changes to the program code must be marked as such. // Contributions and changes to the program code must be marked as such.
// This file is contributed by Jan Sandbrink // This file is contributed by Jan Sandbrink
// based on the Code of wikiBoard.java // based on the Code of wikiBoard.java
package de.anomic.data; package de.anomic.data;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import de.anomic.kelondro.kelondroBase64Order; import de.anomic.kelondro.kelondroBase64Order;
import de.anomic.kelondro.kelondroDyn; import de.anomic.kelondro.kelondroDyn;
import de.anomic.kelondro.kelondroMapObjects; import de.anomic.kelondro.kelondroMapObjects;
import de.anomic.kelondro.kelondroNaturalOrder; import de.anomic.kelondro.kelondroNaturalOrder;
import de.anomic.server.serverDate; import de.anomic.server.serverDate;
public class blogBoard { public class blogBoard {
public static final int keyLength = 64; public static final int keyLength = 64;
private static final int recordSize = 512; private static final int recordSize = 512;
private kelondroMapObjects datbase = null; private kelondroMapObjects datbase = null;
public blogBoard(File actpath, long preloadTime) { public blogBoard(File actpath, long preloadTime) {
new File(actpath.getParent()).mkdir(); new File(actpath.getParent()).mkdir();
if (datbase == null) { if (datbase == null) {
datbase = new kelondroMapObjects(new kelondroDyn(actpath, true, true, preloadTime, keyLength, recordSize, '_', kelondroNaturalOrder.naturalOrder, true, false, false), 500); datbase = new kelondroMapObjects(new kelondroDyn(actpath, true, true, preloadTime, keyLength, recordSize, '_', kelondroNaturalOrder.naturalOrder, true, false, false), 500);
} }
} }
public int size() { public int size() {
return datbase.size(); return datbase.size();
} }
public void close() { public void close() {
datbase.close(); datbase.close();
} }
private static String normalize(String key) { private static String normalize(String key) {
if (key == null) return "null"; if (key == null) return "null";
return key.trim().toLowerCase(); return key.trim().toLowerCase();
} }
public static String webalize(String key) { public static String webalize(String key) {
if (key == null) return "null"; if (key == null) return "null";
key = key.trim().toLowerCase(); key = key.trim().toLowerCase();
int p; int p;
while ((p = key.indexOf(" ")) >= 0) while ((p = key.indexOf(" ")) >= 0)
key = key.substring(0, p) + "%20" + key.substring(p +1); key = key.substring(0, p) + "%20" + key.substring(p +1);
return key; return key;
} }
public String guessAuthor(String ip) { public String guessAuthor(String ip) {
return wikiBoard.guessAuthor(ip); return wikiBoard.guessAuthor(ip);
} }
public entry newEntry(String key, byte[] subject, byte[] author, String ip, Date date, byte[] page, ArrayList<String> comments, String commentMode) { public entry newEntry(String key, byte[] subject, byte[] author, String ip, Date date, byte[] page, ArrayList<String> comments, String commentMode) {
return new entry(normalize(key), subject, author, ip, date, page, comments, commentMode); return new entry(normalize(key), subject, author, ip, date, page, comments, commentMode);
} }
public class entry { public class entry {
String key; String key;
HashMap<String, String> record; HashMap<String, String> record;
public entry(String nkey, byte[] subject, byte[] author, String ip, Date date, byte[] page, ArrayList<String> comments, String commentMode) { public entry(String nkey, byte[] subject, byte[] author, String ip, Date date, byte[] page, ArrayList<String> comments, String commentMode) {
record = new HashMap<String, String>(); record = new HashMap<String, String>();
key = nkey; key = nkey;
if (key.length() > keyLength) key = key.substring(0, keyLength); if (key.length() > keyLength) key = key.substring(0, keyLength);
if(date == null) date = new Date(); if(date == null) date = new Date();
record.put("date", serverDate.formatShortSecond(date)); record.put("date", serverDate.formatShortSecond(date));
if (subject == null) record.put("subject",""); if (subject == null) record.put("subject","");
else record.put("subject", kelondroBase64Order.enhancedCoder.encode(subject)); else record.put("subject", kelondroBase64Order.enhancedCoder.encode(subject));
if (author == null) record.put("author",""); if (author == null) record.put("author","");
else record.put("author", kelondroBase64Order.enhancedCoder.encode(author)); else record.put("author", kelondroBase64Order.enhancedCoder.encode(author));
if ((ip == null) || (ip.length() == 0)) ip = ""; if ((ip == null) || (ip.length() == 0)) ip = "";
record.put("ip", ip); record.put("ip", ip);
if (page == null) record.put("page", ""); if (page == null) record.put("page", "");
else record.put("page", kelondroBase64Order.enhancedCoder.encode(page)); else record.put("page", kelondroBase64Order.enhancedCoder.encode(page));
if (comments == null) record.put("comments", listManager.collection2string(new ArrayList<String>())); if (comments == null) record.put("comments", listManager.collection2string(new ArrayList<String>()));
else record.put("comments", listManager.collection2string(comments)); else record.put("comments", listManager.collection2string(comments));
if (commentMode == null) record.put("commentMode", "1"); if (commentMode == null) record.put("commentMode", "1");
else record.put("commentMode", commentMode); else record.put("commentMode", commentMode);
wikiBoard.setAuthor(ip, new String(author)); wikiBoard.setAuthor(ip, new String(author));
//System.out.println("DEBUG: setting author " + author + " for ip = " + ip + ", authors = " + authors.toString()); //System.out.println("DEBUG: setting author " + author + " for ip = " + ip + ", authors = " + authors.toString());
} }
private entry(String key, HashMap<String, String> record) { private entry(String key, HashMap<String, String> record) {
this.key = key; this.key = key;
this.record = record; this.record = record;
if (this.record.get("comments")==null) this.record.put("comments", listManager.collection2string(new ArrayList<String>())); if (this.record.get("comments")==null) this.record.put("comments", listManager.collection2string(new ArrayList<String>()));
if (this.record.get("commentMode")==null || this.record.get("commentMode").equals("")) this.record.put("commentMode", "1"); if (this.record.get("commentMode")==null || this.record.get("commentMode").equals("")) this.record.put("commentMode", "1");
} }
public String key() { public String key() {
return key; return key;
} }
public byte[] subject() { public byte[] subject() {
String m = record.get("subject"); String m = record.get("subject");
if (m == null) return new byte[0]; if (m == null) return new byte[0];
byte[] b = kelondroBase64Order.enhancedCoder.decode(m, "de.anomic.data.blogBoard.subject()"); byte[] b = kelondroBase64Order.enhancedCoder.decode(m, "de.anomic.data.blogBoard.subject()");
if (b == null) return "".getBytes(); if (b == null) return "".getBytes();
return b; return b;
} }
public Date date() { public Date date() {
try { try {
String c = record.get("date"); String c = record.get("date");
if (c == null) { if (c == null) {
System.out.println("DEBUG - ERROR: date field missing in blogBoard"); System.out.println("DEBUG - ERROR: date field missing in blogBoard");
return new Date(); return new Date();
} }
return serverDate.parseShortSecond(c); return serverDate.parseShortSecond(c);
} catch (ParseException e) { } catch (ParseException e) {
return new Date(); return new Date();
} }
} }
public String timestamp() { public String timestamp() {
String c = record.get("date"); String c = record.get("date");
if (c == null) { if (c == null) {
System.out.println("DEBUG - ERROR: date field missing in blogBoard"); System.out.println("DEBUG - ERROR: date field missing in blogBoard");
return serverDate.formatShortSecond(); return serverDate.formatShortSecond();
} }
return c; return c;
} }
public byte[] author() { public byte[] author() {
String m = record.get("author"); String m = record.get("author");
if (m == null) return new byte[0]; if (m == null) return new byte[0];
byte[] b = kelondroBase64Order.enhancedCoder.decode(m, "de.anomic.data.blogBoard.author()"); byte[] b = kelondroBase64Order.enhancedCoder.decode(m, "de.anomic.data.blogBoard.author()");
if (b == null) return "".getBytes(); if (b == null) return "".getBytes();
return b; return b;
} }
public byte[] commentsSize() { public int commentsSize() {
ArrayList<String> m = listManager.string2arraylist(record.get("comments")); ArrayList<String> m = listManager.string2arraylist(record.get("comments"));
if (m == null) return new byte[0]; return m.size();
byte[] b = Integer.toString(m.size()).getBytes(); }
if (b == null) return "".getBytes();
return b; public ArrayList<String> comments() {
} ArrayList<String> m = listManager.string2arraylist(record.get("comments"));
return m;
public ArrayList<String> comments() { }
ArrayList<String> m = listManager.string2arraylist(record.get("comments"));
if (m == null) return new ArrayList<String>(); public String ip() {
return m; String a = record.get("ip");
} if (a == null) return "127.0.0.1";
return a;
public String ip() { }
String a = record.get("ip");
if (a == null) return "127.0.0.1"; public byte[] page() {
return a; String m = record.get("page");
} if (m == null) return new byte[0];
byte[] b = kelondroBase64Order.enhancedCoder.decode(m, "de.anomic.data.blogBoard.page()");
public byte[] page() { if (b == null) return "".getBytes();
String m = record.get("page"); return b;
if (m == null) return new byte[0]; }
byte[] b = kelondroBase64Order.enhancedCoder.decode(m, "de.anomic.data.blogBoard.page()");
if (b == null) return "".getBytes(); public void addComment(String commentID) {
return b; ArrayList<String> comments = listManager.string2arraylist(record.get("comments"));
} comments.add(commentID);
record.put("comments", listManager.collection2string(comments));
public void addComment(String commentID) { }
ArrayList<String> comments = listManager.string2arraylist(record.get("comments"));
comments.add(commentID); public boolean removeComment(String commentID) {
record.put("comments", listManager.collection2string(comments)); ArrayList<String> comments = listManager.string2arraylist(record.get("comments"));
} boolean success = comments.remove(commentID);
record.put("comments", listManager.collection2string(comments));
public boolean removeComment(String commentID) { return success;
ArrayList<String> comments = listManager.string2arraylist(record.get("comments")); }
boolean success = comments.remove(commentID);
record.put("comments", listManager.collection2string(comments)); public int getCommentMode(){
return success; return Integer.parseInt(record.get("commentMode"));
} }
}
public int getCommentMode(){
return Integer.parseInt(record.get("commentMode")); public String write(entry page) {
} // writes a new page and returns key
} try {
datbase.set(page.key, page.record);
public String write(entry page) { return page.key;
// writes a new page and returns key } catch (IOException e) {
try { return null;
datbase.set(page.key, page.record); }
return page.key; }
} catch (IOException e) {
return null; public entry read(String key) {
} return read(key, datbase);
} }
public entry read(String key) { private entry read(String key, kelondroMapObjects base) {
return read(key, datbase); key = normalize(key);
} if (key.length() > keyLength) key = key.substring(0, keyLength);
HashMap<String, String> record = base.getMap(key);
private entry read(String key, kelondroMapObjects base) { if (record == null) return newEntry(key, "".getBytes(), "anonymous".getBytes(), "127.0.0.1", new Date(), "".getBytes(), null, null);
key = normalize(key); return new entry(key, record);
if (key.length() > keyLength) key = key.substring(0, keyLength); }
HashMap<String, String> record = base.getMap(key);
if (record == null) return newEntry(key, "".getBytes(), "anonymous".getBytes(), "127.0.0.1", new Date(), "".getBytes(), null, null); public boolean importXML(String input) {
return new entry(key, record); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
} try {
DocumentBuilder builder = factory.newDocumentBuilder();
public boolean importXML(String input) { Document doc = builder.parse(new ByteArrayInputStream(input.getBytes()));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); return parseXMLimport(doc);
try { } catch (ParserConfigurationException e) {
DocumentBuilder builder = factory.newDocumentBuilder(); } catch (SAXException e) {
Document doc = builder.parse(new ByteArrayInputStream(input.getBytes())); } catch (IOException e) {}
return parseXMLimport(doc);
} catch (ParserConfigurationException e) { return false;
} catch (SAXException e) { }
} catch (IOException e) {}
private boolean parseXMLimport(Document doc) {
return false; if(!doc.getDocumentElement().getTagName().equals("blog"))
} return false;
private boolean parseXMLimport(Document doc) { NodeList items = doc.getDocumentElement().getElementsByTagName("item");
if(!doc.getDocumentElement().getTagName().equals("blog")) if(items.getLength() == 0)
return false; return false;
NodeList items = doc.getDocumentElement().getElementsByTagName("item"); for(int i=0;i<items.getLength();++i) {
if(items.getLength() == 0) String key = null, ip = null, StrSubject = null, StrAuthor = null, StrPage = null, StrDate = null;
return false; Date date = null;
for(int i=0;i<items.getLength();++i) { if(!items.item(i).getNodeName().equals("item"))
String key = null, ip = null, StrSubject = null, StrAuthor = null, StrPage = null, StrDate = null; continue;
Date date = null;
NodeList currentNodeChildren = items.item(i).getChildNodes();
if(!items.item(i).getNodeName().equals("item"))
continue; for(int j=0;j<currentNodeChildren.getLength();++j) {
Node currentNode = currentNodeChildren.item(j);
NodeList currentNodeChildren = items.item(i).getChildNodes(); if(currentNode.getNodeName().equals("id"))
key = currentNode.getFirstChild().getNodeValue();
for(int j=0;j<currentNodeChildren.getLength();++j) { else if(currentNode.getNodeName().equals("ip"))
Node currentNode = currentNodeChildren.item(j); ip = currentNode.getFirstChild().getNodeValue();
if(currentNode.getNodeName().equals("id")) else if(currentNode.getNodeName().equals("timestamp"))
key = currentNode.getFirstChild().getNodeValue(); StrDate = currentNode.getFirstChild().getNodeValue();
else if(currentNode.getNodeName().equals("ip")) else if(currentNode.getNodeName().equals("subject"))
ip = currentNode.getFirstChild().getNodeValue(); StrSubject = currentNode.getFirstChild().getNodeValue();
else if(currentNode.getNodeName().equals("timestamp")) else if(currentNode.getNodeName().equals("author"))
StrDate = currentNode.getFirstChild().getNodeValue(); StrAuthor = currentNode.getFirstChild().getNodeValue();
else if(currentNode.getNodeName().equals("subject")) else if(currentNode.getNodeName().equals("content"))
StrSubject = currentNode.getFirstChild().getNodeValue(); StrPage = currentNode.getFirstChild().getNodeValue();
else if(currentNode.getNodeName().equals("author")) }
StrAuthor = currentNode.getFirstChild().getNodeValue();
else if(currentNode.getNodeName().equals("content")) try {
StrPage = currentNode.getFirstChild().getNodeValue(); date = serverDate.parseShortSecond(StrDate);
} } catch (ParseException e1) {
date = new Date();
try { }
date = serverDate.parseShortSecond(StrDate);
} catch (ParseException e1) { if(key == null || ip == null || StrSubject == null || StrAuthor == null || StrPage == null || date == null)
date = new Date(); return false;
}
byte[] subject,author,page;
if(key == null || ip == null || StrSubject == null || StrAuthor == null || StrPage == null || date == null) try {
return false; subject = StrSubject.getBytes("UTF-8");
} catch (UnsupportedEncodingException e1) {
byte[] subject,author,page; subject = StrSubject.getBytes();
try { }
subject = StrSubject.getBytes("UTF-8"); try {
} catch (UnsupportedEncodingException e1) { author = StrAuthor.getBytes("UTF-8");
subject = StrSubject.getBytes(); } catch (UnsupportedEncodingException e1) {
} author = StrAuthor.getBytes();
try { }
author = StrAuthor.getBytes("UTF-8"); try {
} catch (UnsupportedEncodingException e1) { page = StrPage.getBytes("UTF-8");
author = StrAuthor.getBytes(); } catch (UnsupportedEncodingException e1) {
} page = StrPage.getBytes();
try { }
page = StrPage.getBytes("UTF-8");
} catch (UnsupportedEncodingException e1) { write (newEntry(key, subject, author, ip, date, page, null, null));
page = StrPage.getBytes(); }
} return true;
}
write (newEntry(key, subject, author, ip, date, page, null, null));
} public void delete(String key) {
return true; key = normalize(key);
} try {
datbase.remove(key);
public void delete(String key) { } catch (IOException e) { }
key = normalize(key); }
try {
datbase.remove(key); public Iterator<String> keys(boolean up) throws IOException {
} catch (IOException e) { } return datbase.keys(up, false);
} }
public Iterator<String> keys(boolean up) throws IOException { }
return datbase.keys(up, false);
}
}

@ -327,7 +327,7 @@ public class listManager {
public static ArrayList<String> string2arraylist(String string){ public static ArrayList<String> string2arraylist(String string){
ArrayList<String> l; ArrayList<String> l;
if (string != null) { if (string != null && string.length() > 0) {
l = new ArrayList<String>(Arrays.asList(string.split(","))); l = new ArrayList<String>(Arrays.asList(string.split(",")));
} else { } else {
l = new ArrayList<String>(); l = new ArrayList<String>();

Loading…
Cancel
Save