
import com.orientechnologies.orient.core.record.impl.ODocument;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import permeagility.util.DatabaseConnection;
import permeagility.util.QueryResult;
import permeagility.web.Weblet;

/** Test type 4: Fortunes
 */
public final class fortunes extends Weblet {

    @Override public String getPage(DatabaseConnection con, HashMap<String, String> parms) {
        QueryResult qr = con.query("SELECT FROM Fortune");
        ODocument newDoc = new ODocument().field("id",0).field("message","Additional fortune added at request time.");
        qr.append(newDoc);

        // Sort the new list
        Collections.sort(qr.get(), new Comparator() {
            public int compare(Object o1, Object o2) {
                ODocument d1 = (ODocument)o1;
                ODocument d2 = (ODocument)o2;
                String m1 = d1.field("message");
                String m2 = d2.field("message");
                return m1.compareTo(m2);
            }
        });

        StringBuilder sb = new StringBuilder();
        for (int i=0;i<qr.size();i++) {
            String stringvalue = qr.getStringValue(i, "message");
            if (stringvalue != null) {
                stringvalue = stringvalue.replace("<", "&lt;"); // These can mess up the display
                stringvalue = stringvalue.replace(">", "&gt;");
            }

            sb.append("<tr>"+column(qr.getStringValue(i, "id"))+column(stringvalue)+"</tr>");
            //System.out.println("Fortune:"+qr.getStringValue(i, "message"));
        }

        return "<head><title>Fortunes</title></head><body>"
            +table(
                "<tr>"+columnHeader("id")+columnHeader("message")+"</tr>"
                +sb.toString())
            +"</body>";
    }

}

@@ -1430,17 +1430,14 @@
 %3Ctr%3E
-%22+column(
+%3Ctd%3E%22+
 qr.g
@@ -1462,17 +1462,21 @@
 id%22)
-)+column(
++%22%3C/td%3E%3Ctd%3E%22+
 stri
@@ -1482,24 +1482,30 @@
 ingvalue
-)
 +%22%3C/t
-r%3E
+d%3E%3C/tr%3E%5Cn
 %22);%0A    
@@ -1645,14 +1645,10 @@
 ead%3E
-%3Cbody%3E
+%5Cn
 %22%0A  
@@ -1662,14 +1662,25 @@
    +
+%22%3Cbody%3E%3C
 table
-(
+%3E%5Cn%22
 %0A   
@@ -1692,51 +1692,37 @@
     
-    
++
 %22%3Ctr%3E
-%22+columnHeader(%22id%22)+columnHeader(
+%3Cth%3E%22+%22id%22+%22%3C/th%3E%3Cth%3E%22+
 %22mes
@@ -1730,20 +1730,24 @@
 age%22
-)
 +%22%3C/t
-r%3E%22%0A  
+h%3E%3C/tr%3E%5Cn%22%0A
     
@@ -1754,18 +1754,16 @@
         
-  
 +sb.toSt
@@ -1768,17 +1768,16 @@
 String()
-)
 %0A       
@@ -1785,16 +1785,24 @@
     +%22%3C/
+table%3E%3C/
 body%3E%22;%0A

Reformat to try to pass test