Skip to content

Commit

Permalink
*)fixed "Umlaute"-Bug in Blog
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2125 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
auron_x committed May 20, 2006
1 parent af098b8 commit e7199c6
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 39 deletions.
71 changes: 56 additions & 15 deletions htroot/Blog.java
Expand Up @@ -100,14 +100,30 @@ else if(post.containsKey("login")){

String pagename = post.get("page", "blog_default");
String ip = post.get("CLIENTIP", "127.0.0.1");
String author = post.get("author", "anonymous");

byte[] author;
try {
author = post.get("author", "").getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
author = post.get("author", "").getBytes();
}

if (author.equals("anonymous")) {
author = switchboard.blogDB.guessAuthor(ip);
try {
author = switchboard.blogDB.guessAuthor(ip).getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
author = switchboard.blogDB.guessAuthor(ip).getBytes();
}
if (author == null) {
if (de.anomic.yacy.yacyCore.seedDB.mySeed == null)
author = "anonymous";
else
author = de.anomic.yacy.yacyCore.seedDB.mySeed.get("Name", "anonymous");
author = "anonymous".getBytes();
else {
try {
author = de.anomic.yacy.yacyCore.seedDB.mySeed.get("Name", "anonymous").getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
author = de.anomic.yacy.yacyCore.seedDB.mySeed.get("Name", "anonymous").getBytes();
}
}
}
}

Expand Down Expand Up @@ -135,7 +151,12 @@ else if(post.containsKey("login")){
date = page.date();
}

String subject = post.get("subject","");
byte[] subject;
try {
subject = post.get("subject", "").getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
subject = post.get("subject", "").getBytes();
}

try {
switchboard.blogDB.write(switchboard.blogDB.newEntry(pagename, subject, author, ip, date, content));
Expand All @@ -159,9 +180,9 @@ else if(post.containsKey("login")){
if(hasRights) {
try {
prop.put("mode", 1); //edit
prop.put("mode_author", wikiCode.replaceHTML(page.author()));
prop.put("mode_author", wikiCode.replaceHTML(new String(page.author(),"UTF-8")));
prop.put("mode_pageid", page.key());
prop.put("mode_subject", wikiCode.replaceHTML(page.subject()));
prop.put("mode_subject", wikiCode.replaceHTML(new String(page.subject(), "UTF-8")));
prop.put("mode_page-code", new String(page.page(), "UTF-8").replaceAll("<","&lt;").replaceAll(">","&gt;"));
} catch (UnsupportedEncodingException e) {}
}
Expand All @@ -175,7 +196,11 @@ else if(post.containsKey("preview")) {
wikiCode wikiTransformer=new wikiCode(switchboard);
prop.put("mode", 2);//preview
prop.put("mode_pageid", pagename);
prop.put("mode_author", wikiCode.replaceHTML(author));
try {
prop.put("mode_author", wikiCode.replaceHTML(new String(author, "UTF-8")));
} catch (UnsupportedEncodingException e) {
prop.put("mode_author", wikiCode.replaceHTML(new String(author)));
}
prop.put("mode_subject", wikiCode.replaceHTML(post.get("subject","")));
prop.put("mode_date", dateString(new Date()));
prop.put("mode_page", wikiTransformer.transform(post.get("content", "")));
Expand All @@ -187,8 +212,16 @@ else if(post.containsKey("delete") && post.get("delete").equals("try")) {
if(hasRights) {
prop.put("mode",4);
prop.put("mode_pageid",pagename);
prop.put("mode_author",wikiCode.replaceHTML(page.author()));
prop.put("mode_subject",wikiCode.replaceHTML(page.subject()));
try {
prop.put("mode_author",wikiCode.replaceHTML(new String(page.author(), "UTF-8")));
} catch (UnsupportedEncodingException e) {
prop.put("mode_author",wikiCode.replaceHTML(new String(page.author())));
}
try {
prop.put("mode_subject",wikiCode.replaceHTML(new String(page.subject(),"UTF-8")));
} catch (UnsupportedEncodingException e) {
prop.put("mode_subject",wikiCode.replaceHTML(new String(page.subject())));
}
}
else prop.put("mode",3); //access denied (no rights)
}
Expand All @@ -214,8 +247,8 @@ 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(entry.subject()));
prop.put("mode_entries_"+count+"_author", wikiCode.replaceHTML(entry.author()));
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+"_date", dateString(entry.date()));
prop.put("mode_entries_"+count+"_page", wikiTransformer.transform(entry.page()));
if(hasRights) {
Expand All @@ -240,8 +273,16 @@ else if(post.containsKey("delete") && post.get("delete").equals("try")) {
//only show 1 entry
prop.put("mode_entries",1);
prop.put("mode_entries_0_pageid", page.key());
prop.put("mode_entries_0_subject", wikiCode.replaceHTML(page.subject()));
prop.put("mode_entries_0_author", wikiCode.replaceHTML(page.author()));
try {
prop.put("mode_entries_0_subject", wikiCode.replaceHTML(new String(page.subject(),"UTF-8")));
} catch (UnsupportedEncodingException e) {
prop.put("mode_entries_0_subject", wikiCode.replaceHTML(new String(page.subject())));
}
try {
prop.put("mode_entries_0_author", wikiCode.replaceHTML(new String(page.author(),"UTF-8")));
} catch (UnsupportedEncodingException e) {
prop.put("mode_entries_0_author", wikiCode.replaceHTML(new String(page.author())));
}
prop.put("mode_entries_0_date", dateString(page.date()));
prop.put("mode_entries_0_page", wikiTransformer.transform(page.page()));
if(hasRights) {
Expand Down
46 changes: 22 additions & 24 deletions source/de/anomic/data/blogBoard.java
Expand Up @@ -124,7 +124,7 @@ public String guessAuthor(String ip) {
return wikiBoard.guessAuthor(ip);
}

public entry newEntry(String key, String subject, String author, String ip, Date date, byte[] page) throws IOException {
public entry newEntry(String key, byte[] subject, byte[] author, String ip, Date date, byte[] page) throws IOException {
return new entry(normalize(key), subject, author, ip, date, page);
}

Expand All @@ -133,24 +133,22 @@ public class entry {
String key;
Map record;

public entry(String nkey, String subject, String author, String ip, Date date, byte[] page) throws IOException {
public entry(String nkey, byte[] subject, byte[] author, String ip, Date date, byte[] page) throws IOException {
record = new HashMap();
key = nkey;
if (key.length() > keyLength) key = key.substring(0, keyLength);
if(date == null) date = new GregorianCalendar(GMTTimeZone).getTime();
record.put("date", dateString(date));
if ((subject == null) || (subject.length() == 0)) subject = "";
record.put("subject", kelondroBase64Order.enhancedCoder.encode(subject.getBytes("UTF-8")));
if ((author == null) || (author.length() == 0)) author = "anonymous";
record.put("author", kelondroBase64Order.enhancedCoder.encode(author.getBytes("UTF-8")));
if (subject == null) record.put("subject","");
else record.put("subject", kelondroBase64Order.enhancedCoder.encode(subject));
if (author == null) record.put("author","");
else record.put("author", kelondroBase64Order.enhancedCoder.encode(author));
if ((ip == null) || (ip.length() == 0)) ip = "";
record.put("ip", ip);
if (page == null)
record.put("page", "");
else
record.put("page", kelondroBase64Order.enhancedCoder.encode(page));
if (page == null) record.put("page", "");
else record.put("page", kelondroBase64Order.enhancedCoder.encode(page));

wikiBoard.setAuthor(ip, author);
wikiBoard.setAuthor(ip, new String(author));
//System.out.println("DEBUG: setting author " + author + " for ip = " + ip + ", authors = " + authors.toString());
}

Expand All @@ -163,12 +161,12 @@ public String key() {
return key;
}

public String subject() {
String a = (String) record.get("subject");
if (a == null) return "";
byte[] b = kelondroBase64Order.enhancedCoder.decode(a);
if (b == null) return "";
return new String(b);
public byte[] subject() {
String m = (String) record.get("subject");
if (m == null) return new byte[0];
byte[] b = kelondroBase64Order.enhancedCoder.decode(m);
if (b == null) return "".getBytes();
return b;
}

public Date date() {
Expand All @@ -184,12 +182,12 @@ public Date date() {
}
}

public String author() {
String a = (String) record.get("author");
if (a == null) return "anonymous";
byte[] b = kelondroBase64Order.enhancedCoder.decode(a);
if (b == null) return "anonymous";
return new String(b);
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 byte[] page() {
Expand Down Expand Up @@ -221,7 +219,7 @@ private entry read(String key, kelondroMap base) {
key = normalize(key);
if (key.length() > keyLength) key = key.substring(0, keyLength);
Map record = base.get(key);
if (record == null) return newEntry(key, "", "anonymous", "127.0.0.1", new GregorianCalendar(GMTTimeZone).getTime(), "".getBytes());
if (record == null) return newEntry(key, "".getBytes(), "anonymous".getBytes(), "127.0.0.1", new GregorianCalendar(GMTTimeZone).getTime(), "".getBytes());
return new entry(key, record);
} catch (IOException e) {
return null;
Expand Down

0 comments on commit e7199c6

Please sign in to comment.