*/
public SampleResult sample(Entry e)
{
catClass.debug("Start : sample2");
long totalTime = (long)0;
SampleResult res = super.sample(e);
String displayName = (String)res.getValue(SampleResult.SAMPLE_LABEL);
res.putValue(SampleResult.DISPLAY_NAME, displayName);
List loadBinaryList = new ArrayList();
if (catClass.isDebugEnabled())
{
catClass.debug("sample2 : main page loading time - " + res.getTime());
}
totalTime += res.getTime();
Document html = null;
try
{
baseUrl = new URL((String)res.getValue(SampleResult.SAMPLE_LABEL));
if (catClass.isDebugEnabled())
{
catClass.debug("sample2 : baseUrl - " + baseUrl.toString());
}
// now use parser to look for image tags
html = (Document)getDOM(new String((byte[])res.getValue(SampleResult.TEXT_RESPONSE)));
}
catch(SAXException exception)
{
catClass.error("sample2 : Error parsing document - " + exception);
catClass.error("sample2 : Setting SampleResult SUCCESS value to false");
res.putValue(SampleResult.TEXT_RESPONSE, exception.toString().getBytes());
res.putValue(RESPONSE_CODE, NON_HTTP_RESPONSE_CODE);
res.putValue(RESPONSE_MESSAGE, NON_HTTP_RESPONSE_MESSAGE);
res.putValue(SampleResult.SUCCESS, new Boolean(false));
}
catch(MalformedURLException exception)
{
catClass.error("sample2 : Error creating URL - " + exception);
catClass.error("sample2 : Setting SampleResult SUCCESS value to false");
res.putValue(SampleResult.TEXT_RESPONSE, exception.toString().getBytes());
res.putValue(RESPONSE_CODE, NON_HTTP_RESPONSE_CODE);
res.putValue(RESPONSE_MESSAGE, NON_HTTP_RESPONSE_MESSAGE);
res.putValue(SampleResult.SUCCESS, new Boolean(false));
}
// sample result to store image from <img...> tags
SampleResult imgRes = null;
NodeList nodeList = html.getElementsByTagName("img");
for(int i = 0; i < nodeList.getLength(); i++)
{
imgRes = new SampleResult();
try
{
Node tempNode = nodeList.item(i);
if(catClass.isDebugEnabled())
{
catClass.debug("sample2 : Image tags - " + tempNode);
}
// get the url of those images
NamedNodeMap nnm = tempNode.getAttributes();
Node namedItem = nnm.getNamedItem("src");
String imgUrlStr = namedItem.getNodeValue();
// set the baseUrl and imgUrl so that if error occurs
// due to MalformedException then at least the values will be
// visible to the user to aid correction
imgRes.putValue(SampleResult.DISPLAY_NAME, baseUrl + "," + imgUrlStr);
// download those images
URL imgUrl = new URL(baseUrl, imgUrlStr);
if (catClass.isDebugEnabled())
{
catClass.debug("sample2 : Image url without baseUrl - " + imgUrlStr);
catClass.debug("sample2 : Image url with baseUrl - " + imgUrl);
}
imgRes.putValue(SampleResult.DISPLAY_NAME, imgUrl.toString());
loadBinary(imgUrl, e, imgRes);
ImageIcon image = new ImageIcon(imgUrl, imgUrl.toString());
imgRes.putValue(IMAGE, image);
totalTime += imgRes.getTime();
imgRes.remove(SampleResult.TEXT_RESPONSE);
}
catch(IOException exception)
{
catClass.error("sample2 : Error reading from URL - " + exception);
catClass.error("sample2 : Setting SampleResult SUCCESS value to false");
imgRes.putValue(SampleResult.TEXT_RESPONSE, exception.toString().getBytes());
imgRes.putValue(RESPONSE_CODE, NON_HTTP_RESPONSE_CODE);
imgRes.putValue(RESPONSE_MESSAGE, NON_HTTP_RESPONSE_MESSAGE);
imgRes.putValue(SampleResult.SUCCESS, new Boolean(false));
}
loadBinaryList.add(imgRes);
}
SampleResult appRes = null;
// use parser to look for applet tags
nodeList = html.getElementsByTagName("applet");
for(int i = 0; i < nodeList.getLength(); i++)
{
appRes = new SampleResult();
try
{
Node tempNode = nodeList.item(i);
if(catClass.isDebugEnabled())
{
catClass.debug("sample2 : Applet tags - " + tempNode);
}
// get the url of those applets
NamedNodeMap nnm = tempNode.getAttributes();
Node namedItem = nnm.getNamedItem("code");
String appletUrlStr = namedItem.getNodeValue() + ".class";
// set the baseUrl and imgUrl so that if error occurs
// due to MalformedException then at least the values will be
// visible to the user to aid correction
appRes.putValue(SampleResult.DISPLAY_NAME, baseUrl + "," + appletUrlStr);
// download those applet
URL appletUrl = new URL(baseUrl, appletUrlStr);
if(catClass.isDebugEnabled())
{
catClass.debug("sample2 : Applet url without baseUrl - " + appletUrlStr);
catClass.debug("sample2 : Applet url with baseUrl - " + appletUrl);
}
appRes.putValue(SampleResult.DISPLAY_NAME, appletUrl.toString());
appRes.putValue(SampleResult.TEXT_RESPONSE, loadBinary(appletUrl, e, appRes));
totalTime += appRes.getTime();
}
catch(IOException exception)
{
catClass.error("sample2 : Error reading from URL - " + exception);
catClass.error("sample2 : Setting SampleResult SUCCESS value to false");
appRes.putValue(SampleResult.TEXT_RESPONSE, exception.toString().getBytes());
appRes.putValue(RESPONSE_CODE, NON_HTTP_RESPONSE_CODE);
appRes.putValue(RESPONSE_MESSAGE, NON_HTTP_RESPONSE_MESSAGE);
appRes.putValue(SampleResult.SUCCESS, new Boolean(false));
}
loadBinaryList.add(appRes);
}
// use parser to look for input tags with image types as well
nodeList = html.getElementsByTagName("input");
for(int i = 0; i < nodeList.getLength(); i++)
{
try
{
Node tempNode = nodeList.item(i);
if(catClass.isDebugEnabled())
{
catClass.debug("sample2 : Input tags - " + tempNode);
}
// get the url of those images
NamedNodeMap nnm = tempNode.getAttributes();
Node namedItem = nnm.getNamedItem("type");
if(namedItem != null)
{
String inputType = namedItem.getNodeValue();
if(catClass.isDebugEnabled())
{
catClass.debug("sample2 : Input type - " +
inputType);
}
if(inputType != null &&
inputType.equalsIgnoreCase("image"))
{
imgRes = new SampleResult();
namedItem = nnm.getNamedItem("src");
String imgUrlStr = namedItem.getNodeValue();
// set the baseUrl and imgUrl so that if error occurs
// due to MalformedException then at least the values