Return-Path: X-Original-To: apmail-manifoldcf-commits-archive@www.apache.org Delivered-To: apmail-manifoldcf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6744DEC03 for ; Mon, 25 Feb 2013 16:19:43 +0000 (UTC) Received: (qmail 73150 invoked by uid 500); 25 Feb 2013 16:19:43 -0000 Delivered-To: apmail-manifoldcf-commits-archive@manifoldcf.apache.org Received: (qmail 73076 invoked by uid 500); 25 Feb 2013 16:19:41 -0000 Mailing-List: contact commits-help@manifoldcf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@manifoldcf.apache.org Delivered-To: mailing list commits@manifoldcf.apache.org Received: (qmail 73043 invoked by uid 99); 25 Feb 2013 16:19:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Feb 2013 16:19:40 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Feb 2013 16:19:34 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D0C59238890B; Mon, 25 Feb 2013 16:19:15 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1449762 - in /manifoldcf/trunk: ./ framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ Date: Mon, 25 Feb 2013 16:19:15 -0000 To: commits@manifoldcf.apache.org From: kwright@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130225161915.D0C59238890B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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())); } }