
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",13).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(row(column(qr.getStringValue(i, "id"))+column(stringvalue)));
            //System.out.println("Fortune:"+qr.getStringValue(i, "message"));
        }

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

}

@@ -545,10 +545,9 @@
 id%22,
-13
+0
 ).fi
@@ -1420,20 +1420,23 @@
 .append(
-row(
+%22%3Ctr%3E%22+
 column(q
@@ -1481,17 +1481,24 @@
 ngvalue)
-)
++%22%3C/tr%3E%22
 );%0A     
@@ -1640,16 +1640,29 @@
 %3E%3Cbody%3E%22
+%0A            
 +table(%22
@@ -1675,12 +1675,32 @@
 le%22,
-row(
+%0A                %22%3Ctr%3E%22+
 colu
@@ -1737,17 +1737,41 @@
 essage%22)
-)
++%22%3C/tr%3E%22%0A                
 +sb.toSt
@@ -1777,16 +1777,29 @@
 tring())
+%0A            
 +%22%3C/body

Fix fortunes