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/31 16:18:09 UTC

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

Author: kwright
Date: Wed Aug 31 14:18:09 2011
New Revision: 1163631

URL: http://svn.apache.org/viewvc?rev=1163631&view=rev
Log:
Add dictionary support, and update example and documentation accordingly.

Modified:
    incubator/lcf/trunk/framework/build.xml
    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/framework/script-example/file-crawl-example.mcf
    incubator/lcf/trunk/site/src/documentation/content/xdocs/script.xml

Modified: incubator/lcf/trunk/framework/build.xml
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/build.xml?rev=1163631&r1=1163630&r2=1163631&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/build.xml (original)
+++ incubator/lcf/trunk/framework/build.xml Wed Aug 31 14:18:09 2011
@@ -407,6 +407,9 @@
         <copy todir="dist/script-engine/script">
             <fileset dir="engine-scripts"/>
         </copy>
+        <copy todir="dist/script-engine">
+            <fileset dir="script-example"/>
+        </copy>
     </target>
     
     <target name="example" depends="war-crawler-ui,war-api-service,war-authority-service,jar-jetty-runner,jar-core,jar-agents,jar-pull-agent">

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=1163631&r1=1163630&r2=1163631&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 Wed Aug 31 14:18:09 2011
@@ -83,6 +83,18 @@ public class VariableConfiguration exten
     // We recognize only the __size__ attribute
     if (attributeName.equals(ATTRIBUTE_SIZE))
       return new VariableInt(configuration.getChildCount());
+    if (attributeName.equals(ATTRIBUTE_DICT))
+    {
+      VariableDict dict = new VariableDict();
+      int i = 0;
+      while (i < configuration.getChildCount())
+      {
+        ConfigurationNode child = configuration.findChild(i++);
+        String type = child.getType();
+        dict.getIndexed(new VariableString(type)).setReference(new VariableConfigurationNode(child));
+      }
+      return dict;
+    }
     return super.getAttribute(attributeName);
   }
   

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=1163631&r1=1163630&r2=1163631&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 Wed Aug 31 14:18:09 2011
@@ -108,6 +108,18 @@ public class VariableConfigurationNode e
     // And the __value__ attribute
     if (attributeName.equals(ATTRIBUTE_VALUE))
       return new ValueReference();
+    if (attributeName.equals(ATTRIBUTE_DICT))
+    {
+      VariableDict dict = new VariableDict();
+      int i = 0;
+      while (i < configurationNode.getChildCount())
+      {
+        ConfigurationNode child = configurationNode.findChild(i++);
+        String type = child.getType();
+        dict.getIndexed(new VariableString(type)).setReference(new VariableConfigurationNode(child));
+      }
+      return dict;
+    }
     if (attributeName.equals(ATTRIBUTE_SCRIPT) ||
       attributeName.equals(ATTRIBUTE_STRING) ||
       attributeName.equals(ATTRIBUTE_INT) ||

Modified: incubator/lcf/trunk/framework/script-example/file-crawl-example.mcf
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-example/file-crawl-example.mcf?rev=1163631&r1=1163630&r2=1163631&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-example/file-crawl-example.mcf (original)
+++ incubator/lcf/trunk/framework/script-example/file-crawl-example.mcf Wed Aug 31 14:18:09 2011
@@ -106,22 +106,14 @@ while true do
   ;
 
   # Find the job's status
-  set jobstatusData = result.__value__[0];
-  set index = 0;
-  set jobstatus = "";
-  while index < jobstatusData.__size__ do
-    set node = jobstatusData[index];
-    if node.__type__ == "status" then
-      set jobstatus = node.__value__;
-    ;
-    set index = index + 1;
-  ;
-  
-  if jobstatus == "" then
+  set jobstatus = result.__value__.__dict__["jobstatus"];
+  if isnull jobstatus then
     error "Couldn't find job status in response: " + result.__script__;
   ;
-    
-  if jobstatus == "done" || jobstatus == "error" then
+  
+  set thestatus = jobstatus.__dict__["status"].__value__;
+  
+  if thestatus == "done" || thestatus == "error" then
     break;
   ;
   wait 10000;

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=1163631&r1=1163630&r2=1163631&view=diff
==============================================================================
--- incubator/lcf/trunk/site/src/documentation/content/xdocs/script.xml (original)
+++ incubator/lcf/trunk/site/src/documentation/content/xdocs/script.xml Wed Aug 31 14:18:09 2011
@@ -190,6 +190,7 @@ print "3".__int__+7;
         <tr><td>__size__</td><td>Typically returns the number of subscript children</td></tr>
         <tr><td>__type__</td><td>Returns the 'type' of the variable</td></tr>
         <tr><td>__value__</td><td>Returns the 'value' of the variable</td></tr>
+        <tr><td>__dict__</td><td>Returns a dictionary equivalent of the variable</td></tr>
         <tr><td>__OK__</td><td>Returns a boolean 'true' if the variable was "OK", false otherwise</td></tr>
         <tr><td>__NOTFOUND__</td><td>Returns a boolean 'true' if the variable was "NOTFOUND", false otherwise</td></tr>
         <tr><td>__CREATED__</td><td>Returns a boolean 'true' if the variable was "CREATED", false otherwise</td></tr>
@@ -293,6 +294,18 @@ print "3".__int__+7;
           by array types, as well as the <em>insert</em> and <em>remove</em> statements.</p>
       </section>
       <section>
+        <title>Dictionaries</title>
+        <p>Array variable types are created using the "new" operator, e.g. <strong>new</strong> <strong>dictionary</strong>.</p>
+        <p>The operations supported for this variable type, and their meanings, are listed in the table below:</p>
+        <table>
+          <caption>Array operations</caption>
+          <tr><th>Operation</th><th>Meaning</th><th>Example</th></tr>
+          <tr><td>subscript []</td><td>Find the specified key, yielding the keyed variable</td><td>mydict ["keyname"]</td></tr>
+        </table>
+        <p>In addition, the standard attributes <em>__script__</em> and <em>__size__</em> are supported 
+          by dictionary types.</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 <strong>{</strong> [<em>expression</em> [<strong>,</strong> <em>expression</em> ...]] <strong>}</strong>.  For example, the script code '{ &lt; "outputconnector" : "" :  : , &lt; "description" : "Solr" :  :  &gt;, &lt; "class_name" : "org.apache.manifoldcf.agents.output.solr.SolrConnector" :  :  &gt; &gt; }'
@@ -304,7 +317,7 @@ print "3".__int__+7;
           <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 
+        <p>In addition, the standard attributes <em>__script__</em>, <em>__dict__</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>
@@ -326,7 +339,7 @@ print "3".__int__+7;
           <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;&lt; "something" : "somethingvalue" : : &gt;&gt;</td></tr>
         </table>
-        <p>In addition, the standard attributes <em>__script__</em>, <em>__string__</em>, <em>__size__</em>, <em>__type__</em>, and <em>__value__</em> are supported 
+        <p>In addition, the standard attributes <em>__script__</em>, <em>__string__</em>, <em>__size__</em>, <em>__type__</em>, <em>__dict__</em> and <em>__value__</em> are supported 
           by configuration node variable types, as well as the <em>insert</em> and <em>remove</em> statements.</p>
       </section>
       <section>