Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
- 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
karlchenofhella1d68fe092e8
diff --git a/htroot/Blog.html b/htroot/Blog.htmlindex 3c2c69ab6..ef14602ab 100644--- a/htroot/Blog.html+++ b/htroot/Blog.html@@ -44,9 +44,9 @@You can use <a href="WikiHelp.html" onclick="window.open('WikiHelp.html','WikiHelp','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=480');return false;">Yacy-Wiki Code</a> here.</p></dd>- <dt><label for="subject">Comments:</label></dt>+ <dt><label for="commentMode">Comments:</label></dt><dd>- <select name="commentMode">+ <select name="commentMode" id="commentMode"><option value="0" #(commentMode)#selected="selected"::#(/commentMode)#>deactivated</option><option value="1" #(commentMode)#::selected="selected"#(/commentMode)#>activated</option></select>@@ -87,9 +87,9 @@You can use <a href="WikiHelp.html" onclick="window.open('WikiHelp.html','WikiHelp','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=480');return false;">Yacy-Wiki Code</a> here.</p></dd>- <dt><label for="subject">Comments:</label></dt>+ <dt><label for="commentMode">Comments:</label></dt><dd>- <select name="commentMode">+ <select name="commentMode" id="commentMode"><option value="0" #(commentMode)#selected="selected"::#(/commentMode)#>deactivated</option><option value="1" #(commentMode)#::selected="selected"#(/commentMode)#>activated</option></select>diff --git a/htroot/Blog.java b/htroot/Blog.javaindex 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 HTROOTimport 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); //viewingif(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 propertiesreturn 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.javaindex 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 <code>minLength</code> line by line in a submatrix+ * <code>{ x, y, matrix[0].length, matrix.length}</code> of the <code>matrix</code>:<br>+ * <code> {_1,__,__} -> X axis</code><br>+ * <code> ,{__,_1,__} </code><br>+ * <code> ,{__,__,_1} </code><br>+ * <ul>+ * TODO: some optimisation ideas see the discusion <a href="http://www.yacy-forum.de/viewtopic.php?t=3557">Diff.findDiagonal(..) buggy????</a>+ * <li>search for a better algorithm on the inet!!! :) </li>+ * <li>pass only the part of the matrix where the search takes place - not the whole matrix everytime</li>+ * <li>break the inner loop if the rest of the matrix is smaller than minLength (and no diagonal has been found yet) </li>+ * <li>return diagonal topologicaly closest to the {0,0} </li>+ * </ul>+ * @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<br>+ * @param matrix the matrix to search through+ * @param minLength the minimal desired length of a diagonal to find+ * @return a vector in the form <code>{ diagStartX, diagStartY, diagLength }</code> where <code> diagLength >= minLength</code>+ */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 suchenfor (yy=y; yy<matrix.length; yy++)for (xx=x; xx<matrix[yy].length; xx++)- if (matrix[yy][xx]) {+ if (matrix[yy][xx]) { // reverse order! [y][x]rx = xx;ry = yy;for (i=1; (yy + i)<matrix.length && (xx + i)<matrix[yy].length; i++)- if (!matrix[yy + i][xx + i]) break;- if (i <= minLength && yy + i < matrix.length && xx + i < matrix[yy].length) {- // vorzeitig abgebrochen => 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.javaindex 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.javanew file mode 100644index 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<matrix.length; yy++)+ for (xx=x; xx<matrix[yy].length; xx++)+ if (matrix[yy][xx]) {+ rx = xx;+ ry = yy;+ for (i=1; (yy + i)<matrix.length && (xx + i)<matrix[yy].length; i++)+ if (!matrix[yy + i][xx + i]) break;+ if (i <= minLength && yy + i < matrix.length && xx + i < matrix[yy].length) {+ // vorzeitig abgebrochen => 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<matrix.length; yy++)+ for (xx=x; xx<matrix[yy].length; xx++)+ if (matrix[yy][xx]) { // reverse order! [y][x]+ rx = xx;+ ry = yy;+ for (i=1; (yy + i)<matrix.length && (xx + i)<matrix[yy].length; 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;+ }++ 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