Return-Path: X-Original-To: apmail-incubator-connectors-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-connectors-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 448027E34 for ; Sat, 27 Aug 2011 23:39:55 +0000 (UTC) Received: (qmail 73135 invoked by uid 500); 27 Aug 2011 23:39:55 -0000 Delivered-To: apmail-incubator-connectors-commits-archive@incubator.apache.org Received: (qmail 73078 invoked by uid 500); 27 Aug 2011 23:39:54 -0000 Mailing-List: contact connectors-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: connectors-dev@incubator.apache.org Delivered-To: mailing list connectors-commits@incubator.apache.org Received: (qmail 73071 invoked by uid 99); 27 Aug 2011 23:39:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 27 Aug 2011 23:39:53 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 27 Aug 2011 23:39:50 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 9E8322388900; Sat, 27 Aug 2011 23:39:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1162459 - in /incubator/lcf/trunk: framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ site/src/documentation/content/xdocs/ Date: Sat, 27 Aug 2011 23:39:30 -0000 To: connectors-commits@incubator.apache.org From: kwright@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110827233930.9E8322388900@eris.apache.org> Author: kwright Date: Sat Aug 27 23:39:29 2011 New Revision: 1162459 URL: http://svn.apache.org/viewvc?rev=1162459&view=rev Log: Various script-engine related updates, including substantial documentation and various fixes for consistency etc. Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/Variable.java incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBoolean.java incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableInt.java incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableResult.java incubator/lcf/trunk/site/src/documentation/content/xdocs/how-to-build-and-deploy.xml incubator/lcf/trunk/site/src/documentation/content/xdocs/script.xml Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/Variable.java URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/Variable.java?rev=1162459&r1=1162458&r2=1162459&view=diff ============================================================================== --- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/Variable.java (original) +++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/Variable.java Sat Aug 27 23:39:29 2011 @@ -50,8 +50,6 @@ public interface Variable public static String ATTRIBUTE_NOTFOUNDSTATUS = "__NOTFOUND__"; /** CREATED status attribute */ public static String ATTRIBUTE_CREATEDSTATUS = "__CREATED__"; - /** RESULT attribute */ - public static String ATTRIBUTE_RESULT = "__result__"; /** Get the variable's value as a string */ public String getStringValue() Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBoolean.java URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBoolean.java?rev=1162459&r1=1162458&r2=1162459&view=diff ============================================================================== --- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBoolean.java (original) +++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBoolean.java Sat Aug 27 23:39:29 2011 @@ -45,13 +45,20 @@ public class VariableBoolean extends Var return value; } - /** Get the variable's value as a string */ - public String getStringValue() + public VariableReference doubleEquals(Variable v) throws ScriptException { - if (value) - return "true"; - return "false"; + if (v == null) + throw new ScriptException("== operand cannot be null"); + return new VariableBoolean(value == v.getBooleanValue()); + } + + public VariableReference exclamationEquals(Variable v) + throws ScriptException + { + if (v == null) + throw new ScriptException("!= operand cannot be null"); + return new VariableBoolean(value != v.getBooleanValue()); } public VariableReference doubleAmpersand(Variable v) @@ -70,6 +77,22 @@ public class VariableBoolean extends Var return new VariableBoolean(value || v.getBooleanValue()); } + public VariableReference ampersand(Variable v) + throws ScriptException + { + if (v == null) + throw new ScriptException("& operand cannot be null"); + return new VariableBoolean(value && v.getBooleanValue()); + } + + public VariableReference pipe(Variable v) + throws ScriptException + { + if (v == null) + throw new ScriptException("| operand cannot be null"); + return new VariableBoolean(value || v.getBooleanValue()); + } + public VariableReference unaryExclamation() throws ScriptException { Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableInt.java URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableInt.java?rev=1162459&r1=1162458&r2=1162459&view=diff ============================================================================== --- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableInt.java (original) +++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableInt.java Sat Aug 27 23:39:29 2011 @@ -72,7 +72,8 @@ public class VariableInt extends Variabl throw new ScriptException("- operand cannot be null"); return new VariableInt(value - v.getIntValue()); } - + + public VariableReference asterisk(Variable v) throws ScriptException { @@ -159,4 +160,10 @@ public class VariableInt extends Variabl return new VariableInt(value | v.getIntValue()); } + public VariableReference unaryExclamation() + throws ScriptException + { + return new VariableInt(value ^ value); + } + } Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableResult.java URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableResult.java?rev=1162459&r1=1162458&r2=1162459&view=diff ============================================================================== --- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableResult.java (original) +++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableResult.java Sat Aug 27 23:39:29 2011 @@ -57,7 +57,7 @@ public class VariableResult extends Vari return new VariableBoolean(resultCode == 201); else if (attributeName.equals(ATTRIBUTE_NOTFOUNDSTATUS)) return new VariableBoolean(resultCode == 404); - else if (attributeName.equals(ATTRIBUTE_RESULT)) + else if (attributeName.equals(ATTRIBUTE_VALUE)) return result; else return super.getAttribute(attributeName); Modified: incubator/lcf/trunk/site/src/documentation/content/xdocs/how-to-build-and-deploy.xml URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/site/src/documentation/content/xdocs/how-to-build-and-deploy.xml?rev=1162459&r1=1162458&r2=1162459&view=diff ============================================================================== --- incubator/lcf/trunk/site/src/documentation/content/xdocs/how-to-build-and-deploy.xml (original) +++ incubator/lcf/trunk/site/src/documentation/content/xdocs/how-to-build-and-deploy.xml Sat Aug 27 23:39:29 2011 @@ -83,6 +83,7 @@ libjars for all the connector plugins, which should be referenced by the appropriate clause in the ManifoldCF configuration file wsddwsdd files that are needed by the included connectors in order to function xxx-processscripts, classpath jars, and -D switch values needed for a required connector-specific process + script-enginejars and scripts for running the ManifoldCF script interpreter examplea jetty-based example that runs in a single process (except for any connector-specific processes) docjavadocs for framework and all included connectors Modified: incubator/lcf/trunk/site/src/documentation/content/xdocs/script.xml URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/site/src/documentation/content/xdocs/script.xml?rev=1162459&r1=1162458&r2=1162459&view=diff ============================================================================== --- incubator/lcf/trunk/site/src/documentation/content/xdocs/script.xml (original) +++ incubator/lcf/trunk/site/src/documentation/content/xdocs/script.xml Sat Aug 27 23:39:29 2011 @@ -53,42 +53,282 @@ java -cp ... org.apache.manifoldcf.scrip and the ScriptParser will accordingly exit. You can also type ^Z to terminate the script.

