mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
* removed single Blogview, now links direct to BlogComments.html
* some other small changes git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4483 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
parent
cfe499d8c9
commit
94e256e13b
|
@ -19,7 +19,7 @@
|
||||||
<!-- 0: viewing -->
|
<!-- 0: viewing -->
|
||||||
#{entries}#
|
#{entries}#
|
||||||
<div class="Post">
|
<div class="Post">
|
||||||
<h2 class="PostSubject"><a href="Blog.html?page=#[pageid]#">#[subject]#</a></h2>
|
<h2 class="PostSubject"><a href="BlogComments.html?page=#[pageid]#">#[subject]#</a></h2>
|
||||||
<div class="PostBody">#[page]#</div>
|
<div class="PostBody">#[page]#</div>
|
||||||
<p class="PostInfo">
|
<p class="PostInfo">
|
||||||
#[date]# | by #[author]# #(commentsactive)#::| <a href="BlogComments.html?page=#[pageid]#">#[comments]# Comments</a>#(/commentsactive)#
|
#[date]# | by #[author]# #(commentsactive)#::| <a href="BlogComments.html?page=#[pageid]#">#[comments]# Comments</a>#(/commentsactive)#
|
||||||
|
|
|
@ -291,7 +291,6 @@ public class Blog {
|
||||||
final boolean hasRights,
|
final boolean hasRights,
|
||||||
final boolean xml)
|
final boolean xml)
|
||||||
{
|
{
|
||||||
//final Iterator<String> i = switchboard.blogDB.keys(false);
|
|
||||||
final Iterator<String> i = switchboard.blogDB.getBlogIterator(false);
|
final Iterator<String> i = switchboard.blogDB.getBlogIterator(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
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#(mode)#
|
#(mode)#
|
||||||
<!-- 0: viewing -->
|
<!-- 0: viewing -->
|
||||||
<div class="Post">
|
<div class="Post">
|
||||||
<h2 class="PostSubject"><a href="Blog.html?page=#[pageid]#">#[subject]#</a></h2>
|
<h2 class="PostSubject"><a href="BlogComments.html?page=#[pageid]#">#[subject]#</a></h2>
|
||||||
<div class="PostBody">#[page]#</div>
|
<div class="PostBody">#[page]#</div>
|
||||||
<p class="PostInfo">
|
<p class="PostInfo">
|
||||||
#[date]# | by #[author]# | <a href="BlogComments.html?page=#[pageid]#">#[comments]# Comments</a>
|
#[date]# | by #[author]# | <a href="BlogComments.html?page=#[pageid]#">#[comments]# Comments</a>
|
||||||
|
@ -49,16 +49,17 @@
|
||||||
<p>Comments are not allowed for this posting!</p>
|
<p>Comments are not allowed for this posting!</p>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
::
|
::
|
||||||
|
<h2>Comment on this Blog</h2>
|
||||||
<form action="BlogComments.html" method="post" enctype="multipart/form-data" accept-charset="UTF-8">
|
<form action="BlogComments.html" method="post" enctype="multipart/form-data" accept-charset="UTF-8">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<dl>
|
<dl>
|
||||||
<dt><label for="author">Author:</label></dt>
|
<dt><label for="author">Author:</label></dt>
|
||||||
<dd>
|
<dd>
|
||||||
<input name="author" id="author" type="text" size="20" maxlength="80" value="#[author]#" />
|
<input name="author" id="author" type="text" size="80" maxlength="80" value="#[author]#" />
|
||||||
</dd>
|
</dd>
|
||||||
<dt><label for="subject">Subject:</label></dt>
|
<dt><label for="subject">Subject:</label></dt>
|
||||||
<dd>
|
<dd>
|
||||||
<input name="subject" id="subject" type="text" size="20" maxlength="80" value="" />
|
<input name="subject" id="subject" type="text" size="80" maxlength="80" value="" />
|
||||||
</dd>
|
</dd>
|
||||||
<dt><label for="content">Text:</label></dt>
|
<dt><label for="content">Text:</label></dt>
|
||||||
<dd>
|
<dd>
|
||||||
|
@ -92,11 +93,11 @@
|
||||||
<dl>
|
<dl>
|
||||||
<dt><label for="author">Author:</label></dt>
|
<dt><label for="author">Author:</label></dt>
|
||||||
<dd>
|
<dd>
|
||||||
<input name="author" id="author" type="text" size="20" maxlength="80" value="#[author]#" />
|
<input name="author" id="author" type="text" size="80" maxlength="80" value="#[author]#" />
|
||||||
</dd>
|
</dd>
|
||||||
<dt><label for="subject">Subject:</label></dt>
|
<dt><label for="subject">Subject:</label></dt>
|
||||||
<dd>
|
<dd>
|
||||||
<input name="subject" id="subject" type="text" size="20" maxlength="80" value="#[subject]#" />
|
<input name="subject" id="subject" type="text" size="80" maxlength="80" value="#[subject]#" />
|
||||||
</dd>
|
</dd>
|
||||||
<dt><label for="content">Text:</label></dt>
|
<dt><label for="content">Text:</label></dt>
|
||||||
<dd>
|
<dd>
|
||||||
|
@ -107,7 +108,7 @@
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
<input type="hidden" name="page" value="#[pageid]#" />
|
<input type="hidden" name="page" value="#[pageid]#" />
|
||||||
<input type="text" name="page" value="#[pageid]#" />
|
<!-- <input type="text" name="page" value="#[pageid]#" /> -->
|
||||||
<input type="submit" name="submit" value="Submit" />
|
<input type="submit" name="submit" value="Submit" />
|
||||||
<input type="submit" name="preview" value="Preview" />
|
<input type="submit" name="preview" value="Preview" />
|
||||||
<input type="submit" name="view" value="Discard" />
|
<input type="submit" name="view" value="Discard" />
|
||||||
|
|
|
@ -123,163 +123,6 @@ public class blogBoard {
|
||||||
return new BlogEntry(normalize(key), subject, author, ip, date, page, comments, commentMode);
|
return new BlogEntry(normalize(key), subject, author, ip, date, page, comments, commentMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BlogEntry {
|
|
||||||
|
|
||||||
String key;
|
|
||||||
HashMap<String, String> record;
|
|
||||||
|
|
||||||
public BlogEntry(String nkey, byte[] subject, byte[] author, String ip, Date date, byte[] page, ArrayList<String> comments, String commentMode) {
|
|
||||||
record = new HashMap<String, String>();
|
|
||||||
setKey(nkey);
|
|
||||||
setDate(date);
|
|
||||||
setSubject(subject);
|
|
||||||
setAuthor(author);
|
|
||||||
setIp(ip);
|
|
||||||
setPage(page);
|
|
||||||
setComments(comments);
|
|
||||||
setCommentMode(commentMode);
|
|
||||||
|
|
||||||
// TODO: implement this function
|
|
||||||
record.put("privacy", "public");
|
|
||||||
|
|
||||||
wikiBoard.setAuthor(ip, new String(author));
|
|
||||||
}
|
|
||||||
private BlogEntry(String key, HashMap<String, String> record) {
|
|
||||||
this.key = key;
|
|
||||||
this.record = record;
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
private void setKey(String key) {
|
|
||||||
if (key.length() > keyLength)
|
|
||||||
this.key = key.substring(0, keyLength);
|
|
||||||
this.key = key;
|
|
||||||
}
|
|
||||||
public String getKey() {
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
public byte[] getSubject() {
|
|
||||||
String m = record.get("subject");
|
|
||||||
if (m == null) return new byte[0];
|
|
||||||
byte[] b = kelondroBase64Order.enhancedCoder.decode(m, "de.anomic.data.blogBoard.subject()");
|
|
||||||
if (b == null) return "".getBytes();
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
private void setSubject(byte[] subject) {
|
|
||||||
if (subject == null)
|
|
||||||
record.put("subject","");
|
|
||||||
else
|
|
||||||
record.put("subject", kelondroBase64Order.enhancedCoder.encode(subject));
|
|
||||||
}
|
|
||||||
public Date getDate() {
|
|
||||||
try {
|
|
||||||
String date = record.get("date");
|
|
||||||
if (date == null) {
|
|
||||||
serverLog.logFinest("Blog", "ERROR: date field missing in blogBoard");
|
|
||||||
return new Date();
|
|
||||||
}
|
|
||||||
return serverDate.parseShortSecond(date);
|
|
||||||
} catch (ParseException e) {
|
|
||||||
return new Date();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void setDate(Date date) {
|
|
||||||
if(date == null)
|
|
||||||
date = new Date();
|
|
||||||
record.put("date", serverDate.formatShortSecond(date));
|
|
||||||
}
|
|
||||||
public String getTimestamp() {
|
|
||||||
String timestamp = record.get("date");
|
|
||||||
if (timestamp == null) {
|
|
||||||
serverLog.logFinest("Blog", "ERROR: date field missing in blogBoard");
|
|
||||||
return serverDate.formatShortSecond();
|
|
||||||
}
|
|
||||||
return timestamp;
|
|
||||||
}
|
|
||||||
public byte[] getAuthor() {
|
|
||||||
String author = record.get("author");
|
|
||||||
if (author == null) return new byte[0];
|
|
||||||
byte[] b = kelondroBase64Order.enhancedCoder.decode(author, "de.anomic.data.blogBoard.author()");
|
|
||||||
if (b == null) return "".getBytes();
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
private void setAuthor(byte[] author) {
|
|
||||||
if (author == null)
|
|
||||||
record.put("author","");
|
|
||||||
else
|
|
||||||
record.put("author", kelondroBase64Order.enhancedCoder.encode(author));
|
|
||||||
}
|
|
||||||
public int getCommentsSize() {
|
|
||||||
// This ist a Bugfix for Version older than 4443.
|
|
||||||
if(record.get("comments").startsWith(",")) {
|
|
||||||
record.put("comments", record.get("comments").substring(1));
|
|
||||||
writeBlogEntry(this);
|
|
||||||
}
|
|
||||||
ArrayList<String> commentsize = listManager.string2arraylist(record.get("comments"));
|
|
||||||
return commentsize.size();
|
|
||||||
}
|
|
||||||
public ArrayList<String> getComments() {
|
|
||||||
ArrayList<String> comments = listManager.string2arraylist(record.get("comments"));
|
|
||||||
return comments;
|
|
||||||
}
|
|
||||||
private void setComments(ArrayList<String> comments) {
|
|
||||||
if (comments == null)
|
|
||||||
record.put("comments", listManager.collection2string(new ArrayList<String>()));
|
|
||||||
else
|
|
||||||
record.put("comments", listManager.collection2string(comments));
|
|
||||||
}
|
|
||||||
public String getIp() {
|
|
||||||
String ip = record.get("ip");
|
|
||||||
if (ip == null) return "127.0.0.1";
|
|
||||||
return ip;
|
|
||||||
}
|
|
||||||
private void setIp(String ip) {
|
|
||||||
if ((ip == null) || (ip.length() == 0))
|
|
||||||
ip = "";
|
|
||||||
record.put("ip", ip);
|
|
||||||
}
|
|
||||||
public byte[] getPage() {
|
|
||||||
String page = record.get("page");
|
|
||||||
if (page == null) return new byte[0];
|
|
||||||
byte[] page_as_byte = kelondroBase64Order.enhancedCoder.decode(page, "de.anomic.data.blogBoard.page()");
|
|
||||||
if (page_as_byte == null) return "".getBytes();
|
|
||||||
return page_as_byte;
|
|
||||||
}
|
|
||||||
private void setPage(byte[] page) {
|
|
||||||
if (page == null)
|
|
||||||
record.put("page", "");
|
|
||||||
else
|
|
||||||
record.put("page", kelondroBase64Order.enhancedCoder.encode(page));
|
|
||||||
}
|
|
||||||
public void addComment(String commentID) {
|
|
||||||
ArrayList<String> comments = listManager.string2arraylist(record.get("comments"));
|
|
||||||
comments.add(commentID);
|
|
||||||
record.put("comments", listManager.collection2string(comments));
|
|
||||||
}
|
|
||||||
public boolean removeComment(String commentID) {
|
|
||||||
ArrayList<String> comments = listManager.string2arraylist(record.get("comments"));
|
|
||||||
boolean success = comments.remove(commentID);
|
|
||||||
record.put("comments", listManager.collection2string(comments));
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
public int getCommentMode(){
|
|
||||||
return Integer.parseInt(record.get("commentMode"));
|
|
||||||
}
|
|
||||||
private void setCommentMode(String mode) {
|
|
||||||
if (mode == null)
|
|
||||||
record.put("commentMode", "1");
|
|
||||||
else
|
|
||||||
record.put("commentMode", mode);
|
|
||||||
}
|
|
||||||
public boolean isPublic() {
|
|
||||||
String privacy = record.get("privacy");
|
|
||||||
if (privacy == null)
|
|
||||||
return true;
|
|
||||||
if(privacy.equalsIgnoreCase("public"))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
* writes a new page and return the key
|
* writes a new page and return the key
|
||||||
*/
|
*/
|
||||||
|
@ -477,4 +320,168 @@ public class blogBoard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class BlogEntry {
|
||||||
|
|
||||||
|
String key;
|
||||||
|
HashMap<String, String> record;
|
||||||
|
|
||||||
|
public BlogEntry(String nkey, byte[] subject, byte[] author, String ip, Date date, byte[] page, ArrayList<String> comments, String commentMode) {
|
||||||
|
record = new HashMap<String, String>();
|
||||||
|
setKey(nkey);
|
||||||
|
setDate(date);
|
||||||
|
setSubject(subject);
|
||||||
|
setAuthor(author);
|
||||||
|
setIp(ip);
|
||||||
|
setPage(page);
|
||||||
|
setComments(comments);
|
||||||
|
setCommentMode(commentMode);
|
||||||
|
|
||||||
|
// TODO: implement this function
|
||||||
|
record.put("privacy", "public");
|
||||||
|
|
||||||
|
wikiBoard.setAuthor(ip, new String(author));
|
||||||
|
}
|
||||||
|
private BlogEntry(String key, HashMap<String, String> record) {
|
||||||
|
this.key = key;
|
||||||
|
this.record = record;
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
private void setKey(String key) {
|
||||||
|
if (key.length() > keyLength)
|
||||||
|
this.key = key.substring(0, keyLength);
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
public byte[] getSubject() {
|
||||||
|
String m = record.get("subject");
|
||||||
|
if (m == null) return new byte[0];
|
||||||
|
byte[] b = kelondroBase64Order.enhancedCoder.decode(m, "de.anomic.data.blogBoard.subject()");
|
||||||
|
if (b == null) return "".getBytes();
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
private void setSubject(byte[] subject) {
|
||||||
|
if (subject == null)
|
||||||
|
record.put("subject","");
|
||||||
|
else
|
||||||
|
record.put("subject", kelondroBase64Order.enhancedCoder.encode(subject));
|
||||||
|
}
|
||||||
|
public Date getDate() {
|
||||||
|
try {
|
||||||
|
String date = record.get("date");
|
||||||
|
if (date == null) {
|
||||||
|
serverLog.logFinest("Blog", "ERROR: date field missing in blogBoard");
|
||||||
|
return new Date();
|
||||||
|
}
|
||||||
|
return serverDate.parseShortSecond(date);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
return new Date();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void setDate(Date date) {
|
||||||
|
if(date == null)
|
||||||
|
date = new Date();
|
||||||
|
record.put("date", serverDate.formatShortSecond(date));
|
||||||
|
}
|
||||||
|
public String getTimestamp() {
|
||||||
|
String timestamp = record.get("date");
|
||||||
|
if (timestamp == null) {
|
||||||
|
serverLog.logFinest("Blog", "ERROR: date field missing in blogBoard");
|
||||||
|
return serverDate.formatShortSecond();
|
||||||
|
}
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
public byte[] getAuthor() {
|
||||||
|
String author = record.get("author");
|
||||||
|
if (author == null) return new byte[0];
|
||||||
|
byte[] b = kelondroBase64Order.enhancedCoder.decode(author, "de.anomic.data.blogBoard.author()");
|
||||||
|
if (b == null) return "".getBytes();
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
private void setAuthor(byte[] author) {
|
||||||
|
if (author == null)
|
||||||
|
record.put("author","");
|
||||||
|
else
|
||||||
|
record.put("author", kelondroBase64Order.enhancedCoder.encode(author));
|
||||||
|
}
|
||||||
|
public int getCommentsSize() {
|
||||||
|
// This ist a Bugfix for Version older than 4443.
|
||||||
|
if(record.get("comments").startsWith(",")) {
|
||||||
|
record.put("comments", record.get("comments").substring(1));
|
||||||
|
writeBlogEntry(this);
|
||||||
|
}
|
||||||
|
ArrayList<String> commentsize = listManager.string2arraylist(record.get("comments"));
|
||||||
|
return commentsize.size();
|
||||||
|
}
|
||||||
|
public ArrayList<String> getComments() {
|
||||||
|
ArrayList<String> comments = listManager.string2arraylist(record.get("comments"));
|
||||||
|
return comments;
|
||||||
|
}
|
||||||
|
private void setComments(ArrayList<String> comments) {
|
||||||
|
if (comments == null)
|
||||||
|
record.put("comments", listManager.collection2string(new ArrayList<String>()));
|
||||||
|
else
|
||||||
|
record.put("comments", listManager.collection2string(comments));
|
||||||
|
}
|
||||||
|
public String getIp() {
|
||||||
|
String ip = record.get("ip");
|
||||||
|
if (ip == null) return "127.0.0.1";
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
private void setIp(String ip) {
|
||||||
|
if ((ip == null) || (ip.length() == 0))
|
||||||
|
ip = "";
|
||||||
|
record.put("ip", ip);
|
||||||
|
}
|
||||||
|
public byte[] getPage() {
|
||||||
|
String page = record.get("page");
|
||||||
|
if (page == null) return new byte[0];
|
||||||
|
byte[] page_as_byte = kelondroBase64Order.enhancedCoder.decode(page, "de.anomic.data.blogBoard.page()");
|
||||||
|
if (page_as_byte == null) return "".getBytes();
|
||||||
|
return page_as_byte;
|
||||||
|
}
|
||||||
|
private void setPage(byte[] page) {
|
||||||
|
if (page == null)
|
||||||
|
record.put("page", "");
|
||||||
|
else
|
||||||
|
record.put("page", kelondroBase64Order.enhancedCoder.encode(page));
|
||||||
|
}
|
||||||
|
public void addComment(String commentID) {
|
||||||
|
ArrayList<String> comments = listManager.string2arraylist(record.get("comments"));
|
||||||
|
comments.add(commentID);
|
||||||
|
record.put("comments", listManager.collection2string(comments));
|
||||||
|
}
|
||||||
|
public boolean removeComment(String commentID) {
|
||||||
|
ArrayList<String> comments = listManager.string2arraylist(record.get("comments"));
|
||||||
|
boolean success = comments.remove(commentID);
|
||||||
|
record.put("comments", listManager.collection2string(comments));
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* returns the comment mode
|
||||||
|
* 0 - no comments allowed
|
||||||
|
* 1 - comments allowed
|
||||||
|
* 2 - comments moderated
|
||||||
|
* @return comment mode
|
||||||
|
*/
|
||||||
|
public int getCommentMode(){
|
||||||
|
return Integer.parseInt(record.get("commentMode"));
|
||||||
|
}
|
||||||
|
private void setCommentMode(String mode) {
|
||||||
|
if (mode == null)
|
||||||
|
record.put("commentMode", "1");
|
||||||
|
else
|
||||||
|
record.put("commentMode", mode);
|
||||||
|
}
|
||||||
|
public boolean isPublic() {
|
||||||
|
String privacy = record.get("privacy");
|
||||||
|
if (privacy == null)
|
||||||
|
return true;
|
||||||
|
if(privacy.equalsIgnoreCase("public"))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,35 +81,28 @@ public class blogBoardComments {
|
||||||
static {
|
static {
|
||||||
SimpleFormatter.setTimeZone(TimeZone.getTimeZone("GMT"));
|
SimpleFormatter.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private kelondroMapObjects database = null;
|
private kelondroMapObjects database = null;
|
||||||
|
|
||||||
public blogBoardComments(File actpath, long preloadTime) {
|
public blogBoardComments(File actpath, long preloadTime) {
|
||||||
new File(actpath.getParent()).mkdir();
|
new File(actpath.getParent()).mkdir();
|
||||||
if (database == null) {
|
if (database == null) {
|
||||||
database = new kelondroMapObjects(new kelondroDyn(actpath, true, true, preloadTime, keyLength, recordSize, '_', kelondroNaturalOrder.naturalOrder, false, false, false), 500);
|
database = new kelondroMapObjects(new kelondroDyn(actpath, true, true, preloadTime, keyLength, recordSize, '_', kelondroNaturalOrder.naturalOrder, false, false, false), 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size() {
|
public int size() {
|
||||||
return database.size();
|
return database.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
database.close();
|
database.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String dateString(Date date) {
|
private static String dateString(Date date) {
|
||||||
synchronized (SimpleFormatter) {
|
synchronized (SimpleFormatter) {
|
||||||
return SimpleFormatter.format(date);
|
return SimpleFormatter.format(date);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
|
@ -118,14 +111,116 @@ public class blogBoardComments {
|
||||||
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 CommentEntry newEntry(String key, byte[] subject, byte[] author, String ip, Date date, byte[] page) {
|
public CommentEntry newEntry(String key, byte[] subject, byte[] author, String ip, Date date, byte[] page) {
|
||||||
return new CommentEntry(normalize(key), subject, author, ip, date, page);
|
return new CommentEntry(normalize(key), subject, author, ip, date, page);
|
||||||
}
|
}
|
||||||
|
public String write(CommentEntry page) {
|
||||||
|
// writes a new page and returns key
|
||||||
|
try {
|
||||||
|
database.set(page.key, page.record);
|
||||||
|
return page.key;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public CommentEntry read(String key) {
|
||||||
|
//System.out.println("DEBUG: read from blogBoardComments");
|
||||||
|
return read(key, database);
|
||||||
|
}
|
||||||
|
private CommentEntry read(String key, kelondroMapObjects base) {
|
||||||
|
key = normalize(key);
|
||||||
|
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());
|
||||||
|
return new CommentEntry(key, record);
|
||||||
|
}
|
||||||
|
public boolean importXML(String input) {
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
try {
|
||||||
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
|
Document doc = builder.parse(new ByteArrayInputStream(input.getBytes()));
|
||||||
|
return parseXMLimport(doc);
|
||||||
|
} catch (ParserConfigurationException e) {
|
||||||
|
} catch (SAXException e) {
|
||||||
|
} catch (IOException e) {}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private boolean parseXMLimport(Document doc) {
|
||||||
|
if(!doc.getDocumentElement().getTagName().equals("blog"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
NodeList items = doc.getDocumentElement().getElementsByTagName("item");
|
||||||
|
if(items.getLength() == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for(int i=0;i<items.getLength();++i) {
|
||||||
|
String key = null, ip = null, StrSubject = null, StrAuthor = null, StrPage = null, StrDate = null;
|
||||||
|
Date date = null;
|
||||||
|
|
||||||
|
if(!items.item(i).getNodeName().equals("item"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
NodeList currentNodeChildren = items.item(i).getChildNodes();
|
||||||
|
|
||||||
|
for(int j=0;j<currentNodeChildren.getLength();++j) {
|
||||||
|
Node currentNode = currentNodeChildren.item(j);
|
||||||
|
if(currentNode.getNodeName().equals("id"))
|
||||||
|
key = currentNode.getFirstChild().getNodeValue();
|
||||||
|
else if(currentNode.getNodeName().equals("ip"))
|
||||||
|
ip = currentNode.getFirstChild().getNodeValue();
|
||||||
|
else if(currentNode.getNodeName().equals("timestamp"))
|
||||||
|
StrDate = currentNode.getFirstChild().getNodeValue();
|
||||||
|
else if(currentNode.getNodeName().equals("subject"))
|
||||||
|
StrSubject = currentNode.getFirstChild().getNodeValue();
|
||||||
|
else if(currentNode.getNodeName().equals("author"))
|
||||||
|
StrAuthor = currentNode.getFirstChild().getNodeValue();
|
||||||
|
else if(currentNode.getNodeName().equals("content"))
|
||||||
|
StrPage = currentNode.getFirstChild().getNodeValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
date = SimpleFormatter.parse(StrDate);
|
||||||
|
} catch (ParseException e1) {
|
||||||
|
date = new Date();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == null || ip == null || StrSubject == null || StrAuthor == null || StrPage == null || date == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
byte[] subject,author,page;
|
||||||
|
try {
|
||||||
|
subject = StrSubject.getBytes("UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e1) {
|
||||||
|
subject = StrSubject.getBytes();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
author = StrAuthor.getBytes("UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e1) {
|
||||||
|
author = StrAuthor.getBytes();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
page = StrPage.getBytes("UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e1) {
|
||||||
|
page = StrPage.getBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
write (newEntry(key, subject, author, ip, date, page));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public void delete(String key) {
|
||||||
|
key = normalize(key);
|
||||||
|
try {
|
||||||
|
database.remove(key);
|
||||||
|
} catch (IOException e) { }
|
||||||
|
}
|
||||||
|
public Iterator<String> keys(boolean up) throws IOException {
|
||||||
|
return database.keys(up, false);
|
||||||
|
}
|
||||||
|
|
||||||
public class CommentEntry {
|
public class CommentEntry {
|
||||||
|
|
||||||
|
@ -241,6 +336,12 @@ public class blogBoardComments {
|
||||||
return "".getBytes();
|
return "".getBytes();
|
||||||
return page_byte;
|
return page_byte;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Is the comment allowed?
|
||||||
|
* this is possible for moderated blog entry only and means
|
||||||
|
* the administrator has explicit allowed the comment.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public boolean isAllowed() {
|
public boolean isAllowed() {
|
||||||
return (record.get("moderated") != null) && record.get("moderated").equals("true");
|
return (record.get("moderated") != null) && record.get("moderated").equals("true");
|
||||||
}
|
}
|
||||||
|
@ -250,128 +351,4 @@ public class blogBoardComments {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String write(CommentEntry page) {
|
|
||||||
// writes a new page and returns key
|
|
||||||
try {
|
|
||||||
database.set(page.key, page.record);
|
|
||||||
return page.key;
|
|
||||||
} catch (IOException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommentEntry read(String key) {
|
|
||||||
//System.out.println("DEBUG: read from blogBoardComments");
|
|
||||||
return read(key, database);
|
|
||||||
}
|
|
||||||
|
|
||||||
private CommentEntry read(String key, kelondroMapObjects base) {
|
|
||||||
key = normalize(key);
|
|
||||||
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());
|
|
||||||
return new CommentEntry(key, record);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* private CommentEntry read(String key, kelondroMapObjects base) {
|
|
||||||
key = normalize(key);
|
|
||||||
if (key.length() > keyLength) key = key.substring(0, keyLength);
|
|
||||||
CommentEntry record = null;
|
|
||||||
try {
|
|
||||||
record = (CommentEntry) base.get(key);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if (record == null) return newEntry(key, "".getBytes(), "anonymous".getBytes(), "127.0.0.1", new Date(), "".getBytes());
|
|
||||||
return new CommentEntry(key, record.record);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public boolean importXML(String input) {
|
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
||||||
try {
|
|
||||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
|
||||||
Document doc = builder.parse(new ByteArrayInputStream(input.getBytes()));
|
|
||||||
return parseXMLimport(doc);
|
|
||||||
} catch (ParserConfigurationException e) {
|
|
||||||
} catch (SAXException e) {
|
|
||||||
} catch (IOException e) {}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean parseXMLimport(Document doc) {
|
|
||||||
if(!doc.getDocumentElement().getTagName().equals("blog"))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
NodeList items = doc.getDocumentElement().getElementsByTagName("item");
|
|
||||||
if(items.getLength() == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
for(int i=0;i<items.getLength();++i) {
|
|
||||||
String key = null, ip = null, StrSubject = null, StrAuthor = null, StrPage = null, StrDate = null;
|
|
||||||
Date date = null;
|
|
||||||
|
|
||||||
if(!items.item(i).getNodeName().equals("item"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
NodeList currentNodeChildren = items.item(i).getChildNodes();
|
|
||||||
|
|
||||||
for(int j=0;j<currentNodeChildren.getLength();++j) {
|
|
||||||
Node currentNode = currentNodeChildren.item(j);
|
|
||||||
if(currentNode.getNodeName().equals("id"))
|
|
||||||
key = currentNode.getFirstChild().getNodeValue();
|
|
||||||
else if(currentNode.getNodeName().equals("ip"))
|
|
||||||
ip = currentNode.getFirstChild().getNodeValue();
|
|
||||||
else if(currentNode.getNodeName().equals("timestamp"))
|
|
||||||
StrDate = currentNode.getFirstChild().getNodeValue();
|
|
||||||
else if(currentNode.getNodeName().equals("subject"))
|
|
||||||
StrSubject = currentNode.getFirstChild().getNodeValue();
|
|
||||||
else if(currentNode.getNodeName().equals("author"))
|
|
||||||
StrAuthor = currentNode.getFirstChild().getNodeValue();
|
|
||||||
else if(currentNode.getNodeName().equals("content"))
|
|
||||||
StrPage = currentNode.getFirstChild().getNodeValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
date = SimpleFormatter.parse(StrDate);
|
|
||||||
} catch (ParseException e1) {
|
|
||||||
date = new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(key == null || ip == null || StrSubject == null || StrAuthor == null || StrPage == null || date == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
byte[] subject,author,page;
|
|
||||||
try {
|
|
||||||
subject = StrSubject.getBytes("UTF-8");
|
|
||||||
} catch (UnsupportedEncodingException e1) {
|
|
||||||
subject = StrSubject.getBytes();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
author = StrAuthor.getBytes("UTF-8");
|
|
||||||
} catch (UnsupportedEncodingException e1) {
|
|
||||||
author = StrAuthor.getBytes();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
page = StrPage.getBytes("UTF-8");
|
|
||||||
} catch (UnsupportedEncodingException e1) {
|
|
||||||
page = StrPage.getBytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
write (newEntry(key, subject, author, ip, date, page));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delete(String key) {
|
|
||||||
key = normalize(key);
|
|
||||||
try {
|
|
||||||
database.remove(key);
|
|
||||||
} catch (IOException e) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterator<String> keys(boolean up) throws IOException {
|
|
||||||
return database.keys(up, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user