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)#::show more entries...#(/moreentries)#
-#(admin)#Login - ::new entry - #(/admin)#Blog-Home +#(admin)#Login - ::new entry - import XML-File - export as XML - #(/admin)#Blog-Home ::
@@ -65,6 +65,19 @@ To edit or create blog-entries you need to be logged in as Admin or User who has
+:: + +

XML-Import

+#(state)# +:: +Import was successful!

+:: +Import failed, maybe the supplied file was no valid blog-backup?

+#(/state)# +Please select the XML-file you want to import:
+
+ +
#(/mode)# #%env/templates/footer.template%# 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 @@ #[pageid]# #[timestamp]# + #[ip]# 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öschen show more entries==zeige weitere Einträ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 \#\[subject\]\# by \#\[author\]\#?==dass Sie #[subject]# von #[author]# löschen wollen? Yes, delete it.==Ja, lö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änden war die angegebene Datei keine gültige Blog-Sicherung? +Please select the XML-file you want to import:==Bitte wä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