jakarta-jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mstov...@apache.org
Subject cvs commit: jakarta-jmeter/src/org/apache/jmeter/save/xml TagHandler.java
Date Fri, 08 Jun 2001 17:01:30 GMT
mstover1    01/06/08 10:01:30

  Modified:    src/org/apache/jmeter/protocol/http/save
                        AuthManagerHandler.java CookieManagerHandler.java
               src/org/apache/jmeter/protocol/jdbc/save
                        JdbcTestSampleHandler.java
               src/org/apache/jmeter/save/handlers
                        AbstractConfigElementHandler.java
                        ArgumentsHandler.java GenericControllerHandler.java
                        HttpTestSampleHandler.java JMeterHandler.java
                        ThreadGroupHandler.java
               src/org/apache/jmeter/save/xml TagHandler.java
  Log:
  Can save special XML characters correctly
  
  Revision  Changes    Path
  1.3       +1 -1      jakarta-jmeter/src/org/apache/jmeter/protocol/http/save/AuthManagerHandler.java
  
  Index: AuthManagerHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/http/save/AuthManagerHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AuthManagerHandler.java	2001/03/17 22:25:52	1.2
  +++ AuthManagerHandler.java	2001/06/08 17:01:10	1.3
  @@ -83,7 +83,7 @@
   	{
   		AuthManager save = (AuthManager)s;
   		out.write("<AuthManager name=\"");
  -		out.write(save.getName());
  +		out.write(JMeterHandler.convertToXML(save.getName()));
   		out.write("\">\n");
   		JMeterHandler.writeObjects(save.getAuthObjects(),out);
   		out.write("</AuthManager>\n");
  
  
  
  1.3       +1 -1      jakarta-jmeter/src/org/apache/jmeter/protocol/http/save/CookieManagerHandler.java
  
  Index: CookieManagerHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/http/save/CookieManagerHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CookieManagerHandler.java	2001/03/17 22:25:52	1.2
  +++ CookieManagerHandler.java	2001/06/08 17:01:12	1.3
  @@ -86,7 +86,7 @@
   	{
   		CookieManager cookies = (CookieManager)cm;
   		out.write("<CookieManager name=\"");
  -		out.write(cookies.getName());
  +		out.write(JMeterHandler.convertToXML(cookies.getName()));
   		out.write("\">\n");
   		JMeterHandler.writeObjects(cookies.getCookies(),out);
   		out.write("</CookieManager>\n");
  
  
  
  1.3       +2 -2      jakarta-jmeter/src/org/apache/jmeter/protocol/jdbc/save/JdbcTestSampleHandler.java
  
  Index: JdbcTestSampleHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/jdbc/save/JdbcTestSampleHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JdbcTestSampleHandler.java	2001/03/17 22:25:53	1.2
  +++ JdbcTestSampleHandler.java	2001/06/08 17:01:17	1.3
  @@ -142,9 +142,9 @@
   	protected void writeMainTag(Writer out, GenericController controller) throws java.io.IOException
   	{
   		out.write("<JdbcTestSample type=\"");
  -		out.write(controller.getClass().getName());
  +		out.write(JMeterHandler.convertToXML(controller.getClass().getName()));
   		out.write("\" name=\"");
  -		out.write(controller.getName());
  +		out.write(JMeterHandler.convertToXML(controller.getName()));
   		out.write("\">\n");
   	}
   
  
  
  
  1.6       +2 -2      jakarta-jmeter/src/org/apache/jmeter/save/handlers/AbstractConfigElementHandler.java
  
  Index: AbstractConfigElementHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/save/handlers/AbstractConfigElementHandler.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractConfigElementHandler.java	2001/04/10 17:31:00	1.5
  +++ AbstractConfigElementHandler.java	2001/06/08 17:01:19	1.6
  @@ -153,7 +153,7 @@
   	{
   		AbstractConfigElement saved = (AbstractConfigElement)obj;
   		out.write("<ConfigElement type=\"");
  -		out.write(saved.getClass().getName());
  +		out.write(JMeterHandler.convertToXML(saved.getClass().getName()));
   		out.write("\">\n");
   		Iterator iter = saved.getPropertyNames().iterator();
   		while (iter.hasNext())
  @@ -171,7 +171,7 @@
   	private void writeProperty(Writer out,String key,Object value) throws IOException
   	{
   		out.write("<property name=\"");
  -		out.write(key);
  +		out.write(JMeterHandler.convertToXML(key));
   		out.write("\">");
   		JMeterHandler.writeObject(value,out);
   		out.write("</property>\n");
  
  
  
  1.5       +2 -2      jakarta-jmeter/src/org/apache/jmeter/save/handlers/ArgumentsHandler.java
  
  Index: ArgumentsHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/save/handlers/ArgumentsHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ArgumentsHandler.java	2001/04/10 17:31:00	1.4
  +++ ArgumentsHandler.java	2001/06/08 17:01:20	1.5
  @@ -95,11 +95,11 @@
   	private void writeArgument(Argument arg,Writer out) throws IOException
   	{
   		out.write("<argument name=\"");
  -		out.write(arg.getName());
  +		out.write(JMeterHandler.convertToXML(arg.getName()));
   		out.write("\">");
   		try
   		{
  -			out.write(arg.getValue().toString());
  +			out.write(JMeterHandler.convertToXML(arg.getValue().toString()));
   		}
   		catch (Exception ex)
   		{
  
  
  
  1.5       +2 -2      jakarta-jmeter/src/org/apache/jmeter/save/handlers/GenericControllerHandler.java
  
  Index: GenericControllerHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/save/handlers/GenericControllerHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- GenericControllerHandler.java	2001/03/17 22:25:56	1.4
  +++ GenericControllerHandler.java	2001/06/08 17:01:20	1.5
  @@ -146,9 +146,9 @@
   	protected void writeMainTag(Writer out, GenericController controller) throws java.io.IOException
   	{
   		out.write("<Controller type=\"");
  -		out.write(controller.getClass().getName());
  +		out.write(JMeterHandler.convertToXML(controller.getClass().getName()));
   		out.write("\" name=\"");
  -		out.write(controller.getName());
  +		out.write(JMeterHandler.convertToXML(controller.getName()));
   		out.write("\">\n");
   	}
   }
  
  
  
  1.4       +2 -2      jakarta-jmeter/src/org/apache/jmeter/save/handlers/HttpTestSampleHandler.java
  
  Index: HttpTestSampleHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/save/handlers/HttpTestSampleHandler.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HttpTestSampleHandler.java	2001/03/17 22:25:56	1.3
  +++ HttpTestSampleHandler.java	2001/06/08 17:01:21	1.4
  @@ -133,9 +133,9 @@
   	protected void writeMainTag(Writer out, GenericController controller) throws java.io.IOException
   	{
   		out.write("<HttpTestSample type=\"");
  -		out.write(controller.getClass().getName());
  +		out.write(JMeterHandler.convertToXML(controller.getClass().getName()));
   		out.write("\" name=\"");
  -		out.write(controller.getName());
  +		out.write(JMeterHandler.convertToXML(controller.getName()));
   		out.write("\">\n");
   	}
   
  
  
  
  1.4       +147 -23   jakarta-jmeter/src/org/apache/jmeter/save/handlers/JMeterHandler.java
  
  Index: JMeterHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/save/handlers/JMeterHandler.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JMeterHandler.java	2001/03/24 14:39:59	1.3
  +++ JMeterHandler.java	2001/06/08 17:01:22	1.4
  @@ -52,7 +52,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  - package org.apache.jmeter.save.handlers;
  +package org.apache.jmeter.save.handlers;
   
   import java.io.*;
   import java.util.*;
  @@ -60,59 +60,103 @@
   import org.apache.jmeter.save.*;
   
   
  -
   /**
  - * Title:
  - * Description:
  - * Copyright:    Copyright (c) 2001
  - * Company:
  - * @author Michael Stover
  - * @version 1.0
  + *  Title: Description: Copyright: Copyright (c) 2001 Company:
  + *
  + *@author     Michael Stover
  + *@created    June 8, 2001
  + *@version    1.0
    */
   
   public class JMeterHandler
   {
  +	private static String TOKENS = "&'\"<>\n\r\t\f\b\\";
   
  +	/**
  +	 *  Constructor for the JMeterHandler object
  +	 */
   	public JMeterHandler()
   	{
   	}
   
  -	public static void writeConfigElements(Collection configs,Writer out) throws IOException
  +	/**
  +	 *  Description of the Method
  +	 *
  +	 *@param  configs          Description of Parameter
  +	 *@param  out              Description of Parameter
  +	 *@exception  IOException  Description of Exception
  +	 */
  +	public static void writeConfigElements(Collection configs, Writer out) throws IOException
   	{
   		out.write("<configElements>\n");
  -		writeObjects(configs,out);
  +		writeObjects(configs, out);
   		out.write("</configElements>\n");
   	}
   
  -	public static void writeControllers(Collection controls,Writer out) throws IOException
  +	/**
  +	 *  Description of the Method
  +	 *
  +	 *@param  controls         Description of Parameter
  +	 *@param  out              Description of Parameter
  +	 *@exception  IOException  Description of Exception
  +	 */
  +	public static void writeControllers(Collection controls, Writer out) throws IOException
   	{
   		out.write("<controllers>\n");
  -		writeObjects(controls,out);
  +		writeObjects(controls, out);
   		out.write("</controllers>\n");
   	}
   
  -	public static void writeThreadGroups(Collection groups,Writer out) throws IOException
  +	/**
  +	 *  Description of the Method
  +	 *
  +	 *@param  groups           Description of Parameter
  +	 *@param  out              Description of Parameter
  +	 *@exception  IOException  Description of Exception
  +	 */
  +	public static void writeThreadGroups(Collection groups, Writer out) throws IOException
   	{
   		out.write("<threadgroups>\n");
  -		writeObjects(groups,out);
  +		writeObjects(groups, out);
   		out.write("</threadgroups>\n");
   	}
   
  -	public static void writeListeners(Collection listeners,Writer out) throws IOException
  +	/**
  +	 *  Description of the Method
  +	 *
  +	 *@param  listeners        Description of Parameter
  +	 *@param  out              Description of Parameter
  +	 *@exception  IOException  Description of Exception
  +	 */
  +	public static void writeListeners(Collection listeners, Writer out) throws IOException
   	{
   		out.write("<listeners>\n");
  -		writeObjects(listeners,out);
  +		writeObjects(listeners, out);
   		out.write("</listeners>\n");
   	}
   
  -	public static void writeTimers(Collection timers,Writer out) throws IOException
  +	/**
  +	 *  Description of the Method
  +	 *
  +	 *@param  timers           Description of Parameter
  +	 *@param  out              Description of Parameter
  +	 *@exception  IOException  Description of Exception
  +	 */
  +	public static void writeTimers(Collection timers, Writer out) throws IOException
   	{
   		out.write("<timers>\n");
  -		writeObjects(timers,out);
  +		writeObjects(timers, out);
   		out.write("</timers>\n");
   	}
   
  -	public static void writeObjects(Collection objects,Writer out) throws IOException
  +	/**
  +	 *  Description of the Method
  +	 *
  +	 *@param  objects          Description of Parameter
  +	 *@param  out              Description of Parameter
  +	 *@exception  IOException  Description of Exception
  +	 */
  +	public static void writeObjects(Collection objects, Writer out) throws IOException
   	{
   		Iterator iter = objects.iterator();
   		while (iter.hasNext())
  @@ -122,6 +166,13 @@
   		}
   	}
   
  +	/**
  +	 *  Description of the Method
  +	 *
  +	 *@param  obj              Description of Parameter
  +	 *@param  out              Description of Parameter
  +	 *@exception  IOException  Description of Exception
  +	 */
   	public static void writeObject(Object obj, Writer out) throws IOException
   	{
   		if (obj instanceof Saveable)
  @@ -136,12 +187,85 @@
   				ex.printStackTrace();
   			}
   		}
  -
   		else
   		{
  -			out.write(obj.toString());
  +			out.write(convertToXML(obj.toString()));
   		}
   	}
  -
   
  -}
  \ No newline at end of file
  +	/**
  +	 *  Description of the Method
  +	 *
  +	 *@param  input  Description of Parameter
  +	 *@return        Description of the Returned Value
  +	 */
  +	public static String convertToXML(String input)
  +	{
  +		if (input == null)
  +		{
  +			return null;
  +		}
  +		String retVal = "";
  +		StringBuffer buffer = new StringBuffer(input);
  +		int length = buffer.length();
  +		for (int i = 0; i < length; i++)
  +		{
  +			char ch = buffer.charAt(i);
  +			int chInt = (int) ch;
  +			if (Character.isLetterOrDigit(ch) || ch == '\n' || ch == '\r' || ch == '\t' || ch ==
' ')
  +			{
  +				continue;
  +			}
  +			int chType = Character.getType(ch);
  +			if (chType == Character.CONTROL || chType == Character.UNASSIGNED)
  +			{
  +				buffer.setCharAt(i, ' ');
  +			}
  +		}
  +		input = buffer.toString();
  +		buffer = new StringBuffer();
  +		java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(input, TOKENS, true);
  +		while (tokenizer.hasMoreTokens())
  +		{
  +			String nextToken = tokenizer.nextToken();
  +			length = nextToken.length();
  +			if (length > 1)
  +			{
  +				buffer.append(nextToken);
  +			}
  +			else if (length == 1)
  +			{
  +				char ch = nextToken.charAt(0);
  +				switch (ch)
  +				{
  +					case '&':
  +						buffer.append("&amp;");
  +						break;
  +					case '\'':
  +						buffer.append("&apos;");
  +						break;
  +					case '"':
  +						buffer.append("&quot;");
  +						break;
  +					case '<':
  +						buffer.append("&lt;");
  +						break;
  +					case '>':
  +						buffer.append("&gt;");
  +						break;
  +					case '\n':
  +					case '\r':
  +					case '\t':
  +					case '\f':
  +					case '\b':
  +					case '\\':
  +						buffer.append("&#");buffer.append((int)ch);buffer.append(";");
  +						break;
  +					default:
  +						buffer.append(nextToken);
  +				}
  +			}
  +		}
  +		return buffer.toString();
  +	}
  +}
  
  
  
  1.3       +1 -1      jakarta-jmeter/src/org/apache/jmeter/save/handlers/ThreadGroupHandler.java
  
  Index: ThreadGroupHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/save/handlers/ThreadGroupHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ThreadGroupHandler.java	2001/03/17 22:25:56	1.2
  +++ ThreadGroupHandler.java	2001/06/08 17:01:22	1.3
  @@ -85,7 +85,7 @@
   	{
   		ThreadGroup save = (ThreadGroup)s;
   		out.write("<ThreadGroup name=\"");
  -		out.write(save.getName());
  +		out.write(JMeterHandler.convertToXML(save.getName()));
   		out.write("\" numThreads=\"");
   		out.write(""+save.getNumThreads());
   		out.write("\">\n");
  
  
  
  1.4       +30 -13    jakarta-jmeter/src/org/apache/jmeter/save/xml/TagHandler.java
  
  Index: TagHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/save/xml/TagHandler.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TagHandler.java	2001/03/17 22:25:56	1.3
  +++ TagHandler.java	2001/06/08 17:01:28	1.4
  @@ -78,7 +78,9 @@
   	protected String tagName;
   	protected XmlHandler xmlParent;
   
  +	private StringBuffer dataStore;
   
  +
   	public abstract void setAtts(Attributes atts) throws Exception;
   
   	public void setXmlParent(XmlHandler xml)
  @@ -195,29 +197,43 @@
   
   	protected void callTagCombo(String data)
   	{
  -		try
  +		if(dataStore == null)
  +		{
  +			dataStore = new StringBuffer();
  +		}
  +		dataStore.append(data);
  +	}
  +
  +	private void releaseData()
  +	{
  +		if(dataStore != null)
   		{
  -			if(getMethodName().equals(""))
  +			try
   			{
  -				setData(data);
  +				if(getMethodName().equals(""))
  +				{
  +					setData(dataStore.toString());
  +				}
  +				else
  +				{
  +					Method method = this.getClass().getMethod(getMethodName(), new Class[]{String.class});
  +					method.invoke(this, new Object[]{dataStore.toString()});
  +				}
   			}
  -			else
  +			catch(NoSuchMethodException e)
   			{
  -				Method method = this.getClass().getMethod(getMethodName(), new Class[]{String.class});
  -				method.invoke(this, new Object[]{data});
   			}
  -		}
  -		catch(NoSuchMethodException e)
  -		{
  -		}
  -		catch (Exception ex)
  -		{
  -			ex.printStackTrace();
  +			catch (Exception ex)
  +			{
  +				ex.printStackTrace();
  +			}
   		}
  +		dataStore = null;
   	}
   
   	protected void passToHandler(String localName, Attributes atts)
   	{
  +		releaseData();
   		try
   		{
   			Class handler = this.getClass();
  @@ -242,6 +258,7 @@
   
   	protected void passToHandler(String localName)
   	{
  +		releaseData();
   		try
   		{
   			Class handler = this.getClass();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org


Mime
View raw message