jmeter-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 60883] New: Add ${__escapeXml()} function
Date Fri, 17 Mar 2017 15:39:30 GMT
https://bz.apache.org/bugzilla/show_bug.cgi?id=60883

            Bug ID: 60883
           Summary: Add ${__escapeXml()} function
           Product: JMeter
           Version: 3.1
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Main
          Assignee: issues@jmeter.apache.org
          Reporter: 1983-01-06@gmx.net
  Target Milestone: ---

Add a counterpart for __escapeHtml for XML too: __escapeXml

Simple impl based off __escapeHtml:

> import java.util.Collection;
> import java.util.LinkedList;
> import java.util.List;
> 
> import org.apache.commons.lang3.StringEscapeUtils;
> import org.apache.jmeter.engine.util.CompoundVariable;
> import org.apache.jmeter.functions.AbstractFunction;
> import org.apache.jmeter.functions.InvalidVariableException;
> import org.apache.jmeter.samplers.SampleResult;
> import org.apache.jmeter.samplers.Sampler;
> 
> public class EscapeXml extends AbstractFunction {
> 
> 	private static final List<String> desc = new LinkedList<String>();
> 
> 	private static final String KEY = "__escapeXml"; //$NON-NLS-1$
> 
> 	static {
> 		desc.add("Escape XML string"); //$NON-NLS-1$
> 	}
> 
> 	private Object[] values;
> 
> 	public EscapeXml() {
> 	}
> 
> 	/** {@inheritDoc} */
> 	@Override
> 	public String execute(SampleResult previousResult, Sampler currentSampler)
> 			throws InvalidVariableException {
> 
> 		String rawString = ((CompoundVariable) values[0]).execute();
> 		return StringEscapeUtils.escapeXml10(rawString);
> 
> 	}
> 
> 	/** {@inheritDoc} */
> 	@Override
> 	public void setParameters(Collection<CompoundVariable> parameters)
> 			throws InvalidVariableException {
> 		checkParameterCount(parameters, 1);
> 		values = parameters.toArray();
> 	}
> 
> 	/** {@inheritDoc} */
> 	@Override
> 	public String getReferenceKey() {
> 		return KEY;
> 	}
> 
> 	/** {@inheritDoc} */
> 	public List<String> getArgumentDesc() {
> 		return desc;
> 	}
> }

-- 
You are receiving this mail because:
You are the assignee for the bug.
Mime
View raw message