From 0bf2eb481359741d6dd930d6d9b59d0e6d25b1f8 Mon Sep 17 00:00:00 2001 From: auron_x Date: Tue, 4 Apr 2006 15:10:59 +0000 Subject: [PATCH] *) fixed Blog updating timestamp on edit (now always keeps creation-date) git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1997 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/Blog.java | 13 ++++++++++--- source/de/anomic/data/blogBoard.java | 15 ++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/htroot/Blog.java b/htroot/Blog.java index 3def31d93..31d35951c 100644 --- a/htroot/Blog.java +++ b/htroot/Blog.java @@ -72,6 +72,7 @@ public class Blog { public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) { plasmaSwitchboard switchboard = (plasmaSwitchboard) env; serverObjects prop = new serverObjects(); + blogBoard.entry page = null; boolean hasRights = switchboard.verifyAuthentication(header, true); @@ -120,16 +121,22 @@ public class Blog { content = post.get("content", "").getBytes(); } - //set name for new entry + Date date = null; + + //set name for new entry or date for old entry if(pagename.equals("blog_default")) pagename = String.valueOf(System.currentTimeMillis()); + else { + page = switchboard.blogDB.read(pagename); //must I read it again after submitting? + date = page.date(); + } try { - switchboard.blogDB.write(switchboard.blogDB.newEntry(pagename, post.get("subject",""), author, ip, content)); + switchboard.blogDB.write(switchboard.blogDB.newEntry(pagename, post.get("subject",""), author, ip, date, content)); } catch (IOException e) {} } - blogBoard.entry page = switchboard.blogDB.read(pagename); + page = switchboard.blogDB.read(pagename); //maybe "if(page == null)" if (post.containsKey("edit")) { //edit an entry diff --git a/source/de/anomic/data/blogBoard.java b/source/de/anomic/data/blogBoard.java index deb9e050f..c777ae3d5 100644 --- a/source/de/anomic/data/blogBoard.java +++ b/source/de/anomic/data/blogBoard.java @@ -96,10 +96,6 @@ public class blogBoard { public void close() { try {datbase.close();} catch (IOException e) {} } - - private static String dateString() { - return dateString(new GregorianCalendar(GMTTimeZone).getTime()); - } private static String dateString(Date date) { return SimpleFormatter.format(date); @@ -123,8 +119,8 @@ public class blogBoard { return wikiBoard.guessAuthor(ip); } - public entry newEntry(String key, String subject, String author, String ip, byte[] page) throws IOException { - return new entry(normalize(key), subject, author, ip, page); + public entry newEntry(String key, String subject, String author, String ip, Date date, byte[] page) throws IOException { + return new entry(normalize(key), subject, author, ip, date, page); } public class entry { @@ -132,11 +128,12 @@ public class blogBoard { String key; Map record; - public entry(String nkey, String subject, String author, String ip, byte[] page) throws IOException { + public entry(String nkey, String subject, String author, String ip, Date date, byte[] page) throws IOException { record = new HashMap(); key = nkey; if (key.length() > keyLength) key = key.substring(0, keyLength); - record.put("date", dateString()); + 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"; @@ -215,7 +212,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", "".getBytes()); + if (record == null) return newEntry(key, "", "anonymous", "127.0.0.1", new GregorianCalendar(GMTTimeZone).getTime(), "".getBytes()); return new entry(key, record); } catch (IOException e) { return null;