001    /**
002     * Copyright 2010 The Kuali Foundation Licensed under the
003     * Educational Community License, Version 2.0 (the "License"); you may
004     * not use this file except in compliance with the License. You may
005     * obtain a copy of the License at
006     *
007     * http://www.osedu.org/licenses/ECL-2.0
008     *
009     * Unless required by applicable law or agreed to in writing,
010     * software distributed under the License is distributed on an "AS IS"
011     * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012     * or implied. See the License for the specific language governing
013     * permissions and limitations under the License.
014     */
015    
016    package org.kuali.student.common.ui.client.util;
017    
018    /**
019     * This provides a library of JSNI methods.
020     * 
021     */
022    public class BrowserUtils {
023        public static native String getOperatingSystem() /*-{
024                    if (navigator.appVersion.indexOf("Win")!=-1) return "Windows";
025                    if (navigator.appVersion.indexOf("Mac")!=-1) return OSName="MacOS";
026                    if (navigator.appVersion.indexOf("X11")!=-1) return OSName="UNIX";
027                    if (navigator.appVersion.indexOf("Linux")!=-1) return OSName="Linux";
028                    return "Unknown: " + navigator.appVersion;
029            }-*/;
030    
031        public  static native String getString(String name) /*-{
032            return eval("$wnd."+name);
033            }-*/;
034    
035        public static native String getUserAgent() /*-{
036                    return navigator.userAgent.toLowerCase();
037            }-*/;
038    
039            /**
040             * Redirect browser window to a different url
041             * @param url
042             */
043        public static native void redirect(String url)/*-{
044            $wnd.location = url;
045            }-*/;
046    
047            /**
048             * Reload the current browser page.
049             */
050        public static native void reload()/*-{
051                    $wnd.location.reload();
052            }-*/;
053        
054        public static native String getClassAttr()/*-{
055            if(navigator.appName == "Microsoft Internet Explorer"){
056                return "className";
057            } else {
058                return "class";
059            }
060        }-*/;
061    
062    }