manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1163618 - /incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/
Date Wed, 31 Aug 2011 13:32:18 GMT
Author: kwright
Date: Wed Aug 31 13:32:17 2011
New Revision: 1163618

URL: http://svn.apache.org/viewvc?rev=1163618&view=rev
Log:
Fix a couple of introduced bugs, and create a dictionary variable type.

Added:
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NewDictionary.java
  (with props)
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableDict.java
  (with props)
Modified:
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/InsertCommand.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/RemoveCommand.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java
    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/VariableArray.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBase.java
    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-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableResult.java

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/InsertCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/InsertCommand.java?rev=1163618&r1=1163617&r2=1163618&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/InsertCommand.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/InsertCommand.java
Wed Aug 31 13:32:17 2011
@@ -49,12 +49,11 @@ public class InsertCommand implements Co
       VariableReference indexRef = sp.evaluateExpression(currentStream);
       if (indexRef == null)
         sp.syntaxError(currentStream,"Missing expression after 'at'");
-      int index = sp.resolveMustExist(currentStream,indexRef).getIntValue();
-      target.insertAt(object,index);
+      target.insertAt(object,indexRef.resolve());
     }
     else
     {
-      target.insert(object);
+      target.insertAt(object,null);
     }
     return false;
   }

Added: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NewDictionary.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NewDictionary.java?rev=1163618&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NewDictionary.java
(added)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NewDictionary.java
Wed Aug 31 13:32:17 2011
@@ -0,0 +1,46 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.manifoldcf.scriptengine;
+
+/** Class defining the creation of a new dictionary object.
+*/
+public class NewDictionary implements NewOperation
+{
+  /** Parse and execute.  Parsing begins right after the "new" keyword and the operation
name token.
+  *@param sp is the script parser to use to help in the parsing.
+  *@param currentStream is the current token stream.
+  *@return the variable reference that got created.  Should never be null.
+  */
+  public VariableReference parseAndCreate(ScriptParser sp, TokenStream currentStream)
+    throws ScriptException
+  {
+    return new VariableDict();
+  }
+  
+  /** Parse and skip.  Parsing begins right after the "new" keyword and the operation name
token.
+  *@param sp is the script parser to use to help in the parsing.
+  *@param currentStream is the current token stream.
+  */
+  public void parseAndSkip(ScriptParser sp, TokenStream currentStream)
+    throws ScriptException
+  {
+  }
+  
+}

Propchange: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NewDictionary.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NewDictionary.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/RemoveCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/RemoveCommand.java?rev=1163618&r1=1163617&r2=1163618&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/RemoveCommand.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/RemoveCommand.java
Wed Aug 31 13:32:17 2011
@@ -33,7 +33,6 @@ public class RemoveCommand implements Co
     VariableReference indexRef = sp.evaluateExpression(currentStream);
     if (indexRef == null)
       sp.syntaxError(currentStream,"Missing index expression");
-    int index = sp.resolveMustExist(currentStream,indexRef).getIntValue();
     Token t = currentStream.peek();
     if (t == null || t.getToken() == null || !t.getToken().equals("from"))
       sp.syntaxError(currentStream,"Missing 'from'");
@@ -42,7 +41,7 @@ public class RemoveCommand implements Co
     if (targetRef == null)
       sp.syntaxError(currentStream,"Missing target expression");
     Variable target = sp.resolveMustExist(currentStream,targetRef);
-    target.removeAt(index);
+    target.removeAt(indexRef.resolve());
     return false;
   }
   

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java?rev=1163618&r1=1163617&r2=1163618&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java
Wed Aug 31 13:32:17 2011
@@ -681,7 +681,7 @@ public class ScriptParser
 	VariableReference expression = evaluateExpression(currentStream);
 	if (expression == null)
 	  syntaxError(currentStream,"Missing expression after '['");
-	int indexValue = resolveMustExist(currentStream,expression).getIntValue();
+	Variable indexValue = resolveMustExist(currentStream,expression);
 	vr = resolveMustExist(currentStream,vr).getIndexed(indexValue);
 	t = currentStream.peek();
 	if (t == null || t.getPunctuation() == null || !t.getPunctuation().equals("]"))
