You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2011/08/28 12:44:44 UTC

svn commit: r1162494 - in /incubator/lcf/trunk: framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ site/src/documentation/content/xdocs/

Author: kwright
Date: Sun Aug 28 10:44:43 2011
New Revision: 1162494

URL: http://svn.apache.org/viewvc?rev=1162494&view=rev
Log:
More work on scripting language documentation, and also make the + operator work consistently across types.

Modified:
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfiguration.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfigurationNode.java
    incubator/lcf/trunk/site/src/documentation/content/xdocs/script.xml

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfiguration.java?rev=1162494&r1=1162493&r2=1162494&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfiguration.java (original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfiguration.java Sun Aug 28 10:44:43 2011
@@ -31,6 +31,11 @@ public class VariableConfiguration exten
   {
     configuration = new Configuration();
   }
+
+  public VariableConfiguration(Configuration c)
+  {
+    configuration = c;
+  }
   
   public VariableConfiguration(String json)
     throws ScriptException
@@ -112,8 +117,18 @@ public class VariableConfiguration exten
   public VariableReference plus(Variable v)
     throws ScriptException
   {
-    insert(v);
-    return this;
+    if (v == null)
+      throw new ScriptException("Can't add a null object");
+    ConfigurationNode node = v.getConfigurationNodeValue();
+    Configuration c = new Configuration();
+    int i = 0;
+    while (i < configuration.getChildCount())
+    {
+      ConfigurationNode child = configuration.findChild(i++);
+      c.addChild(c.getChildCount(),child);
+    }
+    c.addChild(c.getChildCount(),node);
+    return new VariableConfiguration(c);
   }
 
   /** Delete an object from this variable at a position. */

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfigurationNode.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfigurationNode.java?rev=1162494&r1=1162493&r2=1162494&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfigurationNode.java (original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfigurationNode.java Sun Aug 28 10:44:43 2011
@@ -47,9 +47,8 @@ public class VariableConfigurationNode e
     sb.append(" : ");
     String valueField = configurationNode.getValue();
     if (valueField == null)
-      sb.append("null");
-    else
-      sb.append(new VariableString(valueField).toString());
+      valueField = "";
+    sb.append(new VariableString(valueField).toString());
     sb.append(" : ");
     boolean needComma = false;
     Iterator<String> iter = configurationNode.getAttributes();
@@ -83,7 +82,7 @@ public class VariableConfigurationNode e
     throws ScriptException
   {
     if (configurationNode.getValue() == null)
-      return super.getStringValue();
+      return "";
     return configurationNode.getValue();
   }
   
@@ -106,9 +105,7 @@ public class VariableConfigurationNode e
       return new VariableString(configurationNode.getType());
     // And the __value__ attribute
     if (attributeName.equals(ATTRIBUTE_VALUE))
-    {
       return new ValueReference();
-    }
     // All others are presumed to be attributes of the configuration node, which can be set or cleared.
     return new AttributeReference(attributeName);
   }
@@ -146,8 +143,26 @@ public class VariableConfigurationNode e
   public VariableReference plus(Variable v)
     throws ScriptException
   {
-    insert(v);
-    return this;
+    if (v == null)
+      throw new ScriptException("Can't add a null object");
+    ConfigurationNode node = v.getConfigurationNodeValue();
+    ConfigurationNode cn = new ConfigurationNode(configurationNode.getType());
+    cn.setValue(configurationNode.getValue());
+    Iterator<String> attIter = configurationNode.getAttributes();
+    while (attIter.hasNext())
+    {
+      String attrName = attIter.next();
+      String attrValue = configurationNode.getAttributeValue(attrName);
+      cn.setAttribute(attrName,attrValue);
+    }
+    int i = 0;
+    while (i < configurationNode.getChildCount())
+    {
+      ConfigurationNode child = configurationNode.findChild(i++);
+      cn.addChild(cn.getChildCount(),child);
+    }
+    cn.addChild(cn.getChildCount(),node);
+    return new VariableConfigurationNode(cn);
   }
 
   /** Delete an object from this variable at a position. */
@@ -183,14 +198,13 @@ public class VariableConfigurationNode e
     {
       String value = configurationNode.getValue();
       if (value == null)
-        throw new ScriptException("ConfigurationNode value is null");
-      else
-        return new VariableString(value);
+        value = "";
+      return new VariableString(value);
     }
     
     public boolean isNull()
     {
-      return configurationNode.getValue() == null;
+      return false;
     }
   }
   

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=1162494&r1=1162493&r2=1162494&view=diff
==============================================================================
--- incubator/lcf/trunk/site/src/documentation/content/xdocs/script.xml (original)
+++ incubator/lcf/trunk/site/src/documentation/content/xdocs/script.xml Sun Aug 28 10:44:43 2011
@@ -280,7 +280,7 @@ print "3".__int__+7;
       </section>
       <section>
         <title>Arrays</title>
-        <p>Array variable types are created by an initializer of the form '[' expression ',' ... expression ']'.  For example, the code '[3, 4]' will create an array
+        <p>Array variable types are created by an initializer of the form '[' expression ',' ... expression ']'.  For example, the script code '[3, 4]' will create an array
           variable type with two values,  the integer "3" and the integer "4".</p>
         <p>The operations supported for this variable type, and their meanings, are listed in the table below:</p>
         <table>
@@ -289,10 +289,22 @@ print "3".__int__+7;
           <tr><td>subscript []</td><td>Find the specified subscript variable, yielding the variable</td><td>[3,4] [0]</td></tr>
         </table>
         <p>In addition, the standard attributes <em>__script__</em> and <em>__size__</em> are supported 
-          by array types.</p>
+          by array types, as well as the <em>insert</em> and <em>remove</em> statements.</p>
       </section>
       <section>
         <title>Configurations</title>
+        <p>Configuration variables contain the equivalent of the JSON used to communicate with the ManifoldCF API.  They can be created using an initializer
+          of the form '{' expression ',' ... expression '}'.  For example, the script code '{ &lt; "outputconnector" : "" :  : , &lt; "description" : "Solr" :  :  &gt;, &lt; "class_name" : "org.apache.manifoldcf.agents.output.solr.SolrConnector" :  :  &gt; &gt; }'
+          would create a configuration variable equivalent to one that might be returned from the ManifoldCF API if it was queried for the output connectors registered by the system.</p>
+        <p>The operations supported for this variable type, and their meanings are listed in the table below:</p>
+        <table>
+          <caption>Configuration operations</caption>
+          <tr><th>Operation</th><th>Meaning</th><th>Example</th></tr>
+          <tr><td>subscript []</td><td>Find the specified child configuration node variable, yielding the variable</td><td>myconfig [0]</td></tr>
+          <tr><td>binary +</td><td>Append a configuration child node variable to the list</td><td>myconfig + &lt; "something" : "somethingvalue" : : &gt;</td></tr>
+        </table>
+        <p>In addition, the standard attributes <em>__script__</em> and <em>__size__</em> are supported 
+          by configuration variable types, as well as the <em>insert</em> and <em>remove</em> statements.</p>
       </section>
       <section>
         <title>Configuration nodes</title>