From e7199c6c7e83347b8c7881f940e8b0c2602c6d81 Mon Sep 17 00:00:00 2001 From: auron_x Date: Sat, 20 May 2006 12:21:01 +0000 Subject: [PATCH] *)fixed "Umlaute"-Bug in Blog git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2125 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/Blog.java | 71 ++++++++++++++++++++++------ source/de/anomic/data/blogBoard.java | 46 +++++++++--------- 2 files changed, 78 insertions(+), 39 deletions(-) diff --git a/htroot/Blog.java b/htroot/Blog.java index 40ae8b210..8ae157f83 100644 --- a/htroot/Blog.java +++ b/htroot/Blog.java @@ -100,14 +100,30 @@ public class Blog { 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(); + } + } } } @@ -135,7 +151,12 @@ public class Blog { 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)); @@ -159,9 +180,9 @@ public class Blog { 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("<","<").replaceAll(">",">")); } catch (UnsupportedEncodingException e) {} } @@ -175,7 +196,11 @@ public class Blog { 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", ""))); @@ -187,8 +212,16 @@ public class Blog { 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) } @@ -214,8 +247,8 @@ 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(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) { @@ -240,8 +273,16 @@ public class Blog { //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) { diff --git a/source/de/anomic/data/blogBoard.java b/source/de/anomic/data/blogBoard.java index 999f217ef..69fcc7cce 100644 --- a/source/de/anomic/data/blogBoard.java +++ b/source/de/anomic/data/blogBoard.java @@ -124,7 +124,7 @@ public class blogBoard { 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); } @@ -133,24 +133,22 @@ public class blogBoard { 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()); } @@ -163,12 +161,12 @@ public class blogBoard { 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() { @@ -184,12 +182,12 @@ public class blogBoard { } } - 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() { @@ -221,7 +219,7 @@ public class blogBoard { 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;