Wj Kj

It bugged me (ChristianRamseyer? aka. rc@networkz.ch) that there was no Java candidate for the ShortestWikiContest. So, although it was clear that most of the other languages would beat java hands down, I invested an hour or two to come up with a 16 lines, 1212 bytes platform-independent JSP Wiki.

WjKj lives at http://www.networkz.ch/wjkj [broken link]

While writing the code, it came to my mind that there must be some Ents (the "Shepherds of the Trees" from "Lord of the Rings") sitting in the Java design team. It takes really really long to say something in JavaLanguage compared to PerlLanguage. Here's an example:

 File f=new File(c+p);
  if (!f.exists())
    f.createNewFile();
 DataOutputStream o=new DataOutputStream(new FileOutputStream(f));

vs.

 open F,">$&";

Like data compression, one encoding may express some things in a compact way, but it will have to express other things in a more verbose way to make up for it. Perl is tuned for "compressing" text manipulation, but it will be bad at compressing some other things. And of course, the Java version is easy to read for someone who doesn't know Java. To someone who doesn't know Perl, you may as well have run the Java version through a zip algorithm. -- MichaelSparks


This source is from http://web.archive.org/web/20050502223553/www.networkz.ch/wjkj/ -- MarkusSrank

 <%@page import="java.io.*,java.util.regex.*"%><html><title>wJkJ</title><body><%
 String c="/tmp/wiki/";String p=request.getQueryString();if(p==null||!(p.matches(
 "^[A-Z][a-z]+.*")))p="HomePage";out.print("wJkJ: "+p+"<br><br>");File f=new File
 (c+p);if(!f.exists())f.createNewFile();if(request.getMethod().equals("POST")){
 DataOutputStream o=new DataOutputStream(new FileOutputStream(f));o.writeBytes(
 request.getParameter("in"));o.close();}File[] d=(new File(c)).listFiles();String
 b="";Z:for(int i=0;i<d.length;i++){DataInputStream s=new DataInputStream(new 
 FileInputStream(d[i]));while (s.available()>0){if(s.readLine().matches(".*"+p+
 ".*")){b+=d[i].getName()+" ";continue Z;}}}out.print(b.replaceAll("((?:[A-Z]"+
 "\\w+){2,})","<a href=\\\"?$1\\\">$1</a>")+"<br><hr>");DataInputStream i=new
 DataInputStream(new FileInputStream(f));String t="";while(i.available()>0)t+=i.
 readLine()+"\n";out.print(t.replaceAll("(http:\\S+)"," <a href=$1>$1</a>").
 replaceAll("(?m)(^| )((?:[A-Z]\\w+){2,})"," <a href=?$2>$2</a>").replaceAll(
 "\\\n","<br>")+"<br><hr><br><form method=post action=wjkj.jsp?"+p+"><textarea "+
 "name=\"in\" cols=\"80\" rows=\"15\">"+t+"</textarea>");%><br><input type=submit>
 </form></body></html>

 <!-- wJkJ very short wiki 
Installation: 
    - create the directory referenced by "c"
    - put file on a JSP-capable server
    - needs Java 1.4+
 -->
 <%@page import="java.io.*,java.util.regex.*"%><html><title>wJkJ</title><body>
 <%
String c="/tmp/wiki/";
        String p=request.getQueryString();
        if (p==null||!(p.matches("^[A-Z][a-z]+.*")) ){
            p="HomePage";
        }
        out.print("wJkJ: "+p+"<br><br>");
        File f=new File(c+p);
        if (!f.exists())
            f.createNewFile();
        if (request.getMethod().equals("POST")) {
            DataOutputStream o=new DataOutputStream(new FileOutputStream(f));
            o.writeBytes(request.getParameter("in"));
            o.close();
        }
        File[] d=(new File(c)).listFiles();
        String b="";
        Z: for(int i=0;i<d.length;i++){
            DataInputStream s=new DataInputStream(new FileInputStream(d[i]));
            while (s.available()>0) {
                if (s.readLine().matches(".*"+p+".*")) {
                    b+=d[i].getName()+" ";
                    continue Z;
                }
            }
        }
        out.print(b.replaceAll("([A-Z][a-z]+[A-Z][a-z].*?\\b)","<a "
                +" href=\\\"?$1\\\">$1</a>")
                +"<br><hr>");
        DataInputStream i=new DataInputStream(new FileInputStream(f));
        String t="";
        while (i.available()>0)
            t+=i.readLine()+"\n";
out.print(t.replaceAll("(http:\\S+)"," <a href=$1>$1</a>")
.replaceAll("(?m)(^| )((?:[A-Z]\\w+){2,})"," <a href=?$2>$2</a>") 
.replaceAll("\\\n","<br>") 
+ "<br><hr><br><form method=post action=wjkj.jsp?"+p+">" 
+ "<textarea name=\"in\" cols=\"80\" rows=\"15\">"+t+"</textarea>");
 %>  
 <br><input type=submit></form></body></html>

License: GNU GPL


CategoryWikiImplementation


EditText of this page (last edited December 18, 2010) or FindPage with title or text search