diff --git a/src/main/java/com/metaweb/gridworks/commands/util/GetExpressionLanguageInfoCommand.java b/src/main/java/com/metaweb/gridworks/commands/util/GetExpressionLanguageInfoCommand.java index e1dc753ae..7f8d47968 100644 --- a/src/main/java/com/metaweb/gridworks/commands/util/GetExpressionLanguageInfoCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/util/GetExpressionLanguageInfoCommand.java @@ -1,6 +1,7 @@ package com.metaweb.gridworks.commands.util; import java.io.IOException; +import java.util.Properties; import java.util.Map.Entry; import javax.servlet.ServletException; @@ -22,6 +23,8 @@ public class GetExpressionLanguageInfoCommand extends Command { try { JSONWriter writer = new JSONWriter(response.getWriter()); + Properties options = new Properties(); + writer.object(); writer.key("functions"); @@ -29,8 +32,7 @@ public class GetExpressionLanguageInfoCommand extends Command { { for (Entry entry : Parser.functionTable.entrySet()) { writer.key(entry.getKey()); - writer.object(); - writer.endObject(); + entry.getValue().write(writer, options); } } writer.endObject(); @@ -40,8 +42,7 @@ public class GetExpressionLanguageInfoCommand extends Command { { for (Entry entry : Parser.controlTable.entrySet()) { writer.key(entry.getKey()); - writer.object(); - writer.endObject(); + entry.getValue().write(writer, options); } } writer.endObject(); diff --git a/src/main/java/com/metaweb/gridworks/expr/Control.java b/src/main/java/com/metaweb/gridworks/expr/Control.java index 67432c365..4235746b7 100644 --- a/src/main/java/com/metaweb/gridworks/expr/Control.java +++ b/src/main/java/com/metaweb/gridworks/expr/Control.java @@ -2,6 +2,8 @@ package com.metaweb.gridworks.expr; import java.util.Properties; -public interface Control { +import com.metaweb.gridworks.Jsonizable; + +public interface Control extends Jsonizable { public Object call(Properties bindings, Evaluable[] args); } diff --git a/src/main/java/com/metaweb/gridworks/expr/Function.java b/src/main/java/com/metaweb/gridworks/expr/Function.java index eb168bed1..4b647c581 100644 --- a/src/main/java/com/metaweb/gridworks/expr/Function.java +++ b/src/main/java/com/metaweb/gridworks/expr/Function.java @@ -2,6 +2,8 @@ package com.metaweb.gridworks.expr; import java.util.Properties; -public interface Function { +import com.metaweb.gridworks.Jsonizable; + +public interface Function extends Jsonizable { public Object call(Properties bindings, Object[] args); } diff --git a/src/main/java/com/metaweb/gridworks/expr/OperatorCallExpr.java b/src/main/java/com/metaweb/gridworks/expr/OperatorCallExpr.java index 507cb859d..fde798dd8 100644 --- a/src/main/java/com/metaweb/gridworks/expr/OperatorCallExpr.java +++ b/src/main/java/com/metaweb/gridworks/expr/OperatorCallExpr.java @@ -17,72 +17,46 @@ public class OperatorCallExpr implements Evaluable { args[i] = _args[i].evaluate(bindings); } - if ("+".equals(_op)) { - if (args.length == 2) { - if (args[0] instanceof Number && args[1] instanceof Number) { - return ((Number) args[0]).doubleValue() + ((Number) args[1]).doubleValue(); - } else { - return args[0].toString() + args[1].toString(); - } - } - } else if ("-".equals(_op)) { - if (args.length == 2) { - if (args[0] instanceof Number && args[1] instanceof Number) { - return ((Number) args[0]).doubleValue() - ((Number) args[1]).doubleValue(); - } - } - } else if ("*".equals(_op)) { - if (args.length == 2) { - if (args[0] instanceof Number && args[1] instanceof Number) { - return ((Number) args[0]).doubleValue() * ((Number) args[1]).doubleValue(); - } - } - } else if ("/".equals(_op)) { - if (args.length == 2) { - if (args[0] instanceof Number && args[1] instanceof Number) { - return ((Number) args[0]).doubleValue() / ((Number) args[1]).doubleValue(); - } - } - } else if (">".equals(_op)) { - if (args.length == 2) { + if (args.length == 2) { + if (args[0] != null && args[1] != null) { if (args[0] instanceof Number && args[1] instanceof Number) { - return ((Number) args[0]).doubleValue() > ((Number) args[1]).doubleValue(); + if ("+".equals(_op)) { + return ((Number) args[0]).doubleValue() + ((Number) args[1]).doubleValue(); + } else if ("-".equals(_op)) { + return ((Number) args[0]).doubleValue() - ((Number) args[1]).doubleValue(); + } else if ("*".equals(_op)) { + return ((Number) args[0]).doubleValue() * ((Number) args[1]).doubleValue(); + } else if ("/".equals(_op)) { + return ((Number) args[0]).doubleValue() / ((Number) args[1]).doubleValue(); + } else if (">".equals(_op)) { + return ((Number) args[0]).doubleValue() > ((Number) args[1]).doubleValue(); + } else if (">=".equals(_op)) { + return ((Number) args[0]).doubleValue() >= ((Number) args[1]).doubleValue(); + } else if ("<".equals(_op)) { + return ((Number) args[0]).doubleValue() < ((Number) args[1]).doubleValue(); + } else if ("<=".equals(_op)) { + return ((Number) args[0]).doubleValue() <= ((Number) args[1]).doubleValue(); + } } - } - } else if (">=".equals(_op)) { - if (args.length == 2) { - if (args[0] instanceof Number && args[1] instanceof Number) { - return ((Number) args[0]).doubleValue() >= ((Number) args[1]).doubleValue(); - } - } - } else if ("<".equals(_op)) { - if (args.length == 2) { - if (args[0] instanceof Number && args[1] instanceof Number) { - return ((Number) args[0]).doubleValue() < ((Number) args[1]).doubleValue(); - } - } - } else if ("<=".equals(_op)) { - if (args.length == 2) { - if (args[0] instanceof Number && args[1] instanceof Number) { - return ((Number) args[0]).doubleValue() <= ((Number) args[1]).doubleValue(); - } - } - } else if ("==".equals(_op)) { - if (args.length == 2) { + + if ("+".equals(_op)) { + return args[0].toString() + args[1].toString(); + } + } + + if ("==".equals(_op)) { if (args[0] != null) { return args[0].equals(args[1]); } else { return args[1] == null; } - } - } else if ("!=".equals(_op)) { - if (args.length == 2) { + } else if ("!=".equals(_op)) { if (args[0] != null) { return !args[0].equals(args[1]); } else { return args[1] != null; } - } + } } return null; } diff --git a/src/main/java/com/metaweb/gridworks/expr/controls/ForEach.java b/src/main/java/com/metaweb/gridworks/expr/controls/ForEach.java index f66bac996..7845d88ac 100644 --- a/src/main/java/com/metaweb/gridworks/expr/controls/ForEach.java +++ b/src/main/java/com/metaweb/gridworks/expr/controls/ForEach.java @@ -4,6 +4,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Control; import com.metaweb.gridworks.expr.Evaluable; import com.metaweb.gridworks.expr.VariableExpr; @@ -49,5 +52,16 @@ public class ForEach implements Control { } return null; } - + + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value( + "Evaluates expression a to an array. Then for each array element, binds its value to variable name v, evaluates expression e, and pushes the result onto the result array." + ); + writer.key("params"); writer.value("expression a, variable v, expression e"); + writer.key("returns"); writer.value("array"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/controls/ForNonBlank.java b/src/main/java/com/metaweb/gridworks/expr/controls/ForNonBlank.java index ed7398b3f..3ddb60746 100644 --- a/src/main/java/com/metaweb/gridworks/expr/controls/ForNonBlank.java +++ b/src/main/java/com/metaweb/gridworks/expr/controls/ForNonBlank.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.controls; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Control; import com.metaweb.gridworks.expr.Evaluable; import com.metaweb.gridworks.expr.ExpressionUtils; @@ -36,4 +39,16 @@ public class ForNonBlank implements Control { return null; } + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value( + "Evaluates expression o. If it is non-blank, binds its value to variable name v, evaluates expression eNonBlank and returns the result. " + + "Otherwise (if o evaluates to blank), evaluates expression eBlank and returns that result instead." + ); + writer.key("params"); writer.value("expression o, variable v, expression eNonBlank, expression eBlank"); + writer.key("returns"); writer.value("Depends on actual arguments"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/controls/If.java b/src/main/java/com/metaweb/gridworks/expr/controls/If.java index 8a07eef5a..43e6ad0dd 100644 --- a/src/main/java/com/metaweb/gridworks/expr/controls/If.java +++ b/src/main/java/com/metaweb/gridworks/expr/controls/If.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.controls; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Control; import com.metaweb.gridworks.expr.Evaluable; import com.metaweb.gridworks.expr.ExpressionUtils; @@ -20,5 +23,17 @@ public class If implements Control { } return null; } - + + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value( + "Evaluates expression o. If it is true, evaluates expression eTrue and returns the result. " + + "Otherwise, evaluates expression eFalse and returns that result instead." + ); + writer.key("params"); writer.value("expression o, expression eTrue, expression eFalse"); + writer.key("returns"); writer.value("Depends on actual arguments"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/controls/With.java b/src/main/java/com/metaweb/gridworks/expr/controls/With.java index 4662c4c20..d311d1e08 100644 --- a/src/main/java/com/metaweb/gridworks/expr/controls/With.java +++ b/src/main/java/com/metaweb/gridworks/expr/controls/With.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.controls; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Control; import com.metaweb.gridworks.expr.Evaluable; import com.metaweb.gridworks.expr.VariableExpr; @@ -32,5 +35,16 @@ public class With implements Control { } return null; } - + + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value( + "Evaluates expression o and binds its value to variable name v. Then evaluates expression e and returns that result" + ); + writer.key("params"); writer.value("expression o, variable v, expression eNonBlank, expression eBlank"); + writer.key("returns"); writer.value("Depends on actual arguments"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/And.java b/src/main/java/com/metaweb/gridworks/expr/functions/And.java index ba0e1fe81..3cc7bc9d7 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/And.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/And.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class And implements Function { @@ -14,4 +17,14 @@ public class And implements Function { } return true; } + + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("ANDs two boolean values"); + writer.key("params"); writer.value("boolean a, boolean b"); + writer.key("returns"); writer.value("boolean"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/Ceil.java b/src/main/java/com/metaweb/gridworks/expr/functions/Ceil.java index 4f9c5704b..6d9b2207a 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/Ceil.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/Ceil.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class Ceil implements Function { @@ -13,4 +16,13 @@ public class Ceil implements Function { return null; } + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns the ceiling of a number"); + writer.key("params"); writer.value("number d"); + writer.key("returns"); writer.value("number"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/EndsWith.java b/src/main/java/com/metaweb/gridworks/expr/functions/EndsWith.java index 19def4be8..8586c9298 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/EndsWith.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/EndsWith.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class EndsWith implements Function { @@ -17,4 +20,13 @@ public class EndsWith implements Function { return null; } + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns whether s ends with sub"); + writer.key("params"); writer.value("string s, string sub"); + writer.key("returns"); writer.value("boolean"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/Floor.java b/src/main/java/com/metaweb/gridworks/expr/functions/Floor.java index b70ee2be9..30e773e59 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/Floor.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/Floor.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class Floor implements Function { @@ -12,5 +15,15 @@ public class Floor implements Function { } return null; } + + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns the floor of a number"); + writer.key("params"); writer.value("number d"); + writer.key("returns"); writer.value("number"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/Get.java b/src/main/java/com/metaweb/gridworks/expr/functions/Get.java index 0075d5714..d1f017885 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/Get.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/Get.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; import com.metaweb.gridworks.expr.HasFields; @@ -75,4 +78,17 @@ public class Get implements Function { return null; } + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value( + "If o has fields, returns the field named 'from' of o. " + + "If o is an array, returns o[from, to]. " + + "if o is a string, returns o.substring(from, to)" + ); + writer.key("params"); writer.value("o, number or string from, optional number to"); + writer.key("returns"); writer.value("Depends on actual arguments"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/IndexOf.java b/src/main/java/com/metaweb/gridworks/expr/functions/IndexOf.java index e6ce4aa19..09f586373 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/IndexOf.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/IndexOf.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class IndexOf implements Function { @@ -17,4 +20,13 @@ public class IndexOf implements Function { return null; } + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns the index of sub first ocurring in s"); + writer.key("params"); writer.value("string s, string sub"); + writer.key("returns"); writer.value("number"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/IsBlank.java b/src/main/java/com/metaweb/gridworks/expr/functions/IsBlank.java index efbf6d151..689e08c7e 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/IsBlank.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/IsBlank.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.ExpressionUtils; import com.metaweb.gridworks.expr.Function; @@ -11,4 +14,13 @@ public class IsBlank implements Function { return args.length == 0 || ExpressionUtils.isBlank(args[0]); } + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns whether o is null or an empty string"); + writer.key("params"); writer.value("o"); + writer.key("returns"); writer.value("boolean"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/IsNotBlank.java b/src/main/java/com/metaweb/gridworks/expr/functions/IsNotBlank.java index 68a74b3cd..a7231abc4 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/IsNotBlank.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/IsNotBlank.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.ExpressionUtils; import com.metaweb.gridworks.expr.Function; @@ -11,4 +14,13 @@ public class IsNotBlank implements Function { return args.length > 0 && !ExpressionUtils.isBlank(args[0]); } + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns whether o is not null and not an empty string"); + writer.key("params"); writer.value("o"); + writer.key("returns"); writer.value("boolean"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/IsNotNull.java b/src/main/java/com/metaweb/gridworks/expr/functions/IsNotNull.java index 6081c2235..e4ed7b742 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/IsNotNull.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/IsNotNull.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class IsNotNull implements Function { @@ -10,4 +13,13 @@ public class IsNotNull implements Function { return args.length > 0 && args[0] != null; } + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns whether o is not null"); + writer.key("params"); writer.value("o"); + writer.key("returns"); writer.value("boolean"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/IsNull.java b/src/main/java/com/metaweb/gridworks/expr/functions/IsNull.java index c24ed8b9a..3c6ea497d 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/IsNull.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/IsNull.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class IsNull implements Function { @@ -10,4 +13,13 @@ public class IsNull implements Function { return args.length == 0 || args[0] == null; } + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns whether o is null"); + writer.key("params"); writer.value("o"); + writer.key("returns"); writer.value("boolean"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/Join.java b/src/main/java/com/metaweb/gridworks/expr/functions/Join.java index a4f402889..111b2b9b5 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/Join.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/Join.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class Join implements Function { @@ -33,4 +36,13 @@ public class Join implements Function { return null; } + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns the string obtained by joining the array a with the separator sep"); + writer.key("params"); writer.value("array a, string sep"); + writer.key("returns"); writer.value("string"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/LastIndexOf.java b/src/main/java/com/metaweb/gridworks/expr/functions/LastIndexOf.java index 751db55c7..f27d64f24 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/LastIndexOf.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/LastIndexOf.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class LastIndexOf implements Function { @@ -16,5 +19,15 @@ public class LastIndexOf implements Function { } return null; } + + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns the index of sub last ocurring in s"); + writer.key("params"); writer.value("string s, string sub"); + writer.key("returns"); writer.value("number"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/Length.java b/src/main/java/com/metaweb/gridworks/expr/functions/Length.java index da640225c..432a2b711 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/Length.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/Length.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class Length implements Function { @@ -23,4 +26,13 @@ public class Length implements Function { return null; } + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns the length of o"); + writer.key("params"); writer.value("array or string o"); + writer.key("returns"); writer.value("number"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/Ln.java b/src/main/java/com/metaweb/gridworks/expr/functions/Ln.java index 1ae4ddc74..7eda0fb21 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/Ln.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/Ln.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class Ln implements Function { @@ -13,4 +16,13 @@ public class Ln implements Function { return null; } + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns the natural log of n"); + writer.key("params"); writer.value("number n"); + writer.key("returns"); writer.value("number"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/Log.java b/src/main/java/com/metaweb/gridworks/expr/functions/Log.java index 29523fd9a..de4273e5a 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/Log.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/Log.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class Log implements Function { @@ -13,4 +16,13 @@ public class Log implements Function { return null; } + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns the base 10 log of n"); + writer.key("params"); writer.value("number n"); + writer.key("returns"); writer.value("number"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/Max.java b/src/main/java/com/metaweb/gridworks/expr/functions/Max.java index aa6e68036..33c0a9832 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/Max.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/Max.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class Max implements Function { @@ -15,4 +18,13 @@ public class Max implements Function { return null; } + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns the greater of two numbers"); + writer.key("params"); writer.value("number a, number b"); + writer.key("returns"); writer.value("number"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/Min.java b/src/main/java/com/metaweb/gridworks/expr/functions/Min.java index e8d63f055..7df1b8f74 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/Min.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/Min.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class Min implements Function { @@ -15,4 +18,13 @@ public class Min implements Function { return null; } + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns the smaller of two numbers"); + writer.key("params"); writer.value("number a, number b"); + writer.key("returns"); writer.value("number"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/Mod.java b/src/main/java/com/metaweb/gridworks/expr/functions/Mod.java index e8c84ee23..09dd2b0f8 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/Mod.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/Mod.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class Mod implements Function { @@ -16,4 +19,13 @@ public class Mod implements Function { return null; } + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns a modulus b"); + writer.key("params"); writer.value("number a, number b"); + writer.key("returns"); writer.value("number"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/Not.java b/src/main/java/com/metaweb/gridworks/expr/functions/Not.java index 4205ae743..f639dcac5 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/Not.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/Not.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class Not implements Function { @@ -17,4 +20,14 @@ public class Not implements Function { return o == null ? false : ( (o instanceof Boolean) ? ((Boolean) o).booleanValue() : Boolean.parseBoolean(o.toString())); } + + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns the opposite of b"); + writer.key("params"); writer.value("boolean b"); + writer.key("returns"); writer.value("boolean"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/Or.java b/src/main/java/com/metaweb/gridworks/expr/functions/Or.java index 48090b7f8..fda22a682 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/Or.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/Or.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class Or implements Function { @@ -14,4 +17,14 @@ public class Or implements Function { } return false; } + + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns a OR b"); + writer.key("params"); writer.value("boolean a, boolean b"); + writer.key("returns"); writer.value("boolean"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/Replace.java b/src/main/java/com/metaweb/gridworks/expr/functions/Replace.java index aadfb8416..2adea29e2 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/Replace.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/Replace.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class Replace implements Function { @@ -19,4 +22,14 @@ public class Replace implements Function { return null; } + + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns the string obtained by replacing f with r in s"); + writer.key("params"); writer.value("string s, string f, string r"); + writer.key("returns"); writer.value("string"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/Round.java b/src/main/java/com/metaweb/gridworks/expr/functions/Round.java index d32d99723..397028716 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/Round.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/Round.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class Round implements Function { @@ -12,5 +15,14 @@ public class Round implements Function { } return null; } - + + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns n rounded"); + writer.key("params"); writer.value("number n"); + writer.key("returns"); writer.value("number"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/Slice.java b/src/main/java/com/metaweb/gridworks/expr/functions/Slice.java index 04bab5cf3..3e2cb45aa 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/Slice.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/Slice.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class Slice implements Function { @@ -59,4 +62,16 @@ public class Slice implements Function { return null; } + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value( + "If o is an array, returns o[from, to]. " + + "if o is a string, returns o.substring(from, to)" + ); + writer.key("params"); writer.value("o, number from, optional number to"); + writer.key("returns"); writer.value("Depends on actual arguments"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/Split.java b/src/main/java/com/metaweb/gridworks/expr/functions/Split.java index bb26d1833..e625393ec 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/Split.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/Split.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class Split implements Function { @@ -16,5 +19,14 @@ public class Split implements Function { } return null; } - + + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns the array of strings obtained by splitting s with separator sep"); + writer.key("params"); writer.value("string s, string sep"); + writer.key("returns"); writer.value("array"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/StartsWith.java b/src/main/java/com/metaweb/gridworks/expr/functions/StartsWith.java index d38e36e74..bd52e4dbb 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/StartsWith.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/StartsWith.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class StartsWith implements Function { @@ -16,5 +19,13 @@ public class StartsWith implements Function { } return null; } - + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns whether s starts with sub"); + writer.key("params"); writer.value("string s, string sub"); + writer.key("returns"); writer.value("boolean"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/ToLowercase.java b/src/main/java/com/metaweb/gridworks/expr/functions/ToLowercase.java index b42123d9e..c6877034e 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/ToLowercase.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/ToLowercase.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class ToLowercase implements Function { @@ -13,5 +16,14 @@ public class ToLowercase implements Function { } return null; } - + + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns s converted to lowercase"); + writer.key("params"); writer.value("string s"); + writer.key("returns"); writer.value("string"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/ToNumber.java b/src/main/java/com/metaweb/gridworks/expr/functions/ToNumber.java index ef2f13403..28c56e270 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/ToNumber.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/ToNumber.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class ToNumber implements Function { @@ -12,5 +15,15 @@ public class ToNumber implements Function { } return null; } + + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns o converted to a number"); + writer.key("params"); writer.value("o"); + writer.key("returns"); writer.value("number"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/ToString.java b/src/main/java/com/metaweb/gridworks/expr/functions/ToString.java index 8ab021267..b0cdd8de5 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/ToString.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/ToString.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class ToString implements Function { @@ -13,4 +16,14 @@ public class ToString implements Function { return null; } + + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns o converted to a string"); + writer.key("params"); writer.value("o"); + writer.key("returns"); writer.value("string"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/ToTitlecase.java b/src/main/java/com/metaweb/gridworks/expr/functions/ToTitlecase.java index 6e99d50b6..8963eb8e2 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/ToTitlecase.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/ToTitlecase.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class ToTitlecase implements Function { @@ -27,5 +30,15 @@ public class ToTitlecase implements Function { } return null; } + + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns s converted to titlecase"); + writer.key("params"); writer.value("string s"); + writer.key("returns"); writer.value("string"); + writer.endObject(); + } } diff --git a/src/main/java/com/metaweb/gridworks/expr/functions/ToUppercase.java b/src/main/java/com/metaweb/gridworks/expr/functions/ToUppercase.java index 62821de4d..0e236580e 100644 --- a/src/main/java/com/metaweb/gridworks/expr/functions/ToUppercase.java +++ b/src/main/java/com/metaweb/gridworks/expr/functions/ToUppercase.java @@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONWriter; + import com.metaweb.gridworks.expr.Function; public class ToUppercase implements Function { @@ -14,4 +17,13 @@ public class ToUppercase implements Function { return null; } + public void write(JSONWriter writer, Properties options) + throws JSONException { + + writer.object(); + writer.key("description"); writer.value("Returns s converted to uppercase"); + writer.key("params"); writer.value("string s"); + writer.key("returns"); writer.value("string"); + writer.endObject(); + } } diff --git a/src/main/webapp/scripts/project/expression-preview-dialog.js b/src/main/webapp/scripts/project/expression-preview-dialog.js index dd64de326..65ea302d5 100644 --- a/src/main/webapp/scripts/project/expression-preview-dialog.js +++ b/src/main/webapp/scripts/project/expression-preview-dialog.js @@ -81,18 +81,32 @@ ExpressionPreviewDialog.prototype._renderHelpTab = function() { ExpressionPreviewDialog.prototype._renderHelp = function(data) { var elmt = this._elmts.helpTabBody.empty(); - $('

').text("Functions").appendTo(elmt); + var renderEntry = function(table, name, entry) { + var tr0 = table.insertRow(table.rows.length); + var tr1 = table.insertRow(table.rows.length); + var tr2 = table.insertRow(table.rows.length); + + $(tr0.insertCell(0)).text(name); + $(tr0.insertCell(1)).text("(" + entry.params + ")"); + + $(tr1.insertCell(0)); + $(tr1.insertCell(1)).text("returns: " + entry.returns); + + $(tr2.insertCell(0)); + $(tr2.insertCell(1)).text(entry.description); + }; - var ul = $('').appendTo(elmt); - for (var n in data.functions) { - $('
  • ').text(n).appendTo(ul); - } + $('

    ').text("Functions").appendTo(elmt); + var functionTable = $('
    ').appendTo(elmt)[0]; $('

    ').text("Controls").appendTo(elmt); + var controlTable = $('
    ').appendTo(elmt)[0]; - ul = $('').appendTo(elmt); + for (var n in data.functions) { + renderEntry(functionTable, n, data.functions[n]); + } for (var n in data.controls) { - $('
  • ').text(n).appendTo(ul); + renderEntry(controlTable, n, data.controls[n]); } };