@@ -732,7 +732,7 @@ public class ScriptParser
           VariableReference vr = evaluateExpression(currentStream);
           if (vr == null)
             syntaxError(currentStream,"Missing expression in array initializer");
-          va.insert(vr.resolve());
+          va.insertAt(vr.resolve(),null);
           t = currentStream.peek();
           if (t != null && t.getPunctuation() != null && t.getPunctuation().equals("]"))
             break;
@@ -756,7 +756,7 @@ public class ScriptParser
           VariableReference vr = evaluateExpression(currentStream);
           if (vr == null)
             syntaxError(currentStream,"Missing expression in configuration object initializer");
-          va.insert(vr.resolve());
+          va.insertAt(vr.resolve(),null);
           t = currentStream.peek();
           if (t != null && t.getPunctuation() != null && t.getPunctuation().equals("}"))
             break;
@@ -832,7 +832,7 @@ public class ScriptParser
           VariableReference vr = evaluateExpression(currentStream);
           if (vr == null)
             syntaxError(currentStream,"Missing expression in configurationnode object initializer");
-          va.insert(vr.resolve());
+          va.insertAt(vr.resolve(),null);
           t = currentStream.peek();
           if (t != null && t.getPunctuation() != null && t.getPunctuation().equals(">>"))
             break;
@@ -1159,6 +1159,7 @@ public class ScriptParser
     sp.addNewOperation("url",new NewURL());
     sp.addNewOperation("connectionname",new NewConnectionName());
     sp.addNewOperation("array",new NewArray());
+    sp.addNewOperation("dictionary",new NewDictionary());
     
     try
     {
@@ -1172,7 +1173,7 @@ public class ScriptParser
         while (i < argv.length - 1)
         {
           String arg = argv[i+1];
-          va.insert(new VariableString(arg));
+          va.insertAt(new VariableString(arg),null);
           i++;
         }
         sp.addVariable("__args__",va);

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=1163618&r1=1163617&r2=1163618&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
Wed Aug 31 13:32:17 2011
@@ -137,22 +137,18 @@ public interface Variable
   public VariableReference getAttribute(String attributeName)
     throws ScriptException;
   
-  /** Insert an object into this variable at a position. */
-  public void insertAt(Variable v, int index)
-    throws ScriptException;
-    
-  /** Insert an object into this variable at end. */
-  public void insert(Variable v)
+  /** Insert an object into this variable at a position.  Use null to insert at end. */
+  public void insertAt(Variable v, Variable index)
     throws ScriptException;
     
   /** Delete an object from this variable at a position. */
-  public void removeAt(int index)
+  public void removeAt(Variable index)
     throws ScriptException;
     
   // The following operations correspond to xxx[index]
   
   /** Get an indexed property of the variable */
-  public VariableReference getIndexed(int index)
+  public VariableReference getIndexed(Variable index)
     throws ScriptException;
     
 }

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableArray.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableArray.java?rev=1163618&r1=1163617&r2=1163618&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableArray.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableArray.java
Wed Aug 31 13:32:17 2011
@@ -77,7 +77,7 @@ public class VariableArray extends Varia
       if (v == null)
         sb.append("null");
       else
-        sb.append(v.toString());
+        sb.append(v.getScriptValue());
     }
     sb.append(" ]");
     return sb.toString();
@@ -94,37 +94,42 @@ public class VariableArray extends Varia
   }
   
   /** Get an indexed property of the variable */
-  public VariableReference getIndexed(int index)
+  public VariableReference getIndexed(Variable index)
     throws ScriptException
   {
-    if (index < array.size())
-      return new ElementReference(index);
+    if (index == null)
+      throw new ScriptException("Subscript cannot be null for array");
+    int indexValue = index.getIntValue();
+    if (indexValue < array.size())
+      return new ElementReference(indexValue);
     return super.getIndexed(index);
   }
   
   /** Insert an object into this variable at a position. */
