You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2008/07/18 17:19:10 UTC
svn commit: r677934 - in /jakarta/jmeter/trunk:
src/core/org/apache/jmeter/resources/messages.properties
src/functions/org/apache/jmeter/functions/UnEscape.java xdocs/changes.xml
xdocs/usermanual/functions.xml
Author: sebb
Date: Fri Jul 18 08:19:10 2008
New Revision: 677934
URL: http://svn.apache.org/viewvc?rev=677934&view=rev
Log:
Add _unescape() function
Added:
jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/UnEscape.java (with props)
Modified:
jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
jakarta/jmeter/trunk/xdocs/changes.xml
jakarta/jmeter/trunk/xdocs/usermanual/functions.xml
Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=677934&r1=677933&r2=677934&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Fri Jul 18 08:19:10 2008
@@ -806,6 +806,7 @@
transaction_controller_parent=Generate parent sample
transaction_controller_title=Transaction Controller
unbind=Thread Unbind
+unescape_string=String containing Java escapes
uniform_timer_delay=Constant Delay Offset (in milliseconds)\:
uniform_timer_memo=Adds a random delay with a uniform distribution
uniform_timer_range=Random Delay Maximum (in milliseconds)\:
Added: jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/UnEscape.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/UnEscape.java?rev=677934&view=auto
==============================================================================
--- jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/UnEscape.java (added)
+++ jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/UnEscape.java Fri Jul 18 08:19:10 2008
@@ -0,0 +1,74 @@
+/*
+ * 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.io.Serializable;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.jmeter.engine.util.CompoundVariable;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.samplers.Sampler;
+import org.apache.jmeter.util.JMeterUtils;
+
+/**
+ * Function to generate chars from a list of decimal or hex values
+ */
+public class UnEscape extends AbstractFunction implements Serializable {
+
+ private static final List desc = new LinkedList();
+
+ private static final String KEY = "__unescape"; //$NON-NLS-1$
+
+ static {
+ desc.add(JMeterUtils.getResString("unescape_string")); //$NON-NLS-1$
+ }
+
+ private Object[] values;
+
+ public UnEscape() {
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
+ throws InvalidVariableException {
+
+ String rawString = ((CompoundVariable) values[0]).execute();
+ return StringEscapeUtils.unescapeJava(rawString);
+
+ }
+
+ public synchronized void setParameters(Collection parameters) throws InvalidVariableException {
+ checkParameterCount(parameters, 1);
+ values = parameters.toArray();
+ }
+
+ public String getReferenceKey() {
+ return KEY;
+ }
+
+ public List getArgumentDesc() {
+ return desc;
+ }
+}
Propchange: jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/UnEscape.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/UnEscape.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=677934&r1=677933&r2=677934&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Fri Jul 18 08:19:10 2008
@@ -46,6 +46,9 @@
<ul>
Added __char() function: allows arbitrary Unicode characters to be entered in fields.
</ul>
+<ul>
+Added __unescape() function: allows Java-escaped strings to be used.
+</ul>
</p>
<!-- ========================= End of summary ===================================== -->
Modified: jakarta/jmeter/trunk/xdocs/usermanual/functions.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/functions.xml?rev=677934&r1=677933&r2=677934&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/functions.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/functions.xml Fri Jul 18 08:19:10 2008
@@ -110,7 +110,8 @@
<tr><td>Variables</td><td> <a href="#__V">V</a></td><td>evaluate a variable name</td></tr>
<tr><td>Variables</td><td> <a href="#__eval">eval</a></td><td>evaluate a variable expression</td></tr>
<tr><td>Variables</td><td> <a href="#__evalVar">evalVar</a></td><td>evaluate an expression stored in a variable</td></tr>
- <tr><td>Other</td><td> <a href="#__char">char</a></td><td>generate Unicode char values from a list of numbers</td></tr>
+ <tr><td>String</td><td> <a href="#__char">char</a></td><td>generate Unicode char values from a list of numbers</td></tr>
+ <tr><td>String</td><td> <a href="#__unescape">unescape</a></td><td>Process strings containing Java escapes (e.g. \n & \t)</td></tr>
</table>
<p></p>
<subsection name="§-num;.1 What can functions do" anchor="what_can_do">
@@ -958,10 +959,12 @@
<component index="§-num;.5.22" name="__char">
<description>
- <p>The char function returns the result of evaluating a list of numbers as Unicode characters.
+ <p>
+ The char function returns the result of evaluating a list of numbers as Unicode characters.
+ See also __unescape(), below.
</p>
<p>
- This allows one to add any character values into fields.
+ This allows one to add arbitrary character values into fields.
</p>
</description>
@@ -972,12 +975,35 @@
</properties>
<p>Examples:
<br/>
-${__char(0xC,0xA)} = CRLF;
+${__char(0xC,0xA)} = CRLF
<br/>
${__char(165)} = ¥ (yen)
</p>
</component>
+<component index="§-num;.5.23" name="__unescape">
+<description>
+ <p>
+ The unescape function returns the result of evaluating a Java-escaped string. See also __char() above.
+ </p>
+ <p>
+ This allows one to add characters to fields which are otherwise tricky (or impossible) to define via the GUI.
+ </p>
+ </description>
+
+<properties>
+ <property name="String to unescape" required="Yes">
+ The string to be unescaped.
+ </property>
+</properties>
+<p>Examples:
+<br/>
+${__unescape(\r\n)} = CRLF
+<br/>
+${__unescape(1\t2)} = 1[tab]2
+ </p>
+</component>
+
</subsection>
<subsection name="§-num;.6 Pre-defined Variables" anchor="predefinedvars">
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org