If you use ScriptParser with a scripting file, that file will be read and interpreted. The arguments you provide will be loaded into an array of strings, which is accessible from your script as the variable named __args__.

-
- Running the scripting language by hand -

-

When you build ManifoldCF, the required dependent jars for the scripting language are copied to dist/script-engine/jar. - You can run the interpreter in interactive mode by typing:

- +
+ Running the script interpreter by hand +

+

When you build ManifoldCF, the required dependent jars for the scripting language are copied to dist/script-engine/jar. + You can run the interpreter in interactive mode by typing:

+ cd dist script-engine\script\run-script.bat <args> - -

Or, on Linux:

- + +

Or, on Linux:

+ cd dist script-engine/script/run-script.sh <args> - -
-
- Running the script interpreter using Ant -

-

You can also start the script interpreter with all the correct required jars using Ant. Simple type the following:

- + +
+
+ Running the script interpreter using Ant +

+

You can also start the script interpreter with all the correct required jars using Ant. Simple type the following:

+ ant run-script-interpreter - -

This will start the script interpreter in interactive mode only.

-
-
- Running the script interpreter using Maven -

-

You can also run the script interpreter using maven. The commands are:

- + +

This will start the script interpreter in interactive mode only.

+
+
+ Running the script interpreter using Maven +

+

You can also run the script interpreter using maven. The commands are:

+ cd framework/script-engine mvn exec:exec - -

This, once again, will start the interpreter in interactive mode.

-
+ +

This, once again, will start the interpreter in interactive mode.

+
+
+ Script language syntax +

+

