<%
  // This sample is provided under the terms of the BrowserHawk End User
  // License Agreement. Copyright (c) 2007 cyScape, Inc. All rights reserved.
  //
  // This example demonstrates Rules Enforcement Technology (RET), where.
  // an XML file describes tests to perform and what actions to take with
  // different results.
  //
  // This example shows how instead of call in getHtmlResult() you can call
  // getResult() and manually interact with the results before, at your
  // option, sending the HTML table or redirect command.
%>

<%@ page import = "com.cyscape.browserhawk.*" %>

<%
  // To avoid an exception, we first check that the system executing this
  // example has an Enterprise Edition license as required for this test.
  // Note: This is NOT needed in your pages, only for this sample.
  boolean isEnterprise = (BrowserHawk.getVersion().indexOf("Ent") != -1);
  if (!isEnterprise) {
    out.println("Enterprise License Required.  ");
    out.println("You are using " + BrowserHawk.getVersion() + ".  ");
    out.println("See <a href='http://www.cyscape.com/order/'>http://www.cyscape.com/order/</a> for upgrade information.");
    return;
  }

  RuleEngine engine = RuleEngine.getFromFile("rules-manual.xml");

  ExtendedOptions options = engine.getExtendedOptions();
  options.setPageTitle("Please wait...");
  options.setPageMessage("Checking your system. Please wait...");
  options.setBodyTag("BGCOLOR=#FFFFFF");

  ExtendedBrowserInfo extBrowser =
    BrowserHawk.getExtendedBrowserInfo(request, response, options);

  // If the return value is null, we must end the current request here.  The
  // browser will now process the client side tests and call this page back a
  // second time, and this time the return value will not be null.
  if (extBrowser == null) return;
%>

<html>
<head>
	<title>BrowserHawk Sample - Performing a Rules Test (Java)</title>
  <link href="rules.css" rel="stylesheet" type="text/css" />
</head>
<body><font face="arial">
<blockquote>
<h2>Performing a Rules Test (Java)</h2>

<font size=3>
<p>
This sample demonstrates basic use of Rules Enforcement Technology (RET).
</p>
<p>
The table is dynamically built, but the test criteria are for demo
purposes only.  <i>There's no need to take serious any failure
displays in the results!</i>
</p>
<p>

<%
  BrowserInfo info = BrowserHawk.getBrowserInfo(request);

  // * * * * * Here's the major change * * * * *
  RuleEngineResult result = engine.getResult(info, extBrowser, request);

  // Print a summary of test result counts
  out.println("Passes: " + result.getPassCount() + ",");
  out.println("Warns: " + result.getWarnCount() + ",");
  out.println("Failures: " + result.getFailCount() + ",");
  out.println("Infos: " + result.getInfoCount() + ",");
  out.println("Suppresses: " + result.getSuppressCount() + "<br />");

  // Let's do something special based on the "popup" test
  if (result.isFail("popup")) {
    out.println("<i>The popup requirement wasn't satisfied, I see...</i><br /><br />");
  }
  else if (result.isPass("popup")) {
    out.println("<i>The popup requirement was satisfied, I see...</i><br /><br />");
  }

  // Now let's print the table or do a redirect as requested
  String redir = result.getRedirect();
  if (redir != null) {
    response.sendRedirect(redir);
  }
  else {
    out.println(result.getHtmlTable());
  }
%>
<%
/*
  LogOptions logOptions = engine.getLogOptions();
  logOptions.setUserID("person");
  out.println(BrowserHawk.logData(info, extBrowser, logOptions, request));
*/
%>

<p>
<b><a href="rules-manual.jsp">Retry this test</a></b><P>
<b><a href="index.html">Return to list of other JSP samples</a></b><P>
<b><a href="http://www.cyscape.com/order/">BrowserHawk Pricing and Ordering</a></b><P>
<b><a href="http://www.cyscape.com/">cyScape home page</a></b><P>
</font>
</font>
</blockquote>
</body>
</html>