-  public void insertAt(Variable v, int index)
+  public void insertAt(Variable v, Variable index)
     throws ScriptException
   {
-    if (index > array.size())
-      throw new ScriptException("Insert out of bounds");
-    array.add(index,v);
-  }
-
-  /** Insert an object into this variable at end. */
-  public void insert(Variable v)
-    throws ScriptException
-  {
-    array.add(v);
+    if (index == null)
+      array.add(v);
+    else
+    {
+      int indexValue = index.getIntValue();
+      if (indexValue > array.size())
+        throw new ScriptException("Array insert out of bounds");
+      array.add(indexValue,v);
+    }
   }
 
   /** Delete an object from this variable at a position. */
-  public void removeAt(int index)
+  public void removeAt(Variable index)
     throws ScriptException
   {
-    if (index >= array.size())
-      throw new ScriptException("Remove out of bounds");
-    array.remove(index);
+    if (index == null)
+      throw new ScriptException("Array remove cannot be null.");
+    int indexValue = index.getIntValue();
+    if (indexValue < 0 || indexValue >= array.size())
+      throw new ScriptException("Array remove out of bounds: "+indexValue);
+    array.remove(indexValue);
   }
 
   /** Extend VariableReference class so we capture attempts to set the reference, and actually
overwrite the child when that is done */

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBase.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBase.java?rev=1163618&r1=1163617&r2=1163618&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBase.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBase.java
Wed Aug 31 13:32:17 2011
@@ -198,21 +198,14 @@ public class VariableBase implements Var
   }
   
   /** Insert an object into this variable at a position. */
-  public void insertAt(Variable v, int index)
-    throws ScriptException
-  {
-    throw new ScriptException("Can't insert into variable");
-  }
-
-  /** Insert an object into this variable at end. */
-  public void insert(Variable v)
+  public void insertAt(Variable v, Variable index)
     throws ScriptException
   {
     throw new ScriptException("Can't insert into variable");
   }
 
   /** Delete an object from this variable at a position. */
-  public void removeAt(int index)
+  public void removeAt(Variable index)
     throws ScriptException
   {
     throw new ScriptException("Can't remove from variable");
@@ -222,10 +215,10 @@ public class VariableBase implements Var
   // The following two operations correspond to <xxx> and xxx[index]
   
   /** Get an indexed property of the variable */
-  public VariableReference getIndexed(int index)
+  public VariableReference getIndexed(Variable index)
     throws ScriptException
   {
-    throw new ScriptException("Variable has no member number "+Integer.toString(index));
+    throw new ScriptException("Variable does not support subscripts");
   }
 
   // As a variable reference, refer to self

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=1163618&r1=1163617&r2=1163618&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 13:32:17 2011
@@ -63,7 +63,7 @@ public class VariableConfiguration exten
       if (i > 0)
         sb.append(", ");
       ConfigurationNode child = configuration.findChild(i++);
-      sb.append(new VariableConfigurationNode(child).toString());
+      sb.append(new VariableConfigurationNode(child).getScriptValue());
     }
     sb.append(" }");
     return sb.toString();
@@ -87,32 +87,44 @@ public class VariableConfiguration exten
   }
   
   /** Get an indexed property of the variable */
-  public VariableReference getIndexed(int index)
+  public VariableReference getIndexed(Variable index)
     throws ScriptException
   {
-    if (index < configuration.getChildCount())
-      return new NodeReference(index);
-    return super.getIndexed(index);
+    if (index == null)
+      throw new ScriptException("Subscript cannot be null for configuration");
+    int indexValue = index.getIntValue();
+    if (indexValue < configuration.getChildCount())
+      return new NodeReference(indexValue);
+    throw new ScriptException("Subscript "+indexValue+" is out of bounds");
   }
   
   /** Insert an object into this variable at a position. */
