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

  // Use a big response buffer so delay the response commit.
  // This makes it easier to spot late-happening exceptions.
  response.setBufferSize(128000);

  // This sample is provided under the terms of the BrowserHawk End User
  // License Agreement.  Copyright (c) 2003-2010 cyScape, Inc. All rights
  // reserved.

  // This sample demonstrates how to dynamically enumerate the BrowserHawk
  // properties to return a page showing all BrowserHawk detected results.

  // To demonstrate, we dynamically enumerate all the properties and display a
  // table with each property's value.  There are two tables displayed - one
  // for the "basic" properties as exposed through the BrowserInfo interface,
  // and another for the "extended" properties as exposed through the
  // ExtendedBrowserInfo class.

  ExtendedOptions options = new ExtendedOptions();
  BrowserInfo browser = null;
  ExtendedBrowserInfo extBrowser = null;

  // If we don't have an enterprise license, skip testing enterprise props to
  // avoid a run-time license error
  boolean isEnterprise = (BrowserHawk.getVersion().indexOf("Ent") != -1);
  boolean isPro = (BrowserHawk.getVersion().indexOf("Pro") != -1);

  // If Standard Edition then do not set up for or perform any extended
  // property tests, as these are not supported the Standard Edition.
  if (isPro || isEnterprise) {
     // Request a complete test.  This includes all extended properties that
     // are testable at the current BrowserHawk licensed edition.  That is,
     // a Professional license will test all Pro-level features while an
     // Enterprise license will test all Pro and Enterprise-level features.
     options.addProperties("complete");

     // Assign a stable of ports to check
     options.setPortsToCheck("80,443,554");

     // Some properties we'll test only if specifically requested
     options.removeProperties("FontsInstalled, Plugin_Custom, PopupsBlocked, ConnectionSpeed, ConnectionLatency, JavaVendor, JavaVersion, Plugin_JavaVer, MSJVMBuild, OSName, OSVersion, OSArch");

     // If the user sends a "doSpeed" parameter, we test speed detection
     if (request.getParameter("doSpeed") != null) {
       options.addProperties("ConnectionSpeed");
     }

     // If the user sends a "doJvmd" parameter and this is an Enterprise
     // Edition license, we test applet properties
     if (request.getParameter("doJvmd") != null && isEnterprise) {
       options.addProperties("JavaVendor, JavaVersion, Plugin_JavaVer, MSJVMBuild, OSName, OSVersion, OSArch");
     }

     // Now choose a request type; default is AUTO
     // See the documentation of the ExtendedOptions class for more
     // information on these request types and how they differ.
     // Note that in the majority of cases the default of REQUEST_TYPE_AUTO
     // is recommended.
     options.setRequestType(ExtendedOptions.REQUEST_TYPE_AUTO);

     // One common reason to use options is to set a "please wait" message.
     // Here we set the value to an explanation string, for purposes of
     // example.  The default is "".
     options.setPageMessage(
       "Now determining extended properties of this browser, please wait...");

     // Comment in the following if JVMDetector.class is in a different
     // directory than this JSP, and specify where the class is to be found.
     //options.setJVMCodeBase("/some/path/to/shared/files");

     extBrowser =
       BrowserHawk.getExtendedBrowserInfo(request, response, options);
 
     if (extBrowser == null) return;
  }

  // We'll want access to the standard properties too
  browser = BrowserHawk.getBrowserInfo(request);
%>

<HTML><HEAD>
<TITLE>BrowserHawk Sample - Full Browser Capabilities Test Page (JSP)</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF"><font face="arial">

<blockquote>
<h2>All BrowserHawk Properties Test Results</h2>

<FONT SIZE="+1">The following is information on your browser's capabilities<br>
as detected by 
<A HREF="http://www.cyscape.com/index.asp?q=showbrow">BrowserHawk</A>
(<%= BrowserHawk.getVersion() %>)

</FONT>
<P>

User agent: <%= request.getHeader("User-Agent") %><p>
Browser Definition File version: <%= browser.getBDDVersion() %>;
  Dated: <%= browser.getBDDDate() %><p>

<%
   String tdColor1 = "<TD font=arial BGCOLOR=#F0F0F0>";
   String tdColor2 = "<TD font=arial BGCOLOR=#FFFFFF>";
%>

   <TABLE BGCOLOR="#CCCCCC" BORDER=1 CELLPADDING=3 WIDTH=450>
   <TR><TD BGCOLOR="#99CCCC" COLSPAN=2 ALIGN=CENTER><FONT SIZE="5">
     Basic Properties for: <%= browser.getBrowser() %> 
     <%= browser.getFullversion() %>
     <%= browser.getPlatform() %>
   </FONT></TD></TR>
   <TR><TD BGCOLOR="#FFFFCC"><B>&nbsp;Property</B></TD>
       <TD BGCOLOR="#FFFFCC"><B>&nbsp;Value</B></TD></TR>
