Skip to content

Commit

Permalink
*)added ip to Blog.xml
Browse files Browse the repository at this point in the history
*)added possibility to import Blog.xml-files
*)included german translation for new Blog-features

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2178 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
auron_x committed Jun 5, 2006
1 parent 7b47055 commit 71228cf
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 6 deletions.
15 changes: 14 additions & 1 deletion htroot/Blog.html
Expand Up @@ -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">
Expand Down Expand Up @@ -65,6 +65,19 @@ <h3>Are you sure...</h3>
<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>
Expand Down
35 changes: 30 additions & 5 deletions htroot/Blog.java
Expand Up @@ -142,7 +142,7 @@ else if(post.containsKey("login")){
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();
}

Expand Down Expand Up @@ -221,6 +221,19 @@ else if(post.containsKey("delete") && post.get("delete").equals("try")) {
}
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
Expand All @@ -231,9 +244,13 @@ else if(post.containsKey("delete") && post.get("delete").equals("try")) {
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)
Expand All @@ -243,11 +260,19 @@ else if(post.containsKey("delete") && post.get("delete").equals("try")) {
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());
Expand Down
1 change: 1 addition & 0 deletions htroot/Blog.xml
Expand Up @@ -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>
Expand Down
6 changes: 6 additions & 0 deletions locales/de.lng
Expand Up @@ -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:
Expand All @@ -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
Expand Down
106 changes: 106 additions & 0 deletions source/de/anomic/data/blogBoard.java
Expand Up @@ -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;
Expand All @@ -54,6 +56,16 @@
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;
Expand Down Expand Up @@ -182,13 +194,28 @@ public Date date() {
}
}

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];
byte[] b = kelondroBase64Order.enhancedCoder.decode(m);
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");
Expand Down Expand Up @@ -226,6 +253,85 @@ private entry read(String key, kelondroMap base) {
}
}

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 {
Expand Down

0 comments on commit 71228cf

Please sign in to comment.