-  public void insertAt(Variable v, int index)
+  public void insertAt(Variable v, Variable index)
     throws ScriptException
   {
-    if (index > configuration.getChildCount())
-      throw new ScriptException("Insert out of bounds");
     if (v == null)
-      throw new ScriptException("Can't insert a null object");
-    configuration.addChild(index,v.getConfigurationNodeValue());
+      throw new ScriptException("Can't insert a null object into a configuration");
+    if (index == null)
+      configuration.addChild(configuration.getChildCount(),v.getConfigurationNodeValue());
+    else
+    {
+      int indexValue = index.getIntValue();
+      if (indexValue < 0 || indexValue > configuration.getChildCount())
+        throw new ScriptException("Configuration insert out of bounds");
+      configuration.addChild(indexValue,v.getConfigurationNodeValue());
+    }
   }
 
-  /** Insert an object into this variable at end. */
-  public void insert(Variable v)
+  /** Delete an object from this variable at a position. */
+  public void removeAt(Variable index)
     throws ScriptException
   {
-    if (v == null)
-      throw new ScriptException("Can't insert a null object");
-    configuration.addChild(configuration.getChildCount(),v.getConfigurationNodeValue());
+    if (index == null)
+      throw new ScriptException("Configuration remove index cannot be null");
+    int indexValue = index.getIntValue();
+    if (indexValue < 0 || indexValue >= configuration.getChildCount())
+      throw new ScriptException("Configuration remove out of bounds");
+    configuration.removeChild(indexValue);
   }
 
   public VariableReference plus(Variable v)
@@ -132,14 +144,6 @@ public class VariableConfiguration exten
     return new VariableConfiguration(c);
   }
 
-  /** Delete an object from this variable at a position. */
-  public void removeAt(int index)
-    throws ScriptException
-  {
-    if (index >= configuration.getChildCount())
-      throw new ScriptException("Remove out of bounds");
-    configuration.removeChild(index);
-  }
 
   /** Extend VariableReference class so we capture attempts to set the reference, and actually
overwrite the child when that is done */
   protected class NodeReference implements VariableReference

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=1163618&r1=1163617&r2=1163618&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 13:32:17 2011
@@ -44,12 +44,12 @@ public class VariableConfigurationNode e
   {
     StringBuilder sb = new StringBuilder();
     sb.append("<< ");
-    sb.append(new VariableString(configurationNode.getType()).toString());
+    sb.append(new VariableString(configurationNode.getType()).getScriptValue());
     sb.append(" : ");
     String valueField = configurationNode.getValue();
     if (valueField == null)
       valueField = "";
-    sb.append(new VariableString(valueField).toString());
+    sb.append(new VariableString(valueField).getScriptValue());
     sb.append(" : ");
     boolean needComma = false;
     Iterator<String> iter = configurationNode.getAttributes();
@@ -61,9 +61,9 @@ public class VariableConfigurationNode e
         sb.append(", ");
       else
         needComma = true;
-      sb.append(new VariableString(attrName).toString());
+      sb.append(new VariableString(attrName).getScriptValue());
       sb.append("=");
-      sb.append(new VariableString(value).toString());
+      sb.append(new VariableString(value).getScriptValue());
     }
     sb.append(" : ");
     int i = 0;
@@ -72,7 +72,7 @@ public class VariableConfigurationNode e
       ConfigurationNode child = configurationNode.findChild(i);
       if (i > 0)
         sb.append(", ");
-      sb.append(new VariableConfigurationNode(child).toString());
+      sb.append(new VariableConfigurationNode(child).getScriptValue());
       i++;
     }
     sb.append(" >>");
@@ -119,35 +119,47 @@ public class VariableConfigurationNode e
   }
   
   /** Get an indexed property of the variable */
-  public VariableReference getIndexed(int index)
+  public VariableReference getIndexed(Variable index)
     throws ScriptException
   {
-    if (index < configurationNode.getChildCount())
-      return new NodeReference(index);
-    return super.getIndexed(index);
+    if (index == null)
+      throw new ScriptException("Subscript cannot be null for configurationnode");
+    int indexValue = index.getIntValue();
+    if (indexValue >= 0 && indexValue < configurationNode.getChildCount())
+      return new NodeReference(indexValue);
+    throw new ScriptException("Subscript "+indexValue+" is out of bounds");
   }
 
   /** Insert an object into this variable at a position. */
