jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1412519 - in /jmeter/trunk: src/core/org/apache/jmeter/resources/ src/functions/org/apache/jmeter/functions/ xdocs/ xdocs/usermanual/
Date Thu, 22 Nov 2012 12:23:48 GMT
Author: pmouawad
Date: Thu Nov 22 12:23:44 2012
New Revision: 1412519

URL: http://svn.apache.org/viewvc?rev=1412519&view=rev
Log:
Bug 54189 - Add a function to quote ORO regexp meta characters
Bugzilla Id: 54189

Added:
    jmeter/trunk/src/functions/org/apache/jmeter/functions/EscapeOroRegexpChars.java   (with
props)
Modified:
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/functions.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=1412519&r1=1412518&r2=1412519&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Thu Nov 22 12:23:44
2012
@@ -1095,6 +1095,7 @@ userdn=Username
 username=Username
 userpw=Password
 value=Value
+value_to_quote_meta=Value to escape from ORO Regexp meta chars
 var_name=Reference Name
 variable_name_param=Name of variable (may include variable and function references)
 view_graph_tree_title=View Graph Tree

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties?rev=1412519&r1=1412518&r2=1412519&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties Thu Nov 22 12:23:44
2012
@@ -1089,6 +1089,7 @@ userdn=Identifiant
 username=Nom d'utilisateur \:
 userpw=Mot de passe
 value=Valeur \:
+value_to_quote_meta=Valeur \u00E0 \u00E9chapper des caract\u00E8res sp\u00E9ciaux utilis\u00E8s
par ORO Regexp
 var_name=Nom de r\u00E9f\u00E9rence \:
 variable_name_param=Nom de variable (peut inclure une r\u00E9f\u00E9rence de variable ou
fonction)
 view_graph_tree_title=Voir le graphique en arbre

