incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1160012 [1/2] - in /incubator/lcf/trunk/framework: ./ core/src/main/java/org/apache/manifoldcf/core/interfaces/ script-engine/src/main/java/org/apache/manifoldcf/scriptengine/
Date Sun, 21 Aug 2011 17:10:22 GMT
Author: kwright
Date: Sun Aug 21 17:10:20 2011
New Revision: 1160012

URL: http://svn.apache.org/viewvc?rev=1160012&view=rev
Log:
Get script engine working in an (almost complete) manner.

Added:
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/BasicTokenStream.java
      - copied, changed from r1158857, incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/TokenStream.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/BreakCommand.java   (with props)
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/CharacterStream.java   (with props)
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/Command.java   (with props)
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ContextVariableReference.java   (with props)
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/DELETECommand.java   (with props)
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/GETCommand.java   (with props)
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/IfCommand.java   (with props)
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NullVariableReference.java   (with props)
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/POSTCommand.java   (with props)
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PUTCommand.java   (with props)
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PrintCommand.java   (with props)
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/RewindableTokenStream.java   (with props)
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/SetCommand.java   (with props)
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBoolean.java   (with props)
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableFloat.java   (with props)
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableResult.java   (with props)
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/WhileCommand.java   (with props)
Removed:
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/Position.java
Modified:
    incubator/lcf/trunk/framework/build.xml
    incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/Configuration.java
    incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/ConfigurationNode.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/Token.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/TokenStream.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
    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/VariableReference.java

Modified: incubator/lcf/trunk/framework/build.xml
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/build.xml?rev=1160012&r1=1160011&r2=1160012&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/build.xml (original)
+++ incubator/lcf/trunk/framework/build.xml Sun Aug 21 17:10:20 2011
@@ -393,11 +393,13 @@
                 <include name="commons-httpclient-mcf.jar"/>
                 <include name="commons-io*.jar"/>
                 <include name="commons-logging*.jar"/>
+                <include name="json.jar"/>
             </fileset>
         </copy>
-        <copy todir="dist/example/lib">
+        <copy todir="dist/script-engine/lib">
             <fileset dir="build/jar">
                 <include name="mcf-core.jar"/>
+                <include name="mcf-script-engine.jar"/>
             </fileset>
         </copy>
     </target>
@@ -590,6 +592,16 @@
         </junit>
     </target>
 
+    <target name="run-script-engine" depends="script-engine">
+        <java classname="org.apache.manifoldcf.scriptengine.ScriptParser" fork="true" dir="dist/script-engine" maxmemory="128M">
+          <classpath>
+            <fileset dir="dist/script-engine/lib">
+              <include name="*.jar"/>
+            </fileset>
+          </classpath>
+        </java>
+    </target>
+    
     <target name="build" depends="processes,war-authority-service,war-crawler-ui,war-api-service,example,script-engine"/>
     
     <target name="all" depends="build,doc,build-tests,run-tests,run-tests-postgresql"/>

Modified: incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/Configuration.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/Configuration.java?rev=1160012&r1=1160011&r2=1160012&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/Configuration.java (original)
+++ incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/Configuration.java Sun Aug 21 17:10:20 2011
@@ -778,4 +778,23 @@ public class Configuration implements IH
     return true;
   }
 
+  /** Construct a human-readable string */
+  public String toString()
+  {
+    StringBuilder sb = new StringBuilder();
+    sb.append("[");
+    if (children != null)
+    {
+      int i = 0;
+      while (i < children.size())
+      {
+        if (i > 0)
+          sb.append(", ");
+        ConfigurationNode cn = children.get(i++);
+        sb.append(cn.toString());
+      }
+    }
+    sb.append("]");
+    return sb.toString();
+  }
 }

Modified: incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/ConfigurationNode.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/ConfigurationNode.java?rev=1160012&r1=1160011&r2=1160012&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/ConfigurationNode.java (original)
+++ incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/ConfigurationNode.java Sun Aug 21 17:10:20 2011
@@ -345,6 +345,41 @@ public class ConfigurationNode implement
     }
     return true;
   }
