<%
	class MethodBodyGenerator
	{
		public StringBuffer generate(ITestCase testCase)
		{
			StringBuffer sb = generateHttp(testCase);
			if(sb == null)
				sb = generateDefault();
			return sb;
		}
		
		protected StringBuffer generateHttp(ITestCase testCase)
		{
			RequestHelper requestHelper = new RequestHelper();
			requestHelper.setTestCase(testCase);
			HttpRequest request = requestHelper.createHttpRequest();
			if(request == null)
				return null;
		
			StringBuffer sb = new StringBuffer();
			
			sb.append(helper.getImportedName("org.eclipse.hyades.test.http.runner.HttpRequest")).append(" request = new ").append(helper.getImportedName("org.eclipse.hyades.test.http.runner.HttpRequest")).append("();");
			String value = null;

			value = request.getMethod();
			if(value != null)
				sb.append(NL).append("request.setMethod(\"").append(adjustString(value)).append("\");");
	
			value = request.getVersion();
			if(value != null)
				sb.append(NL).append("request.setVersion(\"").append(adjustString(value)).append("\");");

			value = request.getHost();
			if(value != null)
				sb.append(NL).append("request.setHost(\"").append(adjustString(value)).append("\");");
			
			if(request.getPort() > 0)
				sb.append(NL).append("request.setPort(").append(request.getPort()).append(");");

			value = request.getAbsolutePath();
			if(value != null)
				sb.append(NL).append("request.setAbsolutePath(\"").append(adjustString(value)).append("\");");
				
			value = request.getBody();
			if(value != null)
				sb.append(NL).append("request.setBody(\"").append(adjustString(value)).append("\");");
			
			HttpHeader[] headers = request.getHeaders();
			if(headers.length > 0)
			{
				for (int i = 0, maxi = headers.length; i < maxi; i++)
				{
					value = headers[i].getName();
					if(value == null)
						continue;
						
					sb.append(NL).append(NL);
					if(i == 0)
						sb.append(helper.getImportedName("org.eclipse.hyades.test.http.runner.HttpHeader")).append(" ");
					sb.append("header = new ").append(helper.getImportedName("org.eclipse.hyades.test.http.runner.HttpHeader")).append("();");
					
					sb.append(NL).append("header.setName(\"").append(adjustString(value)).append("\");");
					
					value = headers[i].getValue();
					if(value != null)
						sb.append(NL).append("header.setValue(\"").append(adjustString(value)).append("\");");
						
					sb.append(NL).append("request.addHeader(header);");
				}
			}
			
			sb.append(NL);
			sb.append(NL).append("executeRequest(request);");
	
			return sb;
		}

		protected StringBuffer generateDefault()
		{
			StringBuffer sb = new StringBuffer();
			sb.append("// Enter your code here");
			return sb;
		}
		
		protected String adjustString(String string)
		{
			string = StringUtil.replace(string, "\"", "\\\"");
			return string;
		}
	}
%>