" " + MSIE_Win_Lang_Os.getParen(3)); } else if (Opera_Lang_Os.match(agent)) { OS = Opera_Lang_Os.getParen(1); OSVersion = Opera_Lang_Os.getParen(2); lang = Opera_Lang_Os.getParen(3);
" " + RE_MSIE_WIN_LANG_OS.getParen(3)); } else if (RE_OPERA_LANG_OS.match(agent)) { os = RE_OPERA_LANG_OS.getParen(1); osVersion = RE_OPERA_LANG_OS.getParen(2); lang = RE_OPERA_LANG_OS.getParen(3);
    protected void detect()            throws org.apache.regexp.RESyntaxException {        if (agent == null || agent.length() == 0)            return;        /* regexps are not threadsafe, we have to create them. */        RE Start = new RE("^([a-zA-Z0-9_\\-]+)(/([0-9])\\.([0-9]+))?");        RE MSIE = new RE("MSIE ([0-9])\\.([0-9]+)([a-z])?");        RE MSIE_Win_Lang_Os = new RE("[wW]in(dows)? ([A-Z0-9]+) ?([0-9]\\.[0-9])?");        RE MSIE_Mac_Lang_Os = new RE("Mac_PowerPC");        RE NS_Lang_Os = new RE("\\[([a-z-]+)\\][ a-zA-Z0-9-]*\\(([a-zA-Z\\-]+)/?([0-9]* ?[.a-zA-Z0-9 ]*);");        RE NS_X11_Lang_Os = new RE("\\(X11; U; ([a-zA-Z-]+) ([0-9\\.]+)[^\\);]+\\)");        RE NS6_Lang_Os = new RE("\\(([a-zA-Z0-9]+); [a-zA-Z]+; ([a-zA-Z0-9_]+)( ([a-zA-Z0-9]+))?; ([_a-zA-Z-]+);");        RE Lang = new RE("\\[([_a-zA-Z-]+)\\]");        RE Opera = new RE("((; )|\\()([a-zA-Z0-9\\-]+)[ ]+([a-zA-Z0-9\\.]+)([^;\\)]*)(; U)?\\) Opera ([0-9]+)\\.([0-9]+)[ ]+\\[([_a-zA-Z-]+)\\]");        RE Opera_Lang_Os = new RE("\\(([a-zA-Z0-9\\-]+) ([0-9\\.]+)[^)]+\\)[ \t]*\\[([a-z_]+)\\]");        RE Konqueror_Os = new RE("Konqueror/([0-9\\.]+); ([a-zA-Z0-9\\-]+)");        RE Galeon_Os = new RE("\\(([a-zA-Z0-9]+); U; Galeon; ([0-9]+)\\.([0-9]+);");        RE Gecko_Engine = new RE("Gecko/[0-9]*( ([a-zA-Z]+)+[0-9]*/([0-9]+)\\.([0-9]+)([a-zA-Z0-9]*))?");        String mav, miv, lang = null;        if (Start.match(agent)) {            Name = Start.getParen(1);            mav = Start.getParen(3);            miv = Start.getParen(4);                        /* MSIE hides itself behind Mozilla or different name,               good idea, congratulation Bill !            */            if (MSIE.match(agent)) {                Name = "MSIE";                mav = MSIE.getParen(1);                miv = MSIE.getParen(2);                Release = MSIE.getParen(3);                if (MSIE_Win_Lang_Os.match(agent)) {                    OS = "Windows";                    OSVersion = MSIE_Win_Lang_Os.getParen(2) +                            (MSIE_Win_Lang_Os.getParen(3) == null ?                            "" :                            " " + MSIE_Win_Lang_Os.getParen(3));                } else if (MSIE_Mac_Lang_Os.match(agent)) {                    OS = "MacOS";                    OSType = MACOS;                }            }            /* Mozilla has to different id's; one up to version 4               and a second for version >= 5            */            else if (Name.equals("Mozilla") || Name == null) {                Name = "Mozilla";                                /* old mozilla */                if (NS_Lang_Os.match(agent)) {                    lang = NS_Lang_Os.getParen(1);                    OS = NS_Lang_Os.getParen(2);                    OSVersion = NS_Lang_Os.getParen(3);                    if (OS.equals("X")) {                        if (NS_X11_Lang_Os.match(agent)) {                            OS = NS_X11_Lang_Os.getParen(1);                            OSVersion = NS_X11_Lang_Os.getParen(2);                            OSType = UNIX;                        }                    }                }                /* NS5, NS6 Galeon etc. */                else if (Galeon_Os.match(agent)) {                    Name = "Galeon";                    OS = Galeon_Os.getParen(1);                    if (OS.equals("X11")) {                        OS = "Unix";                        OSType = UNIX;                    }                    mav = Galeon_Os.getParen(2);                    miv = Galeon_Os.getParen(3);                    HasGecko = true;                } else if (NS6_Lang_Os.match(agent)) {                    OS = NS6_Lang_Os.getParen(2);                    lang = NS6_Lang_Os.getParen(5);                    HasGecko = true;                }                /* realy seldom but is there */                else if (MSIE_Win_Lang_Os.match(agent)) {                    OS = "Windows";                    OSType = WINDOWS;                    OSVersion = MSIE_Win_Lang_Os.getParen(2) +                            (MSIE_Win_Lang_Os.getParen(3) == null ?                            "" :                            " " + MSIE_Win_Lang_Os.getParen(3));                }                /* Konqueror */                else if (Konqueror_Os.match(agent)) {                    Name = "Konqueror";                    StringTokenizer strtok = new StringTokenizer(Konqueror_Os.getParen(1), ".");                    mav = strtok.nextToken();                    if (strtok.hasMoreTokens())                        miv = strtok.nextToken();                    if (strtok.hasMoreTokens())                        Release = strtok.nextToken();                    OS = Konqueror_Os.getParen(2);                }                /* f*ck, what's that ??? */                else {                    Name = "Mozilla";                }                                /* reformat browser os */                if (OS != null && OS.startsWith("Win") &&                        (OSVersion == null || OSVersion.length() == 0)                ) {                    OSVersion = OS.substring(3, OS.length());                    OS = "Windows";                    OSType = WINDOWS;                }                /* just any windows */                if (OS != null && OS.equals("Win")) {                    OS = "Windows";                    OSType = WINDOWS;                }            }            /* Opera identified as opera, that's easy! */            else if (Name.equals("Opera")) {                if (MSIE_Win_Lang_Os.match(agent)) {                    OS = "Windows";                    OSType = WINDOWS;                    OSVersion = MSIE_Win_Lang_Os.getParen(2) +                            (MSIE_Win_Lang_Os.getParen(3) == null ?                            "" :                            " " + MSIE_Win_Lang_Os.getParen(3));                } else if (Opera_Lang_Os.match(agent)) {                    OS = Opera_Lang_Os.getParen(1);                    OSVersion = Opera_Lang_Os.getParen(2);                    lang = Opera_Lang_Os.getParen(3);                }            }                        /* Opera identified as something else (Mozilla, IE ...) */            if (Opera.match(agent)) {                Name = "Opera";                OS = Opera.getParen(3);                OSVersion = Opera.getParen(4);                mav = Opera.getParen(7);                miv = Opera.getParen(8);                lang = Opera.getParen(10);            }            /* detect gecko */            if (Gecko_Engine.match(agent)) {                HasGecko = true;                if (Gecko_Engine.getParen(2) != null)                    Name = Gecko_Engine.getParen(2);                if (Gecko_Engine.getParen(3) != null)                    mav = Gecko_Engine.getParen(3);                if (Gecko_Engine.getParen(4) != null)                    miv = Gecko_Engine.getParen(4);                if (Gecko_Engine.getParen(5) != null)                    Release = Gecko_Engine.getParen(5);            }                        /* try to find language in uncommon places                if not detected before            */            if (lang == null) {                if (Lang.match(agent)) {                    lang = Lang.getParen(1);                }            }            try { MajorVersion = new Integer(mav).intValue(); } catch (NumberFormatException ex) { MajorVersion = 0; }            try { MinorVersion = new Double("0." + miv).doubleValue(); } catch (NumberFormatException ex) {                MinorVersion = 0f;            }            if (lang == null)                BLocale = Locale.getDefault();            else {                /* Mozilla does that, maybe any other browser too ? */                lang = lang.replace('-', '_');                /* test for country extension */                StringTokenizer strtok = new StringTokenizer(lang, "_");                String l = strtok.nextToken();                if (strtok.hasMoreElements())                    BLocale = new Locale(l, strtok.nextToken());                else                    BLocale = new Locale(l, "");            }            if (OSType == OS_UNKNOWN && OS != null) {                if (OS.equals("Windows"))                    OSType = WINDOWS;                else if (OS.equals("MacOS"))                    OSType = MACOS;                else if (                        OS.equals("Linux") ||                        OS.equals("AIX") ||                        OS.equals("SunOS") ||                        OS.equals("HP-UX") ||                        OS.equals("Solaris") ||                        OS.equals("BSD")                ) {                    OSType = UNIX;                } else if (OS.equals("OS")) {                    OSType = IBMOS;                }            }        }    }