-  public void insertAt(Variable v, int index)
+  public void insertAt(Variable v, Variable index)
     throws ScriptException
   {
     if (v == null)
-      throw new ScriptException("Can't insert a null object");
-    if (index > configurationNode.getChildCount())
-      throw new ScriptException("Insert out of bounds");
-    ConfigurationNode insertObject = v.getConfigurationNodeValue();
-    configurationNode.addChild(index,insertObject);
+      throw new ScriptException("Can't insert a null object into a configurationnode");
+    if (index == null)
+      configurationNode.addChild(configurationNode.getChildCount(),v.getConfigurationNodeValue());
+    else
+    {
+      int indexValue = index.getIntValue();
+      if (indexValue < 0 || indexValue > configurationNode.getChildCount())
+        throw new ScriptException("Configurationnode insert out of bounds");
+      configurationNode.addChild(indexValue,v.getConfigurationNodeValue());
+    }
   }
 
-  /** Insert an object into this variable at end. */
-  public void insert(Variable v)
+  /** Delete an object from this variable at a position. */
+  public void removeAt(Variable index)
     throws ScriptException
   {
-    if (v == null)
-      throw new ScriptException("Can't insert a null object");
-    configurationNode.addChild(configurationNode.getChildCount(),v.getConfigurationNodeValue());
+    if (index == null)
+      throw new ScriptException("Configurationnode remove index cannot be null");
+    int indexValue = index.getIntValue();
+    if (indexValue < 0 || indexValue >= configurationNode.getChildCount())
+      throw new ScriptException("Configurationnode remove out of bounds");
+    configurationNode.removeChild(indexValue);
   }
 
+
   public VariableReference plus(Variable v)
     throws ScriptException
   {
@@ -173,15 +185,6 @@ public class VariableConfigurationNode e
     return new VariableConfigurationNode(cn);
   }
 
-  /** Delete an object from this variable at a position. */
-  public void removeAt(int index)
-    throws ScriptException
-  {
-    if (index >= configurationNode.getChildCount())
-      throw new ScriptException("Remove out of bounds");
-    configurationNode.removeChild(index);
-  }
-
   /** Implement VariableReference to allow values to be set or cleared */
   protected class ValueReference implements VariableReference
   {

Added: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableDict.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableDict.java?rev=1163618&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableDict.java
(added)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableDict.java
Wed Aug 31 13:32:17 2011
@@ -0,0 +1,60 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.manifoldcf.scriptengine;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import java.util.*;
+
+/** Array variable object.
+*/
+public class VariableDict extends VariableBase
+{
+  protected Map<Variable,VariableReference> dict = new HashMap<Variable,VariableReference>();
+  
+  public VariableDict()
+  {
+  }
+  
+  /** Get a named attribute of the variable; e.g. xxx.yyy */
+  public VariableReference getAttribute(String attributeName)
+    throws ScriptException
+  {
+    // We recognize only the __size__ attribute
+    if (attributeName.equals(ATTRIBUTE_SIZE))
+      return new VariableInt(dict.size());
+    return super.getAttribute(attributeName);
+  }
+  
+  /** Get an indexed property of the variable */
+  public VariableReference getIndexed(Variable index)
+    throws ScriptException
+  {
+    if (index == null)
+      throw new ScriptException("Dictionary subscript cannot be null");
+    VariableReference rval = dict.get(index);
+    if (rval == null)
+    {
+      rval = new ContextVariableReference();
+      dict.put(index,rval);
+    }
+    return rval;
+  }
+  
+}

Propchange: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableDict.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableDict.java
------------------------------------------------------------------------------
    svn:keywords = Id

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=1163618&r1=1163617&r2=1163618&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
Wed Aug 31 13:32:17 2011
@@ -38,7 +38,7 @@ public class VariableResult extends Vari
   public String getScriptValue()
     throws ScriptException
   {
-    return "("+Integer.toString(resultCode)+") "+result.toString();
+    return "("+Integer.toString(resultCode)+") "+result.getScriptValue();
   }
 
   /** Get the variable's value as an integer */



Mime
View raw message