Added: jmeter/trunk/src/functions/org/apache/jmeter/functions/EscapeOroRegexpChars.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/functions/org/apache/jmeter/functions/EscapeOroRegexpChars.java?rev=1412519&view=auto
==============================================================================
--- jmeter/trunk/src/functions/org/apache/jmeter/functions/EscapeOroRegexpChars.java (added)
+++ jmeter/trunk/src/functions/org/apache/jmeter/functions/EscapeOroRegexpChars.java Thu Nov
22 12:23:44 2012
@@ -0,0 +1,120 @@
+/*
+ * 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.jmeter.functions;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.jmeter.engine.util.CompoundVariable;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.samplers.Sampler;
+import org.apache.jmeter.threads.JMeterVariables;
+import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.logging.LoggingManager;
+import org.apache.log.Logger;
+import org.apache.oro.text.regex.Perl5Compiler;
+
+/**
+ * Escape ORO meta characters
+ * @since 2.9
+ */
+public class EscapeOroRegexpChars extends AbstractFunction {
+    private static final Logger log = LoggingManager.getLoggerForClass();
+
+    private static final List<String> desc = new LinkedList<String>();
+
+    private static final String KEY = "__escapeOroRegexpChars"; //$NON-NLS-1$
+
+    static {
+        desc.add(JMeterUtils.getResString("value_to_quote_meta")); //$NON-NLS-1$
+        desc.add(JMeterUtils.getResString("function_name_paropt")); //$NON-NLS-1$
+    }
+
+    private CompoundVariable[] values;
+
+    private static final int MAX_PARAM_COUNT = 2;
+
+    private static final int MIN_PARAM_COUNT = 1;
+    
+    private static final int CHARS = 1;
+
+    private static final int PARAM_NAME = 2;
+
+    /**
+     * No-arg constructor.
+     */
+    public EscapeOroRegexpChars() {
+        super();
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
+            throws InvalidVariableException {
+
+        String charsToUse = null;//means no restriction
+        if (values.length >= CHARS) {
+            charsToUse = (values[CHARS - 1]).execute().trim();
+            if (charsToUse.length() <= 0) { // empty chars, return to null
+                charsToUse = null;
+            }
+        }
+
+        String myName = "";//$NON-NLS-1$
+        if (values.length >= PARAM_NAME) {
+            myName = (values[PARAM_NAME - 1]).execute().trim();
+        }
+
+        String myValue = Perl5Compiler.quotemeta(charsToUse);
+         
+        if (myName.length() > 0) {
+            JMeterVariables vars = getVariables();
+            if (vars != null) {// Can be null if called from Config item testEnded() method
+                vars.put(myName, myValue);
+            }
+        }
+
+        if (log.isDebugEnabled()) {
+            String tn = Thread.currentThread().getName();
+            log.debug(tn + " name:" //$NON-NLS-1$
+                    + myName + " value:" + myValue);//$NON-NLS-1$
+        }
+
+        return myValue;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public synchronized void setParameters(Collection<CompoundVariable> parameters)
throws InvalidVariableException {
+        checkParameterCount(parameters, MIN_PARAM_COUNT, MAX_PARAM_COUNT);
+        values = parameters.toArray(new CompoundVariable[parameters.size()]);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String getReferenceKey() {
+        return KEY;
+    }
+
+    /** {@inheritDoc} */
+    public List<String> getArgumentDesc() {
+        return desc;
+    }
+}
\ No newline at end of file

Propchange: jmeter/trunk/src/functions/org/apache/jmeter/functions/EscapeOroRegexpChars.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1412519&r1=1412518&r2=1412519&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Thu Nov 22 12:23:44 2012
@@ -187,6 +187,7 @@ and right angle bracket (&gt;) in search
 
 <h3>Functions</h3>
 <ul>
+<li><bugzilla>54189</bugzilla> - Add a function to quote ORO regexp meta
characters</li>
 </ul>
 
 <h3>I18N</h3>

Modified: jmeter/trunk/xdocs/usermanual/functions.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/functions.xml?rev=1412519&r1=1412518&r2=1412519&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/functions.xml (original)
+++ jmeter/trunk/xdocs/usermanual/functions.xml Thu Nov 22 12:23:44 2012
@@ -120,6 +120,7 @@ Alternatively, just use / instead for th
         <tr><td>Variables</td><td> <a href="#__eval">eval</a></td><td>evaluate
a variable expression</td><td>2.3.1</td></tr>
         <tr><td>Variables</td><td> <a href="#__evalVar">evalVar</a></td><td>evaluate
an expression stored in a variable</td><td>2.3.1</td></tr>
         <tr><td>String</td><td> <a href="#__regexFunction">regexFunction</a></td><td>parse
previous response using a regular expression</td><td>1.X</td></tr>
+        <tr><td>String</td><td> <a href="#__escapeOroRegexpChars">escapeOroRegexpChars</a></td><td>quote
meta chars used by ORO regular expression</td><td>2.9</td></tr>
         <tr><td>String</td><td> <a href="#__char">char</a></td><td>generate
Unicode char values from a list of numbers</td><td>2.3.3</td></tr>
         <tr><td>String</td><td> <a href="#__unescape">unescape</a></td><td>Process
strings containing Java escapes (e.g. \n &amp; \t)</td><td>2.3.3</td></tr>
         <tr><td>String</td><td> <a href="#__unescapeHtml">unescapeHtml</a></td><td>Decode
HTML-encoded strings</td><td>2.3.3</td></tr>
@@ -1194,6 +1195,32 @@ A reference name - refName - for reusing
     </p>
 </description>
 </component>
+
+<component index="&sect-num;.5.29" name="__escapeHtml">
+<description>
+    <p>
+Function which escapes the ORO Regexp meta characters, it is the equivalent of \Q \E in Java
Regexp Engine.
+</p>
+<p>
+For example,<code>[^&quot;].+?</code>
+becomes:
+<code>\[\^\&quot;\]\.\+\?</code>.
+</p>
+    <p>
+    Uses Perl5Compiler#quotemeta(String) from ORO.
+    </p>
+    </description>
+
+<properties>
+        <property name="String to escape" required="Yes">
+        The string to be escaped.
+        </property>
+        <property name="Variable Name" required="No">
+A reference name - refName - for reusing the value created by this function. Stored values
are of the form ${refName}.
+        </property>
+</properties>
+</component>
+
 </subsection>
 
 <subsection name="&sect-num;.6 Pre-defined Variables" anchor="predefinedvars">



Mime
View raw message