From a1d68fe092e8a4bbfdd571089c39a65b741aba3e Mon Sep 17 00:00:00 2001 From: karlchenofhell Date: Tue, 27 Feb 2007 22:52:22 +0000 Subject: [PATCH] - use .class rather than Class.forName for classes in class-path - added Bost's patch for Diff.findDiagonale() from: http://www.yacy-forum.de//files/patch_685.txt - fixed minor bugs in Blog git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3416 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/Blog.html | 8 +- htroot/Blog.java | 156 +++++++++++--------- source/de/anomic/data/Diff.java | 32 ++-- source/de/anomic/http/httpdFileHandler.java | 6 +- test/de/anomic/data/DiffTest.java | 111 ++++++++++++++ 5 files changed, 225 insertions(+), 88 deletions(-) create mode 100644 test/de/anomic/data/DiffTest.java diff --git a/htroot/Blog.html b/htroot/Blog.html index 3c2c69ab6..ef14602ab 100644 --- a/htroot/Blog.html +++ b/htroot/Blog.html @@ -44,9 +44,9 @@ You can use Yacy-Wiki Code here.

-
+
- @@ -87,9 +87,9 @@ You can use Yacy-Wiki Code here.

-
+
- diff --git a/htroot/Blog.java b/htroot/Blog.java index 7f3290cd6..92d7cd90f 100644 --- a/htroot/Blog.java +++ b/htroot/Blog.java @@ -43,7 +43,7 @@ // Contributions and changes to the program code must be marked as such. // You must compile this file with -// javac -classpath .:../Classes Blacklist_p.java +// javac -classpath .:../classes Blog.java // if the shell's current path is HTROOT import java.io.IOException; @@ -78,28 +78,36 @@ public class Blog { blogBoard.entry page = null; boolean hasRights = switchboard.verifyAuthentication(header, true); + final boolean xml = ((String)header.get(httpHeader.CONNECTION_PROP_PATH)).endsWith(".xml"); + final String address = yacyCore.seedDB.mySeed.getAddress(); - if(hasRights) prop.put("mode_admin",1); - else prop.put("mode_admin",0); - + if(hasRights) { + prop.put("mode_admin",1); + } else { + prop.put("mode_admin",0); + } + if (post == null) { - post = new serverObjects(); - post.put("page", "blog_default"); + prop.put("peername", yacyCore.seedDB.mySeed.getName()); + prop.put("address", address); + return putBlogDefault(prop, switchboard, address, 0, 20, hasRights, xml); } - + + final int start = post.getInt("start",0); //indicates from where entries should be shown + final int num = post.getInt("num",20); //indicates how many entries should be shown + if(!hasRights){ userDB.Entry userentry = switchboard.userDB.proxyAuth((String)header.get("Authorization", "xxxxxx")); if(userentry != null && userentry.hasBlogRight()){ hasRights=true; - } - //opens login window if login link is clicked - contrib [MN] - else if(post.containsKey("login")){ + } else if(post.containsKey("login")) { + //opens login window if login link is clicked - contrib [MN] prop.put("AUTHENTICATE","admin log-in"); } } String pagename = post.get("page", "blog_default"); - String ip = post.get("CLIENTIP", "127.0.0.1"); + final String ip = post.get("CLIENTIP", "127.0.0.1"); String StrAuthor = post.get("author", ""); @@ -242,69 +250,9 @@ public class Blog { prop.put("mode", 0); //viewing if(pagename.equals("blog_default")) { prop.put("peername", yacyCore.seedDB.mySeed.getName()); - String address = yacyCore.seedDB.mySeed.getAddress(); prop.put("address", address); //index all entries - 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) - break; - pageid = (String) i.next(); - if(0 < start--) - continue; - entry = switchboard.blogDB.read(pageid); - prop.put("mode_entries_"+count+"_pageid",entry.key()); - prop.put("mode_entries_"+count+"_address", address); - if(!xml) { - 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.putWiki("mode_entries_"+count+"_page", 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.putASIS("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+"_ip", entry.ip()); - if(hasRights) { - prop.put("mode_entries_"+count+"_admin", 1); - prop.put("mode_entries_"+count+"_admin_pageid",entry.key()); - } - else prop.put("mode_entries_"+count+"_admin", 0); - if(entry.getCommentMode() != 0) { - prop.put("mode_entries_"+count+"_commentsactive", 1); - prop.put("mode_entries_"+count+"_commentsactive_pageid",entry.key()); - prop.put("mode_entries_"+count+"_commentsactive_comments", new String(entry.commentsSize(),"UTF-8")); - prop.put("mode_entries_"+count+"_commentsactive_address", address); - - } - else prop.put("mode_entries_"+count+"_commentsactive", 0); - - ++count; - } - prop.put("mode_entries",count); - if(i.hasNext()) { - prop.put("mode_moreentries",1); //more entries are availible - prop.put("mode_moreentries_start",nextstart); - prop.put("mode_moreentries_num",num); - } - else prop.put("moreentries",0); - } catch (IOException e) { - - } + putBlogDefault(prop, switchboard, address, start, num, hasRights, xml); } else { //only show 1 entry @@ -338,4 +286,68 @@ public class Blog { // return rewrite properties return prop; } + + private static serverObjects putBlogDefault( + serverObjects prop, + plasmaSwitchboard switchboard, + String address, + int start, + int num, + boolean hasRights, + boolean xml) { + try { + Iterator i = switchboard.blogDB.keys(false); + String pageid; + blogBoard.entry entry; + int count = 0; //counts how many entries are shown to the user + if(xml) num = 0; + int nextstart = start+num; //indicates the starting offset for next results + while(i.hasNext()) { + if(count >= num && num > 0) + break; + pageid = (String) i.next(); + if(0 < start--) + continue; + entry = switchboard.blogDB.read(pageid); + prop.put("mode_entries_"+count+"_pageid",entry.key()); + prop.put("mode_entries_"+count+"_address", address); + if(!xml) { + 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.putWiki("mode_entries_"+count+"_page", 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.putASIS("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+"_ip", entry.ip()); + if(hasRights) { + prop.put("mode_entries_"+count+"_admin", 1); + prop.put("mode_entries_"+count+"_admin_pageid",entry.key()); + } + else prop.put("mode_entries_"+count+"_admin", 0); + if(entry.getCommentMode() != 0) { + prop.put("mode_entries_"+count+"_commentsactive", 1); + prop.put("mode_entries_"+count+"_commentsactive_pageid",entry.key()); + prop.put("mode_entries_"+count+"_commentsactive_comments", new String(entry.commentsSize(),"UTF-8")); + prop.put("mode_entries_"+count+"_commentsactive_address", address); + + } + else prop.put("mode_entries_"+count+"_commentsactive", 0); + + ++count; + } + prop.put("mode_entries",count); + if(i.hasNext()) { + prop.put("mode_moreentries",1); //more entries are availible + prop.put("mode_moreentries_start",nextstart); + prop.put("mode_moreentries_num",num); + } + else prop.put("moreentries",0); + } catch (IOException e) { } + return prop; + } } diff --git a/source/de/anomic/data/Diff.java b/source/de/anomic/data/Diff.java index 01c8d099d..c37f81ee8 100644 --- a/source/de/anomic/data/Diff.java +++ b/source/de/anomic/data/Diff.java @@ -131,22 +131,36 @@ public class Diff { if (starty < endy) this.parts.add(new Part(Part.ADDED, starty, endy)); } + /** Search for a diagonal with minimal length minLength line by line in a submatrix + * { x, y, matrix[0].length, matrix.length} of the matrix:
+ *       {_1,__,__} -> X axis
+ *      ,{__,_1,__}
+ *      ,{__,__,_1}
+ * + * @param x the starting position of the search on the optical horizontal axis + * @param y the starting position of the search on the optical vertical axis
+ * @param matrix the matrix to search through + * @param minLength the minimal desired length of a diagonal to find + * @return a vector in the form { diagStartX, diagStartY, diagLength } where diagLength >= minLength + */ private static int[] findDiagonal(int x, int y, boolean[][] matrix, int minLength) { int rx, ry, yy, xx, i; - // Zeilenweise nach Diagonalen mit mindest-Laenge minLength suchen for (yy=y; yy zuwenige chars in Diagonale => weitersuchen - continue; - } else { - return new int[] { rx, ry, i }; - } + if (!matrix[yy + i][xx + i]) + break; + if (i >= minLength) + return new int[] { rx, ry, i }; // swap back the x and y axes for better readability } return null; } diff --git a/source/de/anomic/http/httpdFileHandler.java b/source/de/anomic/http/httpdFileHandler.java index ba7b499ef..95638b6a0 100644 --- a/source/de/anomic/http/httpdFileHandler.java +++ b/source/de/anomic/http/httpdFileHandler.java @@ -1032,9 +1032,9 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http //System.out.println("**DEBUG** loading class file " + classFile); Class c = provider.loadClass(classFile); Class[] params = new Class[] { - Class.forName("de.anomic.http.httpHeader"), - Class.forName("de.anomic.server.serverObjects"), - Class.forName("de.anomic.server.serverSwitch")}; + httpHeader.class, + serverObjects.class, + serverSwitch.class }; m = c.getMethod("respond", params); if (useTemplateCache) { diff --git a/test/de/anomic/data/DiffTest.java b/test/de/anomic/data/DiffTest.java new file mode 100644 index 000000000..af6706ab9 --- /dev/null +++ b/test/de/anomic/data/DiffTest.java @@ -0,0 +1,111 @@ +package de.anomic.data; + +import junit.framework.TestCase; + +public class DiffTest extends TestCase { + final static boolean _1 = true; // temporary variables to make the matrix more readable + final static boolean __ = false; + + boolean[][] matrix = + { +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 + {__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,_1,_1,_1} +,{__,__,__,__,__,__,__,__,__,__,_1,__,__,__,__,__,__,_1,_1,_1} +,{__,__,__,__,__,__,__,__,__,__,__,_1,__,__,__,__,__,_1,_1,_1} +,{__,__,__,__,__,__,__,__,__,__,__,__,_1,__,__,__,__,_1,_1,_1} +,{__,__,__,__,__,__,__,__,__,__,__,__,__,_1,__,__,__,_1,_1,_1} +,{__,__,__,__,__,__,__,__,__,__,__,__,__,__,_1,__,__,_1,_1,_1} +,{__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,_1,__,_1,_1,_1} +,{__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,_1,_1,_1,_1} +,{__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,_1,_1,_1} +,{__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,_1,_1,_1} +,{__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,_1,_1,_1} +,{__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,_1,_1,_1} +,{__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,_1,_1,_1} +,{__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,_1,_1,_1} +,{_1,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,_1,_1,_1} +,{__,_1,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,_1,_1,_1} +,{__,__,_1,__,__,__,__,__,__,__,__,__,__,__,__,__,__,_1,_1,_1} +,{__,__,__,_1,__,__,__,__,__,__,__,__,__,__,__,__,__,_1,_1,_1} +,{__,__,__,__,_1,__,__,__,__,__,__,__,__,__,__,__,__,_1,_1,_1} +,{__,__,__,__,__,_1,__,__,__,__,__,__,__,__,__,__,__,_1,_1,_1} +,{__,__,__,__,__,__,_1,__,__,__,__,__,__,__,__,__,__,_1,_1,_1} + }; +/* + boolean[][] matrix = // [x][y] // a another test matrix + { +// 0 1 2 3 4 5 // X == 6 + {__,__,__,__,__,__} // 0 +,{_1,__,__,__,__,__} // 1 +,{__,_1,__,__,__,__} // 2 +,{__,__,_1,__,__,__} // 3 +,{__,__,__,_1,__,__} // 4 +,{__,__,__,__,_1,__} // 5 +,{__,__,__,__,__,_1} // 6 + }; // Y == 7 +*/ + /** the old buggy version */ + private static int[] findDiagonalOld(int x, int y, boolean[][] matrix, int minLength) { + int rx, ry, yy, xx, i; + // Zeilenweise nach Diagonalen mit mindest-Laenge minLength suchen + for (yy=y; yy zuwenige chars in Diagonale => weitersuchen + continue; + } else { + return new int[] { rx, ry, i }; + } + } + return null; + } + + /** the fixed version */ + private static int[] findDiagonalNew(int x, int y, boolean[][] matrix, int minLength) { + int rx, ry, yy, xx, i; + for (yy=y; yy= minLength) + return new int[] { rx, ry, i }; // swap back the x and y axes for better readability + } + return null; + } + + public void testReplace() + { + int[] vectorOld; + int[] vectorNew; + int minLength = 6; + int x = 0; + int y = 0; + + System.out.println("matrix.length: " + matrix.length) ; + System.out.println("matrix[0].length: " + matrix[0].length) ; + + vectorOld = findDiagonalOld(x, y, matrix, minLength); + vectorNew = findDiagonalNew(x, y, matrix, minLength); + + System.out.print("vectorOld: [ "); + if (vectorOld != null) + for (int i = 0; i < vectorOld.length; i++) + System.out.print(vectorOld[i] + ", "); + System.out.println("]"); + + System.out.print("vectorNew: [ "); + if (vectorNew != null) + for (int i = 0; i < vectorNew.length; i++) + System.out.print(vectorNew[i] + ", "); + System.out.println("]"); + } +} \ No newline at end of file