A ManifoldCF script is not sensitive to whitespace or indenting. All comments begin with a '#' character and end with the end of that line. + Unquoted tokens can include alphanumeric characters, plus '_', '$', and '@'. Numeric tokens always begin with a number ('0'-'9'), and are + considered floating-point if they include a decimal point ('.'). Otherwise they are integers. String tokens can be quoted with either a double quote + ('"') or a single quote, and within strings characters can be escaped with a preceding backslash ('\').

+

A ManifoldCF script has a syntax that is readily described with a BNF grammar. See below.

+ +program: +--> statements + +statements: +--> statement1 ... statementN + +statement: +--> 'set' expression '=' expression ';' +--> 'print' expression ';' +--> 'if' expression 'then' statements ['else' statements] ';' +--> 'while' expression 'do' statements ';' +--> 'break' ';' +--> 'error' expression ';' +--> 'insert' expression 'into' expression ['at' expression] ';' +--> 'remove' expression 'from' expression ';' +--> 'GET' expression '=' expression ';' +--> 'PUT' expression '=' expression 'to' expression ';' +--> 'POST' expression '=' expression 'to' expression ';' +--> 'DELETE' expression ';' + +expression: +--> '(' expression ')' +--> expression '&&' expression +--> expression '||' expression +--> '!' expression +--> expression '&' expression +--> expression '|' expression +--> expression '==' expression +--> expression '!=' expression +--> expression '>=' expression +--> expression '<=' expression +--> expression '>' expression +--> expression '<' expression +--> expression '+' expression +--> expression '-' expression +--> expression '*' expression +--> expression '/' expression +--> '-' expression +--> '[' expression ',' ... expression ']' +--> '{' expression ',' ... expression '}' +--> '<' expression ':' expression ':' expression '=' expression ',' ... expression '=' expression ':' expression ',' ... expression '>' +--> expression '[' expression ']' +--> expression '.' token +--> token +--> string +--> number +--> 'true' | 'false' +--> 'null' +--> 'new' newexpression +--> 'isnull' expression + +newexpression: +--> 'url' expression +--> 'connectionname' expression + + +
+ +
+ Script language variables +

+

Variables in the ManifoldCF scripting language determine the behavior of all aspects of expression evaluation, with the exception of operator precedence. + In particular, every canonical variable has the ability to support arbitrary attributes (which are named properties of the variable), + subscripts (children which are accessed by a numeric subscript), and all other operations, such as '+' or '=='. Not all kinds of + variable instance will in fact support all such features. Should you try to use a feature with a variable that does not support it, you will receive a + ScriptException telling you what you did wrong.

+

Since the actual operation details are bound to the variable, for binary operations the left-hand variable typically determines what actually takes place. For example:

+ +print 3+7; + [java] 10 +print "3"+7; + [java] 37 + +

There is, of course, a way to caste a variable to a different type. For example:

+ +print "3".__int__+7; + [java] 10 + +

Here, we are using the built-in attribute __int__ to obtain the integer equivalent of the original string variable "3". See the following table for + a list of some of the standard attributes and their meanings:

+ + + + + + + + + + + + + + +
Standard attributes
Attribute nameMeaning
__script__Returns the script code that would create this variable
__string__Returns the string value of the variable, if any
__int__Returns the integer value of the variable, if any
__float__Returns the floating-point value of the variable, if any
__boolean__Returns the boolean value of the variable, if any
__size__Returns the number of subscript children
__name__Returns the 'name' of the variable
__value__Returns the 'value' of the variable
__OK__Returns a boolean 'true' if the variable was "OK", false otherwise
__NOTFOUND__Returns a boolean 'true' if the variable was "NOTFOUND", false otherwise
__CREATED__Returns a boolean 'true' if the variable was "CREATED", false otherwise
+

Obviously, only some variables will support each of the standard attributes. You will receive a script exception if you try to obtain a non-existent + attribute for a variable.

+
+ Integers +

Integer variable types are created by non-quoted numeric values that do not have a '.' in them. For example, the character '4' will create an integer + variable type with a value of 4.

+

The operations supported for this variable type, and their meanings, are listed in the table below:

+ + + + + + + + + + + + + + + + + +
Integer operations
OperationMeaningExample
binary +Addition, yielding an integer4+7
binary -Subtraction, yielding an integer7-4
binary *Multiplication, yielding an integer7*4
binary /Division, yielding an integer7/4
unary -Negation, yielding an integer-4
binary ==Equality comparison, yielding a boolean7 == 4
binary !=Inequality comparison, yielding a boolean7 != 4
binary >=Greater or equals comparison, yielding a boolean7 >= 4
binary <=Less or equals comparison, yielding a boolean7 <= 4
binary >Greater comparison, yielding a boolean7 > 4
binary <Less comparison, yielding a boolean7 < 4
binary &Bitwise AND, yielding an integer7 & 4
binary |Bitwise OR, yielding an integer7 | 4
unary !Bitwise NOT, yielding an integer! 7
+

In addition, the standard attributes __script__, __string__, __int__, and __float__ are supported + by integer types.

+
+
+ Strings +

String variable types are created by quoted sequences of characters. For example, the character '"hello world"' will create a string + variable type with an (unquoted) value of "hello world".

+

The operations supported for this variable type, and their meanings, are listed in the table below:

+ + + + + + +
String operations
OperationMeaningExample
binary +Concatenation, yielding a string"hi" + "there"
binary ==Equality comparison, yielding a boolean"hi" == "there"
binary !=Inequality comparison, yielding a boolean"hi" != "there"
+

In addition, the standard attributes __script__, __string__, __int__, and __float__ are supported + by string types.

+
+
+ Floating-point numbers +

Float variable types are created by non-quoted numeric values that have a '.' in them. For example, the token '4.1' will create a float + variable type with a value of 4.1

+

The operations supported for this variable type, and their meanings, are listed in the table below:

+ + + + + + + + + + + + + + +
Float operations
OperationMeaningExample
binary +Addition, yielding a float4.0+7.0
binary -Subtraction, yielding a float7.0-4.0
binary *Multiplication, yielding a float7.0*4.0
binary /Division, yielding a float7.0/4.0
unary -Negation, yielding a float-4.0
binary ==Equality comparison, yielding a boolean7.0 == 4.0
binary !=Inequality comparison, yielding a boolean7.0 != 4.0
binary >=Greater or equals comparison, yielding a boolean7.0 >= 4.0
binary <=Less or equals comparison, yielding a boolean7.0 <= 4.0
binary >Greater comparison, yielding a boolean7.0 > 4.0
binary <Less comparison, yielding a boolean7.0 < 4.0
+

In addition, the standard attributes __script__, __string__, __int__, and __float__ are supported + by float types.

+
+
+ Booleans +

Boolean variable types are created by the keywords 'true' and 'false'. For example, the token 'true' will create a boolean + variable type with a value of "true".

+

The operations supported for this variable type, and their meanings, are listed in the table below:

+ + + + + + + + + + +
Boolean operations
OperationMeaningExample
binary ==Equality comparison, yielding a boolean7.0 == 4.0
binary !=Inequality comparison, yielding a boolean7.0 != 4.0
binary &&AND logical operation, yielding a booleantrue && false
binary ||OR logical operation, yielding a booleantrue || false
binary &AND logical operation, yielding a booleantrue & false
binary |OR logical operation, yielding a booleantrue | false
unary !NOT logical operation, yielding a boolean! true
+

In addition, the standard attributes __script__ and __boolean__ are supported + by boolean types.

+
+
+ Arrays +

Array variable types are created by an initializer of the form '[' expression ',' ... expression ']'. For example, the code '[3, 4]' will create an array + variable type with two values, the integer "3" and the integer "4".

+

The operations supported for this variable type, and their meanings, are listed in the table below:

+ + + + +
Array operations
OperationMeaningExample
subscript []Find the specified subscript variable, yielding the variable[3,4] [0]
+

In addition, the standard attributes __script__ and __size__ are supported + by array types.

+
+
+ Configurations +
+
+ Configuration nodes +
+
+ URLs +
+
+ Connection names +
+
+ Results +
+
+ +
+ Statements +

The statements available to a ManifoldCF programmer are designed to support interaction with the ManifoldCF API. Thus, there is support for + all four HTTP verbs, as well as basic variable setting and control flow. The table below describes each statement type:

+ + + + + + + + + + + + + + + +
Statement types
StatementMeaningExample
'set' expression '=' expression ';'Sets the variable described by the first expression with the value computed for the secondset myvar = 4 + 5;
'print' expression ';'Prints the string value of the expression to stdoutprint "hello world";
'if' expression 'then' statements ['else' statements] ';'If the boolean value of the expression is 'true', executes the first set of statements, otherwise executes the (optional) second setif true then print "hello"; else print "there"; ;
'while' expression 'do' statements ';'While expression is true, execute the specified statements, and repeatwhile count > 0 do set count = count - 1; ;
'break' ';'Exits from the nearest enclosing while loopwhile true do break; ;
'error' expression ';'Aborts the script with a script exception based on the string value of the expressionerror "bad stuff";
'insert' expression 'into' expression ['at' expression] ';'Inserts the first expression into the second variable expression, either at the end or optionally at the position specified by the third expressioninsert 4 into myarray at 0 ;
'delete' expression 'from' expression ';'Deletes the element described by the first expression from the second expressiondelete 0 from myarray ;
'GET' expression '=' expression ';'Perform an HTTP GET from the URL specified in the second expression capturing the result in the first expressionGET result = new url "http://localhost:8345/mcf-api-service/json/repositoryconnections" ;
'DELETE' expression '=' expression ';'Perform an HTTP DELETE on the URL specified in the second expression capturing the result in the first expressionDELETE result = myurl ;
'PUT' expression '=' expression 'to' expression ';'Perform an HTTP PUT of the second expression to the URL specified in the third expression capturing the result in the first expressionPUT result = configurationObject to myurl ;
'POST' expression '=' expression 'to' expression ';'Perform an HTTP POST of the second expression to the URL specified in the third expression capturing the result in the first expressionPOST result = configurationObject to myurl ;
+