Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

*)added ip to Blog.xml *)added possibility to import Blog.xml-files *)included german translation for new Blog-features

auron_x71228cfc56c7
diff --git a/htroot/Blog.html b/htroot/Blog.html
index 9195e7e5c..389f5dcad 100644
--- a/htroot/Blog.html
+++ b/htroot/Blog.html
@@ -19,7 +19,7 @@
#{/entries}#
#(moreentries)#::<a href="Blog.html?start=#[start]#&amp;num=#[num]#">show more entries...</a>#(/moreentries)#
<br>
-#(admin)#<a href="Blog.html?login=true">Login</a> - ::<a href="Blog.html?edit=true">new entry</a> - #(/admin)#<a href="Blog.html">Blog-Home</a></center>
+#(admin)#<a href="Blog.html?login=true">Login</a> - ::<a href="Blog.html?edit=true">new entry</a> - <a href="Blog.html?import=xml">import XML-File</a> - <a href="Blog.xml?xml=1">export as XML</a> - #(/admin)#<a href="Blog.html">Blog-Home</a></center>
::
<!-- 1: edit -->
<form action="Blog.html" method="POST" enctype="multipart/form-data" accept-charset="UTF-8">
@@ -65,6 +65,19 @@ To edit or create blog-entries you need to be logged in as Admin or User who has
<form action="Blog.html" method="POST" enctype="multipart/form-data" accept-charset="UTF-8">
<input type="submit" value="No, leave it.">
</form>
+::
+<!-- 5: XML-Import -->
+<h3>XML-Import</h3>
+#(state)#
+::
+Import was successful!<br><br>
+::
+Import failed, maybe the supplied file was no valid blog-backup?<br><br>
+#(/state)#
+Please select the XML-file you want to import:<br>
+<form action="Blog.html" method="POST" enctype="multipart/form-data">
+<input type="file" size=50 name="xmlfile"> <input type="submit" name="importxml" value="Import">
+</form>
#(/mode)#
#%env/templates/footer.template%#
</body>
diff --git a/htroot/Blog.java b/htroot/Blog.java
index 0beeb1960..2a70d010e 100644
--- a/htroot/Blog.java
+++ b/htroot/Blog.java
@@ -142,7 +142,7 @@ public class Blog {
if(pagename.equals("blog_default"))
pagename = String.valueOf(System.currentTimeMillis());
else {
- page = switchboard.blogDB.read(pagename); //must I read it again after submitting?
+ page = switchboard.blogDB.read(pagename);
date = page.date();
}
@@ -221,6 +221,19 @@ public class Blog {
}
else prop.put("mode",3); //access denied (no rights)
}
+ else if(post.containsKey("import")) {
+ prop.put("mode",5);
+ prop.put("mode_state",0);
+ }
+ else if(post.containsKey("xmlfile")) {
+ prop.put("mode",5);
+ if(switchboard.blogDB.importXML(new String((byte[])post.get("xmlfile$file")))) {
+ prop.put("mode_state",1);
+ }
+ else {
+ prop.put("mode_state",2);
+ }
+ }
else {
wikiCode wikiTransformer=new wikiCode(switchboard);
// show blog-entry/entries
@@ -231,9 +244,13 @@ public class Blog {
Iterator i = switchboard.blogDB.keys(false);
String pageid;
blogBoard.entry entry;
+ boolean xml = false;
+ if(post.containsKey("xml"))
+ xml = true;
int count = 0; //counts how many entries are shown to the user
int start = post.getInt("start",0); //indicates from where entries should be shown
int num = post.getInt("num",20); //indicates how many entries should be shown
+ if(xml) num = 0;
int nextstart = start+num; //indicates the starting offset for next results
while(i.hasNext()) {
if(count >= num && num > 0)
@@ -243,11 +260,19 @@ public class Blog {
continue;
entry = switchboard.blogDB.read(pageid);
prop.put("mode_entries_"+count+"_pageid",entry.key());
- prop.put("mode_entries_"+count+"_subject", wikiCode.replaceHTML(new String(entry.subject(),"UTF-8")));
- prop.put("mode_entries_"+count+"_author", wikiCode.replaceHTML(new String(entry.author(),"UTF-8")));
+ if(!xml) {
+ prop.put("mode_entries_"+count+"_subject", wikiCode.replaceHTML(new String(entry.subject(),"UTF-8")));
+ prop.put("mode_entries_"+count+"_author", wikiCode.replaceHTML(new String(entry.author(),"UTF-8")));
+ prop.put("mode_entries_"+count+"_page", wikiTransformer.transform(entry.page()));
+ }
+ else {
+ prop.put("mode_entries_"+count+"_subject", new String(entry.subject(),"UTF-8"));
+ prop.put("mode_entries_"+count+"_author", new String(entry.author(),"UTF-8"));
+ prop.put("mode_entries_"+count+"_page", entry.page());
+ prop.put("mode_entries_"+count+"_timestamp", entry.timestamp());
+ }
prop.put("mode_entries_"+count+"_date", dateString(entry.date()));
- prop.put("mode_entries_"+count+"_timestamp", entry.date().getTime());
- prop.put("mode_entries_"+count+"_page", wikiTransformer.transform(entry.page()));
+ prop.put("mode_entries_"+count+"_ip", entry.ip());
if(hasRights) {
prop.put("mode_entries_"+count+"_admin", 1);
prop.put("mode_entries_"+count+"_admin_pageid",entry.key());
diff --git a/htroot/Blog.xml b/htroot/Blog.xml
index 1bf53e0a2..56d758918 100644
--- a/htroot/Blog.xml
+++ b/htroot/Blog.xml
@@ -5,6 +5,7 @@
<item>
<id>#[pageid]#</id>
<timestamp>#[timestamp]#</timestamp>
+ <ip>#[ip]#</ip>
<author><![CDATA[#[author]#]]></author>
<subject><![CDATA[#[subject]#]]></subject>
<content><![CDATA[#[page]#]]></content>
diff --git a/locales/de.lng b/locales/de.lng
index 358042bf2..3a5777d23 100644
--- a/locales/de.lng
+++ b/locales/de.lng
@@ -70,6 +70,8 @@ File:==Datei:
>delete==>l&ouml;schen
show more entries==zeige weitere Eintr&auml;ge
new entry==Neuer Eintrag
+import XML-File==XML-Datei importieren
+export as XML==als XML exportieren
Blog-Home==Blog-Startseite
Author:==Autor:
Subject:==Titel:
@@ -84,6 +86,10 @@ Are you sure==Sind Sie sicher
that you want to delete <b>\#\[subject\]\#</b> by \#\[author\]\#?==dass Sie <b>#[subject]#</b> von #[author]# l&ouml;schen wollen?
Yes, delete it.==Ja, l&ouml;schen.
No, leave it.==Nein, belassen.
+Import was successful!==Import war erfolgreich!
+Import failed, maybe the supplied file was no valid blog-backup?==Import fehlgeschlagen, unter Umst&auml;nden war die angegebene Datei keine g&uuml;ltige Blog-Sicherung?
+Please select the XML-file you want to import:==Bitte w&auml;hlen Sie die XML-Datei die Sie importieren wollen:
+
#-----------------------------------------------------------
#File: Bookmarks.html
diff --git a/source/de/anomic/data/blogBoard.java b/source/de/anomic/data/blogBoard.java
index fa495d26a..e4b7c8311 100644
--- a/source/de/anomic/data/blogBoard.java
+++ b/source/de/anomic/data/blogBoard.java
@@ -43,8 +43,10 @@
package de.anomic.data;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -54,6 +56,16 @@ import java.util.Iterator;
import java.util.Map;
import java.util.TimeZone;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
import de.anomic.kelondro.kelondroBase64Order;
import de.anomic.kelondro.kelondroDyn;
import de.anomic.kelondro.kelondroMap;
@@ -182,6 +194,15 @@ public class blogBoard {
}
}
+ public String timestamp() {
+ String c = (String) record.get("date");
+ if (c == null) {
+ System.out.println("DEBUG - ERROR: date field missing in blogBoard");
+ return dateString(new Date());
+ }
+ return c;
+ }
+
public byte[] author() {
String m = (String) record.get("author");
if (m == null) return new byte[0];
@@ -189,6 +210,12 @@ public class blogBoard {
if (b == null) return "".getBytes();
return b;
}
+
+ public String ip() {
+ String a = (String) record.get("ip");
+ if (a == null) return "127.0.0.1";
+ return a;
+ }
public byte[] page() {
String m = (String) record.get("page");
@@ -226,6 +253,85 @@ public class blogBoard {
}
}
+ 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();
+ }
+
+ try {
+ write (newEntry(key, subject, author, ip, date, page));
+ } catch (IOException e) { }
+ }
+ return true;
+ }
+
public void delete(String key) {
key = normalize(key);
try {