<%
  // This sample is provided under the terms of the BrowserHawk End User
  // License Agreement. Copyright (c) 2007-2011 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 to use the JSEval feature in combination
  // with RET.  Notice how you can control the JSEval settings from
  // within the XML.
%>

<%@ 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;
  }

  // Notice how <loc> becomes available as a result of the jseval extension setting
  // This example reads the rules from a string rather than file.
  RuleEngine engine = RuleEngine.getFromString(
  "<tests>\n" +
  "  <config>\n" +
  "    <extended-options>\n" +
  "      <jseval name='loc'>document.location</jseval>\n" +
  "    </extended-options>\n" +
  "  </config>\n" +
  "  <test id='location' name='URL Location'>\n" +
  "    <warn>\n" +
  "      <loc matcher='regex'>https?://localhost.*</loc>\n" +
  "      <message>You are browsing localhost (%loc%), which is fine but make sure to test with a public address also</message>\n" +
  "    </warn>\n" +
  "    <info>\n" +
  "      <message>You are browsing %loc%.</message>\n" +
  "    </info>\n" +
  "  </test>\n" +
  "</tests>"
  );

  // This is a good idea, even though here it's the empty string
  // because there's no BrowserHawk properties used above, only
  // extension properties via JSEval.
  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 JSEval Rules Test (Java)</title>
  <link href="rules.css" rel="stylesheet" type="text/css" />
</head>
<body><font face="arial">
<blockquote>
<h2>Performing a JSEval Rules Test (Java)</h2>

<font size=3>
<p>
This sample demonstrates JSEval used with Rules Enforcement Technology (RET).
It also demonstrates regular expression matching.
</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);
%>
<%=
  engine.getHtmlResult(info, extBrowser, request)
%>
<%
/*
  LogOptions logOptions = engine.getLogOptions();
  logOptions.setUserID("person");
  out.println(BrowserHawk.logData(info, extBrowser, logOptions, request));
*/
%>

<p>
<b><a href="rules-eval.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>
