browserDetection.jspf

 

<%--  ******************  Browser Detection  ******************  
    This section uses the CCPP profile to detect the browser.
    The browser variable is passed to the CSS jsps to implement browser-specific styles.
    Default theme CSS needs only differentiate between IE and Mozilla-based browsers.
--%>
<%@ page import="javax.ccpp.Profile" %>
<%@ page import="javax.ccpp.Attribute" %>
<%@ page import="javax.ccpp.ProfileFactory" %>
<%
response.setContentType("application/xhtml+xml");
// Determine the browser. For our purposes, we only distinguish IE vs Moz        
 Profile clientProfile = null;
 ProfileFactory profileFactory = ProfileFactory.getInstance();
 String browserVendor = "unknown";
 String browserName = "unknown";
 String browserVersion = "unknown";
 if (profileFactory != null) {
    clientProfile = profileFactory.newProfile(request);
    Attribute vendorAttribute = clientProfile.getAttribute("Vendor");
    if (vendorAttribute != null) {
        String attrValue = vendorAttribute.toString();
        if (null != attrValue) {
           browserVendor = attrValue;
        }
        pageContext.setAttribute("browserVendor", browserVendor);
    }
    Attribute nameAttribute = clientProfile.getAttribute("BrowserName");
    if (nameAttribute != null) {
        String attrValue = nameAttribute.toString();
        if (null != attrValue) {
           browserName = attrValue;
        }
        pageContext.setAttribute("browserName", browserName);
    }
    Attribute versionAttribute = clientProfile.getAttribute("BrowserVersion");
    if (versionAttribute != null) {
        String attrValue = versionAttribute.toString();
        if (null != attrValue) {
           browserVersion = attrValue;
        }
        pageContext.setAttribute("browserVersion", browserVersion);
    }
 }
 if("Microsoft".equals(browserVendor)){pageContext.setAttribute("browser", "ie");}
 else if("Apple".equals(browserVendor)){pageContext.setAttribute("browser", "safari");}
 else{pageContext.setAttribute("browser", "Moz");}
%>