<%
   int colorCnt = 0;
   String tdColorToUse;

   String[] basicProps = { "Browser", "Majorver", "Minorver", "Minorverlet",
      "Version", "Fullversion", "Platform", "Gecko", "GeckoBuildDate", "Beta",
      "Frames", "IFrames", "Tables", "Cookies", "VBScript", "JavaScript",
      "JavaApplets", "ActiveXControls", "WinInstallerMinVer", "AOL",
      "AOLVersion", "SSL", "SSLActive", "SSLKeySize", "Win16", "Crawler",
      "CDF", "NETCLRInstalled", "NETCLRVersion", "Language",
      "AuthenticodeUpdate", "StyleSheets", "Proxy", "ProxyString",
      "OSDetails", "MSN", "Gold", "DHTML", "FileUpload", "MouseOver", "PNG",
      "FontColor", "FontSize", "TableBGColor", "JavaScriptVer", "IPAddr",
      "Country", "TableBGImage", "CompressGZip", "EmailCrawler", "XML", "WAP",
      "WAP_DeviceModel", "WAP_Gateway", "WAP_SubscriberID", "WAP_MaxDeckSize",
      "HDML", "PDA", "CharHeightAvail", "CharWidthAvail", "ContainerBrowser",
      "ContainerVersion", "ContainerFullversion", "XMLHttpRequest",
      "MobileDevice", "MobileDeviceName" };
   for (int i = 0; i < basicProps.length; i++) {
      String propertyName = basicProps[i];

      colorCnt++;
      if ( colorCnt % 2 == 0)
         tdColorToUse = tdColor1;
      else
         tdColorToUse = tdColor2;

      try {
         String val = null;
         if (propertyName.equalsIgnoreCase("WinInstallerMinVer") && isEnterprise == false) { // special case
            val = "Requires Enterprise Edition";
         }
         else if (propertyName.equalsIgnoreCase("Country")) { // special case
            try {
               val = browser.getCountry();
            }
            catch (Exception countryHawkNotInstalledOrMisconfigured) {
               val = "Requires <a href='http://www.cyscape.com/'>CountryHawk</a>";
            }
         }
         else {
            // Note: In this sample we are enumerating through all the basic
            // properties and dynamically accessing each of the properties
            // values through the get() method to make it convenient to display
            // all results.  However it is important to note that in normal
            // circumstances you would NOT use the get() method to get the
            // value since this returns the result as an object and is
            // internally less efficient.  Instead you should directly
            // reference the property you are interested in.
            // For instance use this:
            //     String browType = browser.getBrowser(); // do this
            //     int majorver = browser.getMajorver();   // do this
            // Instead of this:
            //     Object browType = browser.get("Browser");  // not this
            //     Object majorver = browser.get("Majorver"); // not this
            Object result = browser.get(propertyName);
            if (result != null) {
              val = result.toString();  // else leave as null
            }
         }
         out.println("<TR>" + tdColorToUse + "&nbsp;" + "<a name=\"" + propertyName + "\">" + propertyName + "</a></TD>" + tdColorToUse + "&nbsp;" + val + "</TD></TR>");
      }
      catch (Exception e) {
         out.println("<TR>" + tdColorToUse + "&nbsp;" + "<a name=\"" + propertyName + "\">" + propertyName + "</a></TD>" + tdColorToUse + "&nbsp; " + e.getMessage() + "</TD></TR>");
      }
   }
%>
   </TABLE>

   <P>
   <HR ALIGN=LEFT WIDTH=550>
   <P>

<%
   if (isPro || isEnterprise) {
     if (extBrowser == ExtendedBrowserInfo.UNSUPPORTED) {
       out.println(
         "<big>No extended information is available.  Only Netscape, " +
         "Mozilla, IE, Opera and Safari clients are supported.</big><p>");
     }
     else if (extBrowser.getJavaScriptEnabled() == false) {
       out.println(
         "<big>No extended information is available.  This client has " +
         "JavaScript disabled.</big><p>");
     }
   }
   // We'll print the table below regardless of the above warnings
%>


   <TABLE BGCOLOR="#CCCCCC" BORDER=1 CELLPADDING=3 WIDTH=500>
   <TR><TD BGCOLOR="#99CCCC" COLSPAN=2 ALIGN=CENTER><FONT SIZE="+2">Extended Properties</FONT></TD></TR>
   <TR><TD BGCOLOR="#FFFFCC"><B>&nbsp;Property</B></TD>
       <TD BGCOLOR="#FFFFCC"><B>&nbsp;Value</B></TD></TR>
