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/24 13:59:17 UTC

svn commit: r1161061 - in /incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine: NewConnectionName.java ScriptParser.java VariableConnectionName.java VariableURL.java

Author: kwright
Date: Wed Aug 24 11:59:16 2011
New Revision: 1161061

URL: http://svn.apache.org/viewvc?rev=1161061&view=rev
Log:
Add support for building proper ManifoldCF API URLs

Added:
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NewConnectionName.java   (with props)
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConnectionName.java   (with props)
Modified:
    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/VariableURL.java

Added: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NewConnectionName.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NewConnectionName.java?rev=1161061&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NewConnectionName.java (added)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NewConnectionName.java Wed Aug 24 11:59:16 2011
@@ -0,0 +1,51 @@
+/* $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 Connection Name object.
+*/
+public class NewConnectionName 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
+  {
+    VariableReference connectionName = sp.evaluateExpression(currentStream);
+    if (connectionName == null)
+      sp.syntaxError(currentStream,"Need connection name expression");
+    String connectionNameString = sp.resolveMustExist(currentStream,connectionName).getStringValue();
+    return new VariableConnectionName(connectionNameString);
+  }
+  
+  /** 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
+  {
+    sp.skipExpression(currentStream);
+  }
+  
+}

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

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

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=1161061&r1=1161060&r2=1161061&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 24 11:59:16 2011
@@ -908,6 +908,7 @@ public class ScriptParser
     sp.addNewOperation("configuration",new NewConfiguration());
     sp.addNewOperation("configurationnode",new NewConfigurationNode());
     sp.addNewOperation("url",new NewURL());
+    sp.addNewOperation("connectionname",new NewConnectionName());
     
     try
     {

Added: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConnectionName.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConnectionName.java?rev=1161061&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConnectionName.java (added)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConnectionName.java Wed Aug 24 11:59:16 2011
@@ -0,0 +1,76 @@
+/* $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;
+
+
+/** Variable class representing a ManifoldCF API URL connection name segment.  In conjunction
+* with the URL variable, this variable will properly character-stuff the connection name to make
+* a valid URL.
+*/
+public class VariableConnectionName extends VariableBase
+{
+  protected String encodedConnectionName;
+  
+  public VariableConnectionName(String connectionName)
+  {
+    this.encodedConnectionName = encode(connectionName);
+  }
+  
+  /** Get the variable's value as a string */
+  public String getStringValue()
+    throws ScriptException
+  {
+    return encodedConnectionName;
+  }
+
+  public VariableReference doubleEquals(Variable v)
+    throws ScriptException
+  {
+    if (v == null)
+      throw new ScriptException("== operand cannot be null");
+    return new VariableBoolean(encodedConnectionName.equals(v.getStringValue()));
+  }
+
+  public VariableReference exclamationEquals(Variable v)
+    throws ScriptException
+  {
+    if (v == null)
+      throw new ScriptException("!= operand cannot be null");
+    return new VariableBoolean(!encodedConnectionName.equals(v.getStringValue()));
+  }
+
+  protected static String encode(String connectionName)
+  {
+    StringBuilder sb = new StringBuilder();
+    int i = 0;
+    while (i < connectionName.length())
+    {
+      char x = connectionName.charAt(i++);
+      if (x == '/')
+        sb.append('.').append('+');
+      else if (x == '.')
+        sb.append('.').append('.');
+      else
+        sb.append(x);
+    }
+    return sb.toString();
+  }
+  
+}

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

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

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java?rev=1161061&r1=1161060&r2=1161061&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java (original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java Wed Aug 24 11:59:16 2011
@@ -50,7 +50,7 @@ public class VariableURL extends Variabl
       throw new ScriptException("+ operand cannot be null");
     try
     {
-      return new VariableURL(encodedURL + "/" + URLEncoder.encode(v.getStringValue(),"utf-8"));
+      return new VariableURL(encodedURL + "/" + URLEncoder.encode(v.getStringValue(),"utf-8").replace("+","%20"));
     }
     catch (UnsupportedEncodingException e)
     {