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/23 20:18:28 UTC
svn commit: r1160831 - in
/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine:
POSTCommand.java PUTCommand.java Variable.java VariableBase.java
VariableConfiguration.java VariableConfigurationNode.java
Author: kwright
Date: Tue Aug 23 18:18:27 2011
New Revision: 1160831
URL: http://svn.apache.org/viewvc?rev=1160831&view=rev
Log:
Add variable operations for insert and remove, in prep for supporting commands that do that.
Modified:
incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/POSTCommand.java
incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PUTCommand.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/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
Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/POSTCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/POSTCommand.java?rev=1160831&r1=1160830&r2=1160831&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/POSTCommand.java (original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/POSTCommand.java Tue Aug 23 18:18:27 2011
@@ -18,6 +18,7 @@
*/
package org.apache.manifoldcf.scriptengine;
+import org.apache.manifoldcf.core.interfaces.*;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import java.io.*;
@@ -54,10 +55,11 @@ public class POSTCommand implements Comm
// Perform the actual PUT.
String urlString = sp.resolveMustExist(currentStream,url).getStringValue();
- String json = sp.resolveMustExist(currentStream,send).getJSONValue();
+ Configuration configuration = sp.resolveMustExist(currentStream,send).getConfigurationValue();
try
{
+ String json = configuration.toJSON();
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(urlString);
method.setRequestHeader("Content-type", "text/plain; charset=UTF-8");
@@ -72,6 +74,10 @@ public class POSTCommand implements Comm
return false;
}
+ catch (ManifoldCFException e)
+ {
+ throw new ScriptException(e.getMessage(),e);
+ }
catch (IOException e)
{
throw new ScriptException(e.getMessage(),e);
Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PUTCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PUTCommand.java?rev=1160831&r1=1160830&r2=1160831&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PUTCommand.java (original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PUTCommand.java Tue Aug 23 18:18:27 2011
@@ -18,6 +18,7 @@
*/
package org.apache.manifoldcf.scriptengine;
+import org.apache.manifoldcf.core.interfaces.*;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import java.io.*;
@@ -54,10 +55,11 @@ public class PUTCommand implements Comma
// Perform the actual PUT.
String urlString = sp.resolveMustExist(currentStream,url).getStringValue();
- String json = sp.resolveMustExist(currentStream,send).getJSONValue();
-
+ Configuration configuration = sp.resolveMustExist(currentStream,send).getConfigurationValue();
+
try
{
+ String json = configuration.toJSON();
HttpClient client = new HttpClient();
PutMethod method = new PutMethod(urlString);
method.setRequestHeader("Content-type", "text/plain; charset=UTF-8");
@@ -72,6 +74,10 @@ public class PUTCommand implements Comma
return false;
}
+ catch (ManifoldCFException e)
+ {
+ throw new ScriptException(e.getMessage(),e);
+ }
catch (IOException e)
{
throw new ScriptException(e.getMessage(),e);
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=1160831&r1=1160830&r2=1160831&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 Tue Aug 23 18:18:27 2011
@@ -18,6 +18,8 @@
*/
package org.apache.manifoldcf.scriptengine;
+import org.apache.manifoldcf.core.interfaces.*;
+
/** This interface represents a variable within the ManifoldCF script engine.
* A variable may have a value, and may have various named properties, as described below.
*
@@ -45,10 +47,14 @@ public interface Variable
public String getStringValue()
throws ScriptException;
- /** Get the variable's value as a JSON string */
- public String getJSONValue()
+ /** Get the variable's value as a Configuration object */
+ public Configuration getConfigurationValue()
throws ScriptException;
-
+
+ /** Get the variable's value as a ConfigurationNode object */
+ public ConfigurationNode getConfigurationNodeValue()
+ throws ScriptException;
+
/** Get the variable's value as a boolean */
public boolean getBooleanValue()
throws ScriptException;
@@ -117,6 +123,14 @@ 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;
+
+ /** Delete an object from this variable at a position. */
+ public void removeAt(int index)
+ throws ScriptException;
+
// The following operations correspond to xxx[index]
/** Get an indexed property of the variable */
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=1160831&r1=1160830&r2=1160831&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 Tue Aug 23 18:18:27 2011
@@ -19,6 +19,8 @@
package org.apache.manifoldcf.scriptengine;
+import org.apache.manifoldcf.core.interfaces.*;
+
/** Base class for variables.
* Basically, everything is illegal until overridden.
*/
@@ -35,11 +37,18 @@ public class VariableBase implements Var
throw new ScriptException("Cannot convert variable to string");
}
- /** Get the variable's value as a JSON string */
- public String getJSONValue()
+ /** Get the variable's value as a Configuration object */
+ public Configuration getConfigurationValue()
throws ScriptException
{
- throw new ScriptException("Cannot convert variable to JSON");
+ throw new ScriptException("Cannot convert variable to Configuration object");
+ }
+
+ /** Get the variable's value as a ConfigurationNode object */
+ public ConfigurationNode getConfigurationNodeValue()
+ throws ScriptException
+ {
+ throw new ScriptException("Cannot convert variable to ConfigurationNode object");
}
/** Get the variable's value as a boolean */
@@ -170,6 +179,21 @@ public class VariableBase implements Var
throw new ScriptException("Variable has no attribute called '"+attributeName+"'");
}
+ /** 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");
+ }
+
+ /** Delete an object from this variable at a position. */
+ public void removeAt(int index)
+ throws ScriptException
+ {
+ throw new ScriptException("Can't remove from variable");
+ }
+
+
// The following two operations correspond to <xxx> and xxx[index]
/** Get an indexed property of the variable */
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=1160831&r1=1160830&r2=1160831&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 Tue Aug 23 18:18:27 2011
@@ -53,20 +53,13 @@ public class VariableConfiguration exten
return configuration.toString();
}
- /** Get the variable's value as a JSON string */
- public String getJSONValue()
+ /** Get the variable's value as a Configuration object */
+ public Configuration getConfigurationValue()
throws ScriptException
{
- try
- {
- return configuration.toJSON();
- }
- catch (ManifoldCFException e)
- {
- throw new ScriptException(e.getMessage(),e);
- }
+ return configuration;
}
-
+
/** Get a named attribute of the variable; e.g. xxx.yyy */
public VariableReference getAttribute(String attributeName)
throws ScriptException
@@ -86,6 +79,24 @@ public class VariableConfiguration exten
return super.getIndexed(index);
}
+ /** Insert an object into this variable at a position. */
+ public void insertAt(Variable v, int index)
+ throws ScriptException
+ {
+ if (index > configuration.getChildCount())
+ throw new ScriptException("Insert out of bounds");
+ configuration.addChild(index,v.getConfigurationNodeValue());
+ }
+
+ /** 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
{
@@ -99,12 +110,11 @@ public class VariableConfiguration exten
public void setReference(Variable v)
throws ScriptException
{
- if (!(v instanceof VariableConfigurationNode))
- throw new ScriptException("Cannot set Configuration child value to anything other than a ConfigurationNode object");
if (index >= configuration.getChildCount())
throw new ScriptException("Index out of range for Configuration children");
+ ConfigurationNode confNode = v.getConfigurationNodeValue();
configuration.removeChild(index);
- configuration.addChild(index,((VariableConfigurationNode)v).getConfigurationNode());
+ configuration.addChild(index,confNode);
}
public Variable resolve()
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=1160831&r1=1160830&r2=1160831&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 Tue Aug 23 18:18:27 2011
@@ -44,6 +44,13 @@ public class VariableConfigurationNode e
return configurationNode.toString();
}
+ /** Get the variable's value as a ConfigurationNode object */
+ public ConfigurationNode getConfigurationNodeValue()
+ throws ScriptException
+ {
+ return configurationNode;
+ }
+
/** Get a named attribute of the variable; e.g. xxx.yyy */
public VariableReference getAttribute(String attributeName)
throws ScriptException
@@ -71,12 +78,26 @@ public class VariableConfigurationNode e
return new NodeReference(index);
return super.getIndexed(index);
}
-
- public ConfigurationNode getConfigurationNode()
+
+ /** Insert an object into this variable at a position. */
+ public void insertAt(Variable v, int index)
+ throws ScriptException
{
- return configurationNode;
+ if (index > configurationNode.getChildCount())
+ throw new ScriptException("Insert out of bounds");
+ ConfigurationNode insertObject = v.getConfigurationNodeValue();
+ configurationNode.addChild(index,insertObject);
}
-
+
+ /** 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
{
@@ -162,12 +183,11 @@ public class VariableConfigurationNode e
public void setReference(Variable v)
throws ScriptException
{
- if (!(v instanceof VariableConfigurationNode))
- throw new ScriptException("Cannot set ConfigurationNode child value to anything other than a ConfigurationNode object");
if (index >= configurationNode.getChildCount())
throw new ScriptException("Index out of range for ConfigurationNode children");
+ ConfigurationNode confNode = v.getConfigurationNodeValue();
configurationNode.removeChild(index);
- configurationNode.addChild(index,((VariableConfigurationNode)v).getConfigurationNode());
+ configurationNode.addChild(index,confNode);
}
public Variable resolve()