<%
   colorCnt = 0;

   String[] extendedProps = { "BrowserBuild", "ServicePack", "VBScriptEnabled",
      "VBScriptBuild", "JavaScriptEnabled", "JavaScriptBuild", "JavaEnabled",
      "JavaVersion", "JavaVendor", "MSJVMBuild", "ActiveXEnabled",
      "ImagesEnabled", "SSLEnabled", "SSLKeySize", "LangUser", "LangSystem",
      "TimeZoneDiff", "BrowserDateTime", "BrowserDateTimeMs", "Firewall",
      "FontSmoothing", "TextSize", "Height", "HeightAvail", "Width",
      "WidthAvail", "Broadband", "ConnectionType", "ConnectionSpeed",
      "Plugin_Flash", "Plugin_FlashVerEx", "Plugin_Silverlight",
			"Plugin_SilverlightVerEx", "Plugin_Director",
      "Plugin_DirectorVerEx", "Plugin_QuickTime", "Plugin_QuickTimeVerEx",
      "Plugin_Acrobat", "Plugin_AcrobatVerEx", "Plugin_RealPlayer",
      "Plugin_RealPlayerBuild", "Plugin_MediaPlayer", "Plugin_MediaPlayerVerEx",
      "Plugin_SVGViewer", "Plugin_CrystalReports", "Plugin_Viewpoint",
      "Plugin_Authorware", "Plugin_MapGuide", "Plugin_Citrix",
      "Plugin_JavaVer", "Plugin_Custom", "NetMeetingBuild", "ColorDepth",
      "MSXML", "OpenPorts", "Referrer", "PopupsBlocked", "FontsInstalled",
      "Plugin_IPIXViewer", "PersistentCookies", "SessionCookies",
      "HighSecurity", "OSName", "OSVersion", "OSArch", "ContainerBrowser",
      "ContainerVersion", "ContainerFullversion", "DisplayXDPIActual",
      "DisplayYDPIActual", "DisplayXDPILogical", "DisplayYDPILogical",
      "Plugin_Flip4Mac"
   };
   for (int i = 0; i < extendedProps.length; i++) {
     String propertyName = extendedProps[i];

      colorCnt++;
      if (colorCnt % 2 == 0)
         tdColorToUse = tdColor1;
      else
         tdColorToUse = tdColor2;

      String val;

      try {
         // Basic default for Standard Edition licensees
         if (!isPro && !isEnterprise) {
            val = "Not Available in Standard Edition";
         }
         // If this is a JVMD test and it's not set, let the user click
         else if (request.getParameter("doJvmd") == null && isEnterprise &&
                 (
                  propertyName.equalsIgnoreCase("plugin_javaver") ||
                  propertyName.equalsIgnoreCase("javavendor") ||
                  propertyName.equalsIgnoreCase("javaversion") ||
                  propertyName.equalsIgnoreCase("msjvmbuild") ||
                  propertyName.equalsIgnoreCase("osname") ||
                  propertyName.equalsIgnoreCase("osarch") ||
                  propertyName.equalsIgnoreCase("osversion")
                 )) {
            val = "Click <a href=\"?doJvmd=1\">here</a> to test";
            // If isPro, intentionally fall through to translate()
         }
         else if (propertyName.equalsIgnoreCase("connectionspeed") && request.getParameter("doSpeed") == null) {
            val = "Click <a href=\"?doSpeed=1\">here</a> to test";
         }
         else if (propertyName.equalsIgnoreCase("popupsblocked") && isEnterprise) {
            val = "Click <a href=\"popupcheck.jsp\">here</a> to test";
         }
         else if (propertyName.equalsIgnoreCase("fontsinstalled") && isEnterprise) {
            val = "Click <a href=\"fontcheck_adv.jsp\">here</a> to test";
         }
         else {
            val = extBrowser.translate(propertyName);
         }

         out.println("<TR>" + tdColorToUse + "&nbsp;" + "<a name=\"" + propertyName + "\">" + propertyName + "</a></TD>" + tdColorToUse + "&nbsp;" + val + "</TD></TR>");
      }
      catch (Exception e) {
        String result = "&nbsp; Exception occurred: " + e.getMessage();
        out.println("<TR>" + tdColorToUse + "&nbsp;" + "<a name=\"" + propertyName + "\">" + propertyName + "</a></TD>" + tdColorToUse + result + "</TD></TR>");
      }
   }
%>

   </TABLE>

   <P>
   <HR>
   <P>

<b><a href="showbrow.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>
</blockquote>
</body>
</html>
