Author: kwright
Date: Mon Feb 25 16:19:15 2013
New Revision: 1449762
URL: http://svn.apache.org/r1449762
Log:
Fix for CONNECTORS-651. Add scripting support for query arguments.
Added:
manifoldcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableQueryArg.java
(with props)
Modified:
manifoldcf/trunk/CHANGES.txt
manifoldcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java
manifoldcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java
Modified: manifoldcf/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/manifoldcf/trunk/CHANGES.txt?rev=1449762&r1=1449761&r2=1449762&view=diff
==============================================================================
--- manifoldcf/trunk/CHANGES.txt (original)
+++ manifoldcf/trunk/CHANGES.txt Mon Feb 25 16:19:15 2013
@@ -3,6 +3,9 @@ $Id$
======================= 1.2-dev =====================
+CONNECTORS-651: Add query argument support to script client.
+(Karl Wright)
+
CONNECTORS-63: Add API support for history and queue reports.
(Karl Wright)
Modified:
manifoldcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java
URL:
http://svn.apache.org/viewvc/manifoldcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java?rev=1449762&r1=1449761&r2=1449762&view=diff
==============================================================================
---
manifoldcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java
(original)
+++
manifoldcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java
Mon Feb 25 16:19:15 2013
@@ -1242,6 +1242,7 @@ public class ScriptParser
sp.addNewOperation("connectionname",new NewConnectionName());
sp.addNewOperation("array",new NewArray());
sp.addNewOperation("dictionary",new NewDictionary());
+ sp.addNewOperation("queryarg",new NewQueryArgument());
try
{
Added:
manifoldcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableQueryArg.java
URL:
http://svn.apache.org/viewvc/manifoldcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableQueryArg.java?rev=1449762&view=auto
==============================================================================
---
manifoldcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableQueryArg.java
(added)
+++
manifoldcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableQueryArg.java
Mon Feb 25 16:19:15 2013
@@ -0,0 +1,146 @@
+/* $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.net.*;
+import java.io.*;
+
+/** Variable class representing a ManifoldCF query argument, with a name
+* and a value.
+*/
+public class VariableQueryArg extends VariableBase
+{
+ protected final String name;
+ protected final String value;
+
+ public VariableQueryArg(String name, String value)
+ {
+ if (value == null)
+ value = "";
+ this.name = name;
+ this.value = value;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return name.hashCode() + value.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (!(o instanceof VariableQueryArg))
+ return false;
+ VariableQueryArg other = (VariableQueryArg)o;
+ return other.name.equals(name) && other.value.equals(value);
+ }
+
+ /** Check if the variable has a string value */
+ @Override
+ public boolean hasStringValue()
+ throws ScriptException
+ {
+ return true;
+ }
+
+ /** Check if the variable has a script value */
+ @Override
+ public boolean hasScriptValue()
+ throws ScriptException
+ {
+ return true;
+ }
+
+ /** Check if the variable has a query arg value */
+ @Override
+ public boolean hasQueryArgumentValue()
+ throws ScriptException
+ {
+ return true;
+ }
+
+ /** Get the variable's script value */
+ @Override
+ public String getScriptValue()
+ throws ScriptException
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("new queryarg
").append(escapeValue(name)).append("=").append(escapeValue(value));
+ return sb.toString();
+ }
+
+ protected static String escapeValue(String input)
+ {
+ StringBuilder sb = new StringBuilder("\"");
+ int i = 0;
+ while (i < input.length())
+ {
+ char x = input.charAt(i++);
+ if (x == '\\' || x == '\"')
+ sb.append('\\');
+ sb.append(x);
+ }
+ sb.append("\"");
+ return sb.toString();
+ }
+
+ /** Get the variable's value as a string */
+ @Override
+ public String getStringValue()
+ throws ScriptException
+ {
+ try
+ {
+ return URLEncoder.encode(name,"utf-8").replace("+","%20") + "=" +
+ URLEncoder.encode(value,"utf-8").replace("+","%20");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new ScriptException(composeMessage(e.getMessage()),e);
+ }
+ }
+
+ @Override
+ public String getQueryArgumentValue()
+ throws ScriptException
+ {
+ return getStringValue();
+ }
+
+ @Override
+ public VariableReference doubleEquals(Variable v)
+ throws ScriptException
+ {
+ if (v == null)
+ throw new ScriptException(composeMessage("Binary '==' operand cannot be
null"));
+ return new VariableBoolean(getStringValue().equals(v.getStringValue()));
+ }
+
+ @Override
+ public VariableReference exclamationEquals(Variable v)
+ throws ScriptException
+ {
+ if (v == null)
+ throw new ScriptException(composeMessage("Binary '!=' operand cannot be
null"));
+ return new VariableBoolean(!getStringValue().equals(v.getStringValue()));
+ }
+
+}
Propchange:
manifoldcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableQueryArg.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
manifoldcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableQueryArg.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified:
manifoldcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java
URL:
http://svn.apache.org/viewvc/manifoldcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java?rev=1449762&r1=1449761&r2=1449762&view=diff
==============================================================================
---
manifoldcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java
(original)
+++
manifoldcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java
Mon Feb 25 16:19:15 2013
@@ -28,18 +28,25 @@ import java.io.*;
public class VariableURL extends VariableBase
{
protected String encodedURL;
+ protected String encodedArgs;
public VariableURL(String baseURLValue)
{
+ this(baseURLValue,null);
+ }
+
+ public VariableURL(String baseURLValue, String encodedArgsValue)
+ {
this.encodedURL = baseURLValue;
if (encodedURL.endsWith("/"))
this.encodedURL =
this.encodedURL.substring(0,this.encodedURL.length()-1);
+ this.encodedArgs = encodedArgsValue;
}
@Override
public int hashCode()
{
- return encodedURL.hashCode();
+ return encodedURL.hashCode() + encodedArgs.hashCode();
}
@Override
@@ -47,7 +54,18 @@ public class VariableURL extends Variabl
{
if (!(o instanceof VariableURL))
return false;
- return ((VariableURL)o).encodedURL.equals(encodedURL);
+ VariableURL other = (VariableURL)o;
+ if (!other.encodedURL.equals(encodedURL))
+ return false;
+ if (other.encodedArgs != null || encodedArgs != null)
+ {
+ if (other.encodedArgs == encodedArgs)
+ return true;
+ if (other.encodedArgs == null || encodedArgs == null)
+ return false;
+ return other.encodedArgs.equals(encodedArgs);
+ }
+ return true;
}
/** Check if the variable has a string value */
@@ -72,11 +90,12 @@ public class VariableURL extends Variabl
throws ScriptException
{
StringBuilder sb = new StringBuilder();
+ String value = getStringValue();
sb.append("\"");
int i = 0;
- while (i < encodedURL.length())
+ while (i < value.length())
{
- char x = encodedURL.charAt(i++);
+ char x = value.charAt(i++);
if (x == '\\' || x == '\"')
sb.append('\\');
sb.append(x);
@@ -90,7 +109,10 @@ public class VariableURL extends Variabl
public String getStringValue()
throws ScriptException
{
- return encodedURL;
+ if (encodedArgs != null)
+ return encodedURL + "?" + encodedArgs;
+ else
+ return encodedURL;
}
@Override
@@ -99,7 +121,18 @@ public class VariableURL extends Variabl
{
if (v == null)
throw new ScriptException(composeMessage("Binary '+' operand cannot be
null"));
- return new VariableURL(encodedURL + "/" + v.getURLPathValue());
+ String urlSide = encodedURL;
+ if (v.hasURLPathValue())
+ urlSide += "/" + v.getURLPathValue();
+ String argSide = encodedArgs;
+ if (v.hasQueryArgumentValue())
+ {
+ if (argSide == null)
+ argSide = v.getQueryArgumentValue();
+ else
+ argSide = "&" + v.getQueryArgumentValue();
+ }
+ return new VariableURL(urlSide,argSide);
}
@Override
@@ -108,7 +141,7 @@ public class VariableURL extends Variabl
{
if (v == null)
throw new ScriptException(composeMessage("Binary '==' operand cannot be
null"));
- return new VariableBoolean(encodedURL.equals(v.getStringValue()));
+ return new VariableBoolean(getStringValue().equals(v.getStringValue()));
}
@Override
@@ -117,7 +150,7 @@ public class VariableURL extends Variabl
{
if (v == null)
throw new ScriptException(composeMessage("Binary '!=' operand cannot be
null"));
- return new VariableBoolean(!encodedURL.equals(v.getStringValue()));
+ return new VariableBoolean(!getStringValue().equals(v.getStringValue()));
}
}