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/19 04:46:41 UTC
svn commit: r678092 - in /jakarta/jmeter/trunk:
src/core/org/apache/jmeter/resources/
src/functions/org/apache/jmeter/functions/ xdocs/ xdocs/usermanual/
Author: sebb
Date: Fri Jul 18 19:46:41 2008
New Revision: 678092
URL: http://svn.apache.org/viewvc?rev=678092&view=rev
Log:
Added (un)escapeHtml functions
Added:
jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/EscapeHtml.java (with props)
jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/UnEscapeHtml.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=678092&r1=678091&r2=678092&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 19:46:41 2008
@@ -194,6 +194,7 @@
error_occurred=Error Occurred
error_title=Error
es=Spanish
+escape_html_string=String to escape
eval_name_param=Text containing variable and function references
evalvar_name_param=Name of variable
example_data=Sample Data
@@ -808,6 +809,7 @@
transaction_controller_title=Transaction Controller
unbind=Thread Unbind
unescape_string=String containing Java escapes
+unescape_html_string=String to unescape
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/EscapeHtml.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/EscapeHtml.java?rev=678092&view=auto
==============================================================================
--- jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/EscapeHtml.java (added)
+++ jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/EscapeHtml.java Fri Jul 18 19:46:41 2008
@@ -0,0 +1,89 @@
+/*
+ * 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;
+
+/**
+ * <p>Function which escapes the characters in a <code>String</code> using HTML entities.</p>
+ *
+ * <p>
+ * For example:
+ * </p>
+ * <p><code>"bread" & "butter"</code></p>
+ * becomes:
+ * <p>
+ * <code>&quot;bread&quot; &amp; &quot;butter&quot;</code>.
+ * </p>
+ *
+ * <p>Supports all known HTML 4.0 entities.
+ * Note that the commonly used apostrophe escape character (&apos;)
+ * is not a legal entity and so is not supported). </p>
+ *
+ * @see StringEscapeUtils#escapeHtml(String) (Commons Lang)
+ */
+public class EscapeHtml extends AbstractFunction implements Serializable {
+
+ private static final List desc = new LinkedList();
+
+ private static final String KEY = "__escapeHtml"; //$NON-NLS-1$
+
+ static {
+ desc.add(JMeterUtils.getResString("escape_html_string")); //$NON-NLS-1$
+ }
+
+ private Object[] values;
+
+ public EscapeHtml() {
+ }
+
+ 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.escapeHtml(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/EscapeHtml.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/EscapeHtml.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/UnEscapeHtml.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/UnEscapeHtml.java?rev=678092&view=auto
==============================================================================
--- jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/UnEscapeHtml.java (added)
+++ jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/UnEscapeHtml.java Fri Jul 18 19:46:41 2008
@@ -0,0 +1,80 @@
+/*
+ * 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 unescape a string containing entity escapes
+ * to a string containing the actual Unicode characters corresponding to the escapes.
+ * Supports HTML 4.0 entities.
+ * For example, the string "<Français>" will become "<Français>"
+ * If an entity is unrecognized, it is left alone, and inserted verbatim into the result string.
+ * e.g. ">&zzzz;x" will become ">&zzzz;x".
+ * @see StringEscapeUtils#unescapeHtml(String) (Commons Lang)
+ */
+public class UnEscapeHtml extends AbstractFunction implements Serializable {
+
+ private static final List desc = new LinkedList();
+
+ private static final String KEY = "__unescapeHtml"; //$NON-NLS-1$
+
+ static {
+ desc.add(JMeterUtils.getResString("unescape_html_string")); //$NON-NLS-1$
+ }
+
+ private Object[] values;
+
+ public UnEscapeHtml() {
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
+ throws InvalidVariableException {
+
+ String escapedString = ((CompoundVariable) values[0]).execute();
+ return StringEscapeUtils.unescapeHtml(escapedString);
+
+ }
+
+ 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/UnEscapeHtml.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/UnEscapeHtml.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=678092&r1=678091&r2=678092&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Fri Jul 18 19:46:41 2008
@@ -42,16 +42,16 @@
</p>
<h4>Improvements</h4>
+
<p>
<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>
-<ul>
-Add Body (unescaped) source option to Regular Expression Extractor.
+<li>Added __char() function: allows arbitrary Unicode characters to be entered in fields.</li>
+<li>Added __unescape() function: allows Java-escaped strings to be used.</li>
+<li>Add Body (unescaped) source option to Regular Expression Extractor.</li>
+<li>Added __unescapeHtml() function: decodes Html-encoded text.</li>
+<li>Added __escapeHtml() function: encodes text using Html-encoding.</li>
</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=678092&r1=678091&r2=678092&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/functions.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/functions.xml Fri Jul 18 19:46:41 2008
@@ -99,7 +99,6 @@
<tr><td>Calculation</td><td> <a href="#__intSum">intSum</a></td><td>add int numbers</td></tr>
<tr><td>Calculation</td><td> <a href="#__longSum">longSum</a></td><td>add long numbers</td></tr>
<tr><td>Calculation</td><td> <a href="#__Random">Random</a></td><td>generate a random number</td></tr>
- <tr><td>Calculation</td><td> <a href="#__regexFunction">regexFunction</a></td><td>parse previous response using a regular expression</td></tr>
<tr><td>Scripting</td><td> <a href="#__BeanShell">BeanShell</a></td><td>run a BeanShell script</td></tr>
<tr><td>Scripting</td><td> <a href="#__javaScript">javaScript</a></td><td>process JavaScript (Mozilla Rhino)</td></tr>
<tr><td>Scripting</td><td> <a href="#__jexl">jexl</a></td><td>evaluate a Commons Jexl expression</td></tr>
@@ -110,8 +109,11 @@
<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>String</td><td> <a href="#__regexFunction">regexFunction</a></td><td>parse previous response using a regular expression</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>
+ <tr><td>String</td><td> <a href="#__unescape">unescape</a></td><td>Process strings containing Java escapes (e.g. \n & \t)</td></tr>
+ <tr><td>String</td><td> <a href="#__unescapeHtml">unescapeHtml</a></td><td>Decode HTML-encoded strings</td></tr>
+ <tr><td>String</td><td> <a href="#__escapeHtml">escapeHtml</a></td><td>Encode strings using HTML encoding</td></tr>
</table>
<p></p>
<subsection name="§-num;.1 What can functions do" anchor="what_can_do">
@@ -1004,6 +1006,56 @@
</p>
</component>
+<component index="§-num;.5.24" name="__unescapeHtml">
+<description>
+ <p>
+Function to unescape a string containing HTML entity escapes
+to a string containing the actual Unicode characters corresponding to the escapes.
+Supports HTML 4.0 entities.
+</p>
+<p>
+For example, the string <code>"&#38;lt;Fran&#38;ccedil;ais&#38;gt;"</code>
+will become <code>"&lt;Fran&ccedil;ais&gt;"</code>.
+</p>
+<p>
+If an entity is unrecognized, it is left alone, and inserted verbatim into the result string.
+e.g. <code>"&gt;&zzzz;x"</code> will become <code>">&zzzz;x"</code>.
+</p>
+ <p>
+ Uses StringEscapeUtils#unescapeHtml(String) from Commons Lang.
+ </p>
+ </description>
+
+<properties>
+ <property name="String to unescape" required="Yes">
+ The string to be unescaped.
+ </property>
+</properties>
+</component>
+
+<component index="§-num;.5.25" name="__escapeHtml">
+<description>
+ <p>
+Function which escapes the characters in a String using HTML entities.
+Supports HTML 4.0 entities.
+</p>
+<p>
+For example,<code>&quot;bread&quot; &amp; &quot;butter&quot;</code>
+becomes:
+<code>&#38;quot;bread&#38;quot; &#38;amp; &#38;quot;butter&#38;quot;</code>.
+</p>
+ <p>
+ Uses StringEscapeUtils#escapeHtml(String) from Commons Lang.
+ </p>
+ </description>
+
+<properties>
+ <property name="String to escape" required="Yes">
+ The string to be escaped.
+ </property>
+</properties>
+</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