+  
+  /** Construct a human-readable string */
+  public String toString()
+  {
+    StringBuilder sb = new StringBuilder();
+    sb.append("(");
+    sb.append(type);
+    if (value != null)
+      sb.append(":").append(value);
+    if (attributes != null)
+    {
+      Iterator<String> iter = attributes.keySet().iterator();
+      while (iter.hasNext())
+      {
+        sb.append(" ");
+        String key = iter.next();
+        String attrValue = attributes.get(key);
+        sb.append(key).append("='").append(attrValue).append("'");
+      }
+    }
+    sb.append(" [");
+    if (children != null)
+    {
+      int i = 0;
+      while (i < children.size())
+      {
+        if (i > 0)
+          sb.append(", ");
+        ConfigurationNode cn = children.get(i++);
+        sb.append(cn.toString());
+      }
+    }
+    sb.append("])");
+    return sb.toString();
+  }
 
   protected static Map<String,String> cloneAttributes(Map<String,String> attributes)
   {

Copied: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/BasicTokenStream.java (from r1158857, incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/TokenStream.java)
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/BasicTokenStream.java?p2=incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/BasicTokenStream.java&p1=incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/TokenStream.java&r1=1158857&r2=1160012&rev=1160012&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/TokenStream.java (original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/BasicTokenStream.java Sun Aug 21 17:10:20 2011
@@ -19,33 +19,22 @@
 
 package org.apache.manifoldcf.scriptengine;
 
-/** Convert a script into a stream of tokens.
+import java.io.*;
+
+/** Convert a sequence of characters into a stream of tokens.
 */
-public class TokenStream
+public class BasicTokenStream implements TokenStream
 {
-  protected String fileName;
-  protected String code;
-  protected int characterPosition = 0;
+  protected CharacterStream characterStream;
   protected Token currentToken = null;
   
-  public TokenStream(String fileName, String code)
-  {
-    this.fileName = fileName;
-    this.code = code;
-  }
-  
-  public int getCharacterPosition()
+  public BasicTokenStream(Reader reader)
   {
-    return characterPosition;
-  }
-  
-  public void setCharacterPosition(int characterPosition)
-  {
-    this.characterPosition = characterPosition;
-    currentToken = null;
+    this.characterStream = new CharacterStream(reader);
   }
   
   public Token peek()
+    throws ScriptException
   {
     if (currentToken == null)
       currentToken = parseNextToken();
@@ -57,40 +46,46 @@ public class TokenStream
     currentToken = null;
   }
   
-  public String getFileName()
-  {
-    return fileName;
-  }
-
   // Protected methods
   
   protected Token parseNextToken()
+    throws ScriptException
   {
+    char y;
+    int lineNumber;
+    int characterNumber;
+
     // Skip to the start of the next token (or exit if no token start can be found)
     while (true)
     {
+      
       // Skip white space
-      while (characterPosition < code.length())
+      while (true)
       {
-        char x = code.charAt(characterPosition);
-        if (x > ' ')
+        // Remember current position so we can properly characterize the token.
+        lineNumber = characterStream.getLineNumber();
+        characterNumber = characterStream.getCharacterNumber();
+        int x = characterStream.peek();
+        if (x == -1)
+          return null;
+        y = (char)x;
+        if (y > ' ')
           break;
-        characterPosition++;
+        characterStream.skip();
       }
-      
-      // End of text?
-      if (characterPosition == code.length())
-        return null;
-      
+
       // Is it a comment?
-      char y = code.charAt(characterPosition);
       if (y == '#')
       {
         // Skip to the end of the line, or the end of the text.
-        while (characterPosition < code.length())
+        while (true)
         {
-          char x = code.charAt(characterPosition++);
-          if (x == '\n')
+          int x = characterStream.peek();
+          if (x == -1)
+            return null;
+          characterStream.skip();
+          y = (char)x;
+          if (y == '\n')
             break;
         }
         continue;
@@ -99,67 +94,127 @@ public class TokenStream
     }
 
     // At the start of the next token.
-    // Figure out what kind of token it is.  Currently we only care about punctuation
-    // and strings.  Furthermore, no distinction is made between quoted and unquoted
-    // strings.
-    char z = code.charAt(characterPosition);
-    if (isLegalTokenCharacter(z))
+    if (isQuoteCharacter(y))
     {
       // Legal token character
       StringBuilder tokenBuffer = new StringBuilder();
-      int quoteMark = -1;
-      while (characterPosition < code.length())
+      char quoteMark = y;
+      characterStream.skip();
+      while (true)
       {
-        char x = code.charAt(characterPosition);
-        if (quoteMark == -1)
+        int x = characterStream.peek();
+        if (x == -1)
+          break;
+        y = (char)x;
+        characterStream.skip();
+        if (y == quoteMark)
+          // End of the quotation
+          break;
+        if (y == '\\')
         {
-          // Not yet in a quote
-          if (x <= ' ' || x == '#')
-            break;
-          if (x == '\'' || x == '"')
+          // Escape character
+          x = characterStream.peek();
+          if (x != -1)
           {
-            characterPosition++;
-            quoteMark = (int)x;
+            tokenBuffer.append((char)x);
+            characterStream.skip();
           }
-          else if (isLegalTokenCharacter(x))
-          {
-            characterPosition++;
-            tokenBuffer.append(x);
-          }
-          else
-            break;
         }
         else
+          tokenBuffer.append(y);
+      }
+      return new Token(Token.TOKEN_STRING,tokenBuffer.toString(),lineNumber,characterNumber);
+    }
+    else if (isTokenCharacter(y))
+    {
+      // Legal token character
+      StringBuilder tokenBuffer = new StringBuilder();
+      while (true)
+      {
+        int x = characterStream.peek();
+        if (x == -1)
+          break;
+        y = (char)x;
+        if (isTokenCharacter(y) || isNumberCharacter(y))
         {
-          characterPosition++;
-          // In a quote.
-          if (((int)x) == quoteMark)
-            // End of the quotation
-            break;
-          if (x == '\\')
-          {
-            // Escape character
-            if (characterPosition < code.length())
-              tokenBuffer.append(code.charAt(characterPosition++));
-          }
-          else
-            tokenBuffer.append(x);
+          // Tokens can include numbers, just so long they aren't the first character
+          characterStream.skip();
+          tokenBuffer.append(y);
         }
+        else
+          break;
       }
-      return new Token(Token.TOKEN_STRING,tokenBuffer.toString());
+      return new Token(Token.TOKEN_TOKEN,tokenBuffer.toString(),lineNumber,characterNumber);
+    }
+    else if (isNumberCharacter(y))
+    {
+      StringBuilder tokenBuffer = new StringBuilder();
+      boolean seenDot = false;
+      while (true)
+      {
+        int x = characterStream.peek();
+        if (x == -1)
+          break;
+        y = (char)x;
+        if (isNumberCharacter(y))
+        {
+          tokenBuffer.append(y);
+          characterStream.skip();
+        }
+        else if (y == '.' && seenDot == false)
+        {
+          tokenBuffer.append(y);
+          seenDot = true;
+          characterStream.skip();
+        }
+        else
+          break;
+      }
+      if (seenDot)
+        return new Token(Token.TOKEN_FLOAT,tokenBuffer.toString(),lineNumber,characterNumber);
+      else
+        return new Token(Token.TOKEN_INTEGER,tokenBuffer.toString(),lineNumber,characterNumber);
     }
     else
     {
       // Set a punctuation token
-      characterPosition++;
-      return new Token(Token.TOKEN_PUNCTUATION,new StringBuilder(z).toString());
+      characterStream.skip();
+      if (y == '=' || y == '!' || y == '>' || y == '<' || y == '&' || y == '|')
+      {
+        int x = characterStream.peek();
+        if (x != -1)
+        {
+          char q = (char)x;
+          if (y == '=' && q == '=' ||
+            y == '!' && q == '=' ||
+            y == '>' && q == '=' ||
+            y == '<' && q == '=' ||
+            y == '&' && q == '&' ||
+            y == '|' && q == '|')
+          {
+            characterStream.skip();
+            return new Token(Token.TOKEN_PUNCTUATION,new StringBuilder().append(y).append(q).toString(),
+              lineNumber,characterNumber);
+          }
+        }
+      }
+      return new Token(Token.TOKEN_PUNCTUATION,new StringBuilder().append(y).toString(),
+        lineNumber,characterNumber);
     }
   }
   
-  protected static boolean isLegalTokenCharacter(char x)
+  protected static boolean isQuoteCharacter(char x)
+  {
+    return (x == '\'' || x == '"');
+  }
+  
+  protected static boolean isNumberCharacter(char x)
+  {
+    return (x >= '0' && x <= '9');
+  }
+  
+  protected static boolean isTokenCharacter(char x)
   {
-    if (x >= '0' && x <= '9')
-      return true;
     if (x >= 'a' && x <= 'z')
       return true;
     if (x >= 'A' && x <='Z')

Added: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/BreakCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/BreakCommand.java?rev=1160012&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/BreakCommand.java (added)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/BreakCommand.java Sun Aug 21 17:10:20 2011
@@ -0,0 +1,44 @@
+/* $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;
+
+/** Break command. */
+public class BreakCommand implements Command
+{
+  /** Parse and execute.  Parsing begins right after the command name, and should stop before the trailing semicolon.
+  *@param sp is the script parser to use to help in the parsing.
+  *@param currentStream is the current token stream.
+  *@return true to send a break signal, false otherwise.
+  */
+  public boolean parseAndExecute(ScriptParser sp, TokenStream currentStream)
+    throws ScriptException
+  {
+    return true;
+  }
+  
+  /** Parse and skip.  Parsing begins right after the command name, and should stop before the trailing semicolon.
+  *@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/BreakCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/CharacterStream.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/CharacterStream.java?rev=1160012&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/CharacterStream.java (added)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/CharacterStream.java Sun Aug 21 17:10:20 2011
@@ -0,0 +1,93 @@
+/* $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 java.io.*;
+
+/** Convert a Reader into a sequence of characters, while keeping track of line
+* endings.
+*/
+public class CharacterStream
+{
+  protected Reader reader;
+  protected int currentCharacter = -1;
+  protected int lineNumber = 0;
+  protected int characterNumber = 0;
+  
+  public CharacterStream(Reader reader)
+  {
+    this.reader = reader;
+  }
+  
+  public int peek()
+    throws ScriptException
+  {
+    if (currentCharacter == -1)
+      currentCharacter = readNextCharacter();
+    return currentCharacter;
+  }
+  
+  public void skip()
+  {
+    currentCharacter = -1;
+  }
+  
+  public int getLineNumber()
+  {
+    return lineNumber;
+  }
+  
+  public int getCharacterNumber()
+  {
+    return characterNumber;
+  }
+  
+  // Protected methods
+  
+  protected int readNextCharacter()
+    throws ScriptException
+  {
+    if (reader == null)
+      return -1;
+    
+    try
+    {
+      int rval = reader.read();
+      if (rval == -1)
+      {
+        reader.close();
+        reader = null;
+        return -1;
+      }
+      characterNumber++;
+      if (((char)rval) == '\n')
+      {
+        lineNumber++;
+        characterNumber = 0;
+      }
+      return rval;
+    }
+    catch (IOException e)
+    {
+      throw new ScriptException("I/O exception: "+e.getMessage(),e);
+    }
+  }
+  
+}

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

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

Added: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/Command.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/Command.java?rev=1160012&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/Command.java (added)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/Command.java Sun Aug 21 17:10:20 2011
@@ -0,0 +1,41 @@
+/* $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;
+
+/** Interface describing what a command needs to do.
+*/
+public interface Command
+{
+  /** Parse and execute.  Parsing begins right after the command name, and should stop before the trailing semicolon.
+  *@param sp is the script parser to use to help in the parsing.
+  *@param currentStream is the current token stream.
+  *@return true to send a break signal, false otherwise.
+  */
+  public boolean parseAndExecute(ScriptParser sp, TokenStream currentStream)
+    throws ScriptException;
+  
+  /** Parse and skip.  Parsing begins right after the command name, and should stop before the trailing semicolon.
+  *@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/Command.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ContextVariableReference.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ContextVariableReference.java?rev=1160012&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ContextVariableReference.java (added)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ContextVariableReference.java Sun Aug 21 17:10:20 2011
@@ -0,0 +1,48 @@
+/* $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;
+
+/** Overwritable variable references from within a context.
+*/
+public class ContextVariableReference implements VariableReference
+{
+  protected Variable variable = null;
+  
+  public ContextVariableReference()
+  {
+  }
+  
+  /** Set the reference */
+  public void setReference(Variable object)
+    throws ScriptException
+  {
+    variable = object;
+  }
+  
+  /** Resolve the reference */
+  public Variable resolve()
+    throws ScriptException
+  {
+    if (variable == null)
+      throw new ScriptException("Attempt to dereference null variable pointer");
+    return variable;
+  }
+
+}

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

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

Added: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/DELETECommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/DELETECommand.java?rev=1160012&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/DELETECommand.java (added)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/DELETECommand.java Sun Aug 21 17:10:20 2011
@@ -0,0 +1,88 @@
+/* $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.commons.httpclient.*;
+import org.apache.commons.httpclient.methods.*;
+import java.io.*;
+
+/** DELETE command.  This performs a REST-style DELETE operation, designed to work
+* against the ManifoldCF API.  The syntax is: DELETE resultvariable = urlvariable */
+public class DELETECommand implements Command
+{
+  /** Parse and execute.  Parsing begins right after the command name, and should stop before the trailing semicolon.
+  *@param sp is the script parser to use to help in the parsing.
+  *@param currentStream is the current token stream.
+  *@return true to send a break signal, false otherwise.
+  */
+  public boolean parseAndExecute(ScriptParser sp, TokenStream currentStream)
+    throws ScriptException
+  {
+    VariableReference result = sp.evaluateExpression(currentStream);
+    if (result == null)
+      sp.syntaxError(currentStream,"Missing result expression");
+    Token t = currentStream.peek();
+    if (t == null || t.getPunctuation() == null || !t.getPunctuation().equals("="))
+      sp.syntaxError(currentStream,"Missing '=' sign");
+    currentStream.skip();
+    VariableReference url = sp.evaluateExpression(currentStream);
+    if (url == null)
+      sp.syntaxError(currentStream,"Missing URL expression");
+    
+    // Perform the actual GET.
+    String urlString = url.resolve().getStringValue();
+    
+    try
+    {
+      HttpClient client = new HttpClient();
+      DeleteMethod method = new DeleteMethod(urlString);
+      int resultCode = client.executeMethod(method);
+      byte[] responseData = method.getResponseBody();
+      // We presume that the data is utf-8, since that's what the API
+      // uses throughout.
+      String resultJSON = new String(responseData,"utf-8");
+
+      result.setReference(new VariableResult(resultCode,resultJSON));
+    
+      return false;
+    }
+    catch (IOException e)
+    {
+      throw new ScriptException(e.getMessage(),e);
+    }
+  }
+  
+  /** Parse and skip.  Parsing begins right after the command name, and should stop before the trailing semicolon.
+  *@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
+  {
+    if (sp.skipExpression(currentStream) == false)
+      sp.syntaxError(currentStream,"Missing result expression");
+    Token t = currentStream.peek();
+    if (t == null || t.getPunctuation() == null || !t.getPunctuation().equals("="))
+      sp.syntaxError(currentStream,"Missing '=' sign");
+    currentStream.skip();
+    if (sp.skipExpression(currentStream) == false)
+      sp.syntaxError(currentStream,"Missing URL expression");
+  }
+
+}

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

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

Added: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/GETCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/GETCommand.java?rev=1160012&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/GETCommand.java (added)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/GETCommand.java Sun Aug 21 17:10:20 2011
@@ -0,0 +1,88 @@
+/* $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.commons.httpclient.*;
+import org.apache.commons.httpclient.methods.*;
+import java.io.*;
+
+/** GET command.  This performs a REST-style GET operation, designed to work
+* against the ManifoldCF API.  The syntax is: GET resultvariable = urlvariable */
+public class GETCommand implements Command
+{
+  /** Parse and execute.  Parsing begins right after the command name, and should stop before the trailing semicolon.
+  *@param sp is the script parser to use to help in the parsing.
+  *@param currentStream is the current token stream.
+  *@return true to send a break signal, false otherwise.
+  */
+  public boolean parseAndExecute(ScriptParser sp, TokenStream currentStream)
+    throws ScriptException
+  {
+    VariableReference result = sp.evaluateExpression(currentStream);
+    if (result == null)
+      sp.syntaxError(currentStream,"Missing result expression");
+    Token t = currentStream.peek();
+    if (t == null || t.getPunctuation() == null || !t.getPunctuation().equals("="))
+      sp.syntaxError(currentStream,"Missing '=' sign");
+    currentStream.skip();
+    VariableReference url = sp.evaluateExpression(currentStream);
+    if (url == null)
+      sp.syntaxError(currentStream,"Missing URL expression");
+    
+    // Perform the actual GET.
+    String urlString = url.resolve().getStringValue();
+    
+    try
+    {
+      HttpClient client = new HttpClient();
+      GetMethod method = new GetMethod(urlString);
+      int resultCode = client.executeMethod(method);
+      byte[] responseData = method.getResponseBody();
+      // We presume that the data is utf-8, since that's what the API
+      // uses throughout.
+      String resultJSON = new String(responseData,"utf-8");
+
+      result.setReference(new VariableResult(resultCode,resultJSON));
+    
+      return false;
+    }
+    catch (IOException e)
+    {
+      throw new ScriptException(e.getMessage(),e);
+    }
+  }
+  
+  /** Parse and skip.  Parsing begins right after the command name, and should stop before the trailing semicolon.
+  *@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
+  {
+    if (sp.skipExpression(currentStream) == false)
+      sp.syntaxError(currentStream,"Missing result expression");
+    Token t = currentStream.peek();
+    if (t == null || t.getPunctuation() == null || !t.getPunctuation().equals("="))
+      sp.syntaxError(currentStream,"Missing '=' sign");
+    currentStream.skip();
+    if (sp.skipExpression(currentStream) == false)
+      sp.syntaxError(currentStream,"Missing URL expression");
+  }
+
+}

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

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

Added: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/IfCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/IfCommand.java?rev=1160012&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/IfCommand.java (added)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/IfCommand.java Sun Aug 21 17:10:20 2011
@@ -0,0 +1,88 @@
+/* $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;
+
+/** If command. */
+public class IfCommand implements Command
+{
+  /** Parse and execute.  Parsing begins right after the command name, and should stop before the trailing semicolon.
+  *@param sp is the script parser to use to help in the parsing.
+  *@param currentStream is the current token stream.
+  *@return true to send a break signal, false otherwise.
+  */
+  public boolean parseAndExecute(ScriptParser sp, TokenStream currentStream)
+    throws ScriptException
+  {
+    boolean rval = false;
+    VariableReference ifCondition = sp.evaluateExpression(currentStream);
+    if (ifCondition == null)
+      sp.syntaxError(currentStream,"Missing if expression");
+    Token t = currentStream.peek();
+    if (t == null || t.getToken() == null || !t.getToken().equals("then"))
+      sp.syntaxError(currentStream,"Missing 'then' in if statement");
+    currentStream.skip();
+    if (ifCondition.resolve().getBooleanValue())
+    {
+      rval = sp.parseStatements(currentStream);
+      t = currentStream.peek();
+      if (t != null &&t.getToken().equals("else"))
+      {
+        currentStream.skip();
+        // Skip statements
+        sp.skipStatements(currentStream);
+      }
+    }
+    else
+    {
+      sp.skipStatements(currentStream);
+      t = currentStream.peek();
+      if (t != null && t.getToken().equals("else"))
+      {
+        currentStream.skip();
+        // Parse statements
+        rval = sp.parseStatements(currentStream);
+      }
+    }
+    return rval;
+  }
+  
+  /** Parse and skip.  Parsing begins right after the command name, and should stop before the trailing semicolon.
+  *@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
+  {
+    if (sp.skipExpression(currentStream) == false)
+      sp.syntaxError(currentStream,"Missing if expression");
+    Token t = currentStream.peek();
+    if (t == null || t.getToken() == null || !t.getToken().equals("then"))
+      sp.syntaxError(currentStream,"Missing 'then' in if statement");
+    currentStream.skip();
+    sp.skipStatements(currentStream);
+    t = currentStream.peek();
+    if (t != null &&t.getToken().equals("else"))
+    {
+      currentStream.skip();
+      // Skip statements
+      sp.skipStatements(currentStream);
+    }
+  }
+
+}

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

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

Added: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NullVariableReference.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NullVariableReference.java?rev=1160012&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NullVariableReference.java (added)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NullVariableReference.java Sun Aug 21 17:10:20 2011
@@ -0,0 +1,44 @@
+/* $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;
+
+/** Null variable reference.
+*/
+public class NullVariableReference implements VariableReference
+{
+  public NullVariableReference()
+  {
+  }
+  
+  /** Set the reference */
+  public void setReference(Variable object)
+    throws ScriptException
+  {
+    throw new ScriptException("Null reference is immutable");
+  }
+  
+  /** Resolve the reference */
+  public Variable resolve()
+    throws ScriptException
+  {
+    throw new ScriptException("Attempt to dereference null variable pointer");
+  }
+
+}

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

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

Added: 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=1160012&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/POSTCommand.java (added)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/POSTCommand.java Sun Aug 21 17:10:20 2011
@@ -0,0 +1,104 @@
+/* $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.commons.httpclient.*;
+import org.apache.commons.httpclient.methods.*;
+import java.io.*;
+
+/** POST command.  This performs a REST-style POST operation, designed to work
+* against the ManifoldCF API.  The syntax is: POST resultvariable = sendvariable to urlvariable*/
+public class POSTCommand implements Command
+{
+  /** Parse and execute.  Parsing begins right after the command name, and should stop before the trailing semicolon.
+  *@param sp is the script parser to use to help in the parsing.
+  *@param currentStream is the current token stream.
+  *@return true to send a break signal, false otherwise.
+  */
+  public boolean parseAndExecute(ScriptParser sp, TokenStream currentStream)
+    throws ScriptException
+  {
+    VariableReference result = sp.evaluateExpression(currentStream);
+    if (result == null)
+      sp.syntaxError(currentStream,"Missing result expression");
+    Token t = currentStream.peek();
+    if (t == null || t.getPunctuation() == null || !t.getPunctuation().equals("="))
+      sp.syntaxError(currentStream,"Missing '=' sign");
+    currentStream.skip();
+    VariableReference send = sp.evaluateExpression(currentStream);
+    if (send == null)
+      sp.syntaxError(currentStream,"Missing send expression");
+    t = currentStream.peek();
+    if (t == null || t.getToken() == null || !t.getToken().equals("to"))
+      sp.syntaxError(currentStream,"Missing 'to'");
+    currentStream.skip();
+    VariableReference url = sp.evaluateExpression(currentStream);
+    if (url == null)
+      sp.syntaxError(currentStream,"Missing URL expression");
+    
+    // Perform the actual PUT.
+    String urlString = url.resolve().getStringValue();
+    String json = send.resolve().getJSONValue();
+    
+    try
+    {
+      HttpClient client = new HttpClient();
+      PostMethod method = new PostMethod(urlString);
+      method.setRequestHeader("Content-type", "text/plain; charset=UTF-8");
+      method.setRequestBody(json);
+      int resultCode = client.executeMethod(method);
+      byte[] responseData = method.getResponseBody();
+      // We presume that the data is utf-8, since that's what the API
+      // uses throughout.
+      String resultJSON = new String(responseData,"utf-8");
+
+      result.setReference(new VariableResult(resultCode,resultJSON));
+    
+      return false;
+    }
+    catch (IOException e)
+    {
+      throw new ScriptException(e.getMessage(),e);
+    }
+  }
+  
+  /** Parse and skip.  Parsing begins right after the command name, and should stop before the trailing semicolon.
+  *@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
+  {
+    if (sp.skipExpression(currentStream) == false)
+      sp.syntaxError(currentStream,"Missing result expression");
+    Token t = currentStream.peek();
+    if (t == null || t.getPunctuation() == null || !t.getPunctuation().equals("="))
+      sp.syntaxError(currentStream,"Missing '=' sign");
+    currentStream.skip();
+    if (sp.skipExpression(currentStream) == false)
+      sp.syntaxError(currentStream,"Missing send expression");
+    t = currentStream.peek();
+    if (t == null || t.getToken() == null || !t.getToken().equals("to"))
+      sp.syntaxError(currentStream,"Missing 'to'");
+    currentStream.skip();
+    if (sp.skipExpression(currentStream) == false)
+      sp.syntaxError(currentStream,"Missing URL expression");
+  }
+
+}

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

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

Added: 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=1160012&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PUTCommand.java (added)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PUTCommand.java Sun Aug 21 17:10:20 2011
@@ -0,0 +1,104 @@
+/* $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.commons.httpclient.*;
+import org.apache.commons.httpclient.methods.*;
+import java.io.*;
+
+/** PUT command.  This performs a REST-style PUT operation, designed to work
+* against the ManifoldCF API.  The syntax is: PUT resultvariable = sendvariable to urlvariable*/
+public class PUTCommand implements Command
+{
+  /** Parse and execute.  Parsing begins right after the command name, and should stop before the trailing semicolon.
+  *@param sp is the script parser to use to help in the parsing.
+  *@param currentStream is the current token stream.
+  *@return true to send a break signal, false otherwise.
+  */
+  public boolean parseAndExecute(ScriptParser sp, TokenStream currentStream)
+    throws ScriptException
+  {
+    VariableReference result = sp.evaluateExpression(currentStream);
+    if (result == null)
+      sp.syntaxError(currentStream,"Missing result expression");
+    Token t = currentStream.peek();
+    if (t == null || t.getPunctuation() == null || !t.getPunctuation().equals("="))
+      sp.syntaxError(currentStream,"Missing '=' sign");
+    currentStream.skip();
+    VariableReference send = sp.evaluateExpression(currentStream);
+    if (send == null)
+      sp.syntaxError(currentStream,"Missing send expression");
+    t = currentStream.peek();
+    if (t == null || t.getToken() == null || !t.getToken().equals("to"))
+      sp.syntaxError(currentStream,"Missing 'to'");
+    currentStream.skip();
+    VariableReference url = sp.evaluateExpression(currentStream);
+    if (url == null)
+      sp.syntaxError(currentStream,"Missing URL expression");
+    
+    // Perform the actual PUT.
+    String urlString = url.resolve().getStringValue();
+    String json = send.resolve().getJSONValue();
+    
+    try
+    {
+      HttpClient client = new HttpClient();
+      PutMethod method = new PutMethod(urlString);
+      method.setRequestHeader("Content-type", "text/plain; charset=UTF-8");
+      method.setRequestBody(json);
+      int resultCode = client.executeMethod(method);
+      byte[] responseData = method.getResponseBody();
+      // We presume that the data is utf-8, since that's what the API
+      // uses throughout.
+      String resultJSON = new String(responseData,"utf-8");
+
+      result.setReference(new VariableResult(resultCode,resultJSON));
+    
+      return false;
+    }
+    catch (IOException e)
+    {
+      throw new ScriptException(e.getMessage(),e);
+    }
+  }
+  
+  /** Parse and skip.  Parsing begins right after the command name, and should stop before the trailing semicolon.
+  *@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
+  {
+    if (sp.skipExpression(currentStream) == false)
+      sp.syntaxError(currentStream,"Missing result expression");
+    Token t = currentStream.peek();
+    if (t == null || t.getPunctuation() == null || !t.getPunctuation().equals("="))
+      sp.syntaxError(currentStream,"Missing '=' sign");
+    currentStream.skip();
+    if (sp.skipExpression(currentStream) == false)
+      sp.syntaxError(currentStream,"Missing send expression");
+    t = currentStream.peek();
+    if (t == null || t.getToken() == null || !t.getToken().equals("to"))
+      sp.syntaxError(currentStream,"Missing 'to'");
+    currentStream.skip();
+    if (sp.skipExpression(currentStream) == false)
+      sp.syntaxError(currentStream,"Missing URL expression");
+  }
+
+}

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

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

Added: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PrintCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PrintCommand.java?rev=1160012&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PrintCommand.java (added)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PrintCommand.java Sun Aug 21 17:10:20 2011
@@ -0,0 +1,50 @@
+/* $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;
+
+/** Print command. */
+public class PrintCommand implements Command
+{
+  /** Parse and execute.  Parsing begins right after the command name, and should stop before the trailing semicolon.
+  *@param sp is the script parser to use to help in the parsing.
+  *@param currentStream is the current token stream.
+  *@return true to send a break signal, false otherwise.
+  */
+  public boolean parseAndExecute(ScriptParser sp, TokenStream currentStream)
+    throws ScriptException
+  {
+    VariableReference expr = sp.evaluateExpression(currentStream);
+    if (expr == null)
+      sp.syntaxError(currentStream,"Missing print expression");
+    System.out.println(expr.resolve().getStringValue());
+    return false;
+  }
+  
+  /** Parse and skip.  Parsing begins right after the command name, and should stop before the trailing semicolon.
+  *@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
+  {
+    if (sp.skipExpression(currentStream) == false)
+      sp.syntaxError(currentStream,"Missing print expression");
+  }
+
+}

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

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

Added: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/RewindableTokenStream.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/RewindableTokenStream.java?rev=1160012&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/RewindableTokenStream.java (added)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/RewindableTokenStream.java Sun Aug 21 17:10:20 2011
@@ -0,0 +1,65 @@
+/* $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 java.util.*;
+
+/** Allows a TokenStream to be repeated as long as a sequence start is kept.
+*/
+public class RewindableTokenStream implements TokenStream
+{
+  protected TokenStream parent;
+  protected List<Token> history = new ArrayList<Token>();
+  protected int currentIndex = 0;
+  protected int committedSize = 0;
+  
+  public RewindableTokenStream(TokenStream parent)
+  {
+    this.parent = parent;
+  }
+  
+  public Token peek()
+    throws ScriptException
+  {
+    if (history.size() > currentIndex)
+      return history.get(currentIndex);
+    Token rval = parent.peek();
+    history.add(rval);
+    return rval;
+  }
+  
+  public void skip()
+  {
+    currentIndex++;
+    if (currentIndex > committedSize)
+    {
+      parent.skip();
+      committedSize++;
+    }
+    if (currentIndex > committedSize)
+      throw new RuntimeException("Two skips in a row!");
+  }
+  
+  public void reset()
+  {
+    currentIndex = 0;
+  }
+  
+}

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

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



Mime
View raw message