KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > webapp > data > UrlUtil


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * Sebastian Davids <sdavids@gmx.de> - fix for Bug 182466
11  *******************************************************************************/

12 package org.eclipse.help.internal.webapp.data;
13 import java.io.IOException JavaDoc;
14 import java.net.InetAddress JavaDoc;
15 import java.util.ArrayList JavaDoc;
16 import java.util.Collection JavaDoc;
17 import java.util.Enumeration JavaDoc;
18 import java.util.HashSet JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Locale JavaDoc;
22 import java.util.StringTokenizer JavaDoc;
23 import java.util.regex.Matcher JavaDoc;
24 import java.util.regex.Pattern JavaDoc;
25
26 import javax.servlet.http.Cookie JavaDoc;
27 import javax.servlet.http.HttpServletRequest JavaDoc;
28 import javax.servlet.http.HttpServletResponse JavaDoc;
29
30 import org.eclipse.core.runtime.Platform;
31 import org.eclipse.help.internal.HelpPlugin;
32 import org.eclipse.help.internal.base.BaseHelpSystem;
33 import org.eclipse.help.internal.base.HelpBasePlugin;
34 import org.eclipse.help.internal.base.util.TString;
35
36 public class UrlUtil {
37     // XML escaped characters mapping
38
private static final String JavaDoc invalidXML[] = {"&", ">", "<", "\""}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
39
private static final String JavaDoc escapedXML[] = {
40             "&amp;", "&gt;", "&lt;", "&quot;"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
41

42     // for Safari build 125.1 finds version 125
43
static final Pattern JavaDoc safariPattern = Pattern.compile(
44             "Safari/(\\d+)(?:\\.|\\s|$)", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
45

46     // Default locale to use for serving requests to help
47
private static String JavaDoc defaultLocale;
48     // Locales that infocenter can serve in addition to the default locale.
49
// null indicates that infocenter can serve every possible client locale.
50
private static Collection JavaDoc locales;
51     
52     private static final int INFOCENTER_DIRECTION_BY_LOCALE = 1;
53     private static final int INFOCENTER_DIRECTION_LTR = 2;
54     private static final int INFOCENTER_DIRECTION_RTL = 3;
55     private static int infocenterDirection = INFOCENTER_DIRECTION_BY_LOCALE;
56
57     /**
58      * Encodes string for embedding in JavaScript source
59      */

60     public static String JavaDoc JavaScriptEncode(String JavaDoc str) {
61         if (str == null) return null;
62         char[] wordChars = new char[str.length()];
63         str.getChars(0, str.length(), wordChars, 0);
64         StringBuffer JavaDoc jsEncoded = new StringBuffer JavaDoc();
65         for (int j = 0; j < wordChars.length; j++) {
66             int unicode = wordChars[j];
67             // to enhance readability, do not encode A-Z,a-z
68
if (('A' <= unicode && unicode <= 'Z')
69                     || ('a' <= unicode && unicode <= 'z')) {
70                 jsEncoded.append(wordChars[j]);
71                 continue;
72             }
73             // encode the character
74
String JavaDoc charInHex = Integer.toString(unicode, 16).toUpperCase();
75             switch (charInHex.length()) {
76                 case 1 :
77                     jsEncoded.append("\\u000").append(charInHex); //$NON-NLS-1$
78
break;
79                 case 2 :
80                     jsEncoded.append("\\u00").append(charInHex); //$NON-NLS-1$
81
break;
82                 case 3 :
83                     jsEncoded.append("\\u0").append(charInHex); //$NON-NLS-1$
84
break;
85                 default :
86                     jsEncoded.append("\\u").append(charInHex); //$NON-NLS-1$
87
break;
88             }
89         }
90         return jsEncoded.toString();
91     }
92
93     /**
94      * Encodes string for embedding in html source.
95      */

96     public static String JavaDoc htmlEncode(String JavaDoc str) {
97
98         for (int i = 0; i < invalidXML.length; i++)
99             str = TString.change(str, invalidXML[i], escapedXML[i]);
100         return str;
101     }
102
103     public static boolean isLocalRequest(HttpServletRequest JavaDoc request) {
104         String JavaDoc reqIP = request.getRemoteAddr();
105         if ("127.0.0.1".equals(reqIP)) { //$NON-NLS-1$
106
return true;
107         }
108
109         try {
110             String JavaDoc hostname = InetAddress.getLocalHost().getHostName();
111             InetAddress JavaDoc[] addr = InetAddress.getAllByName(hostname);
112             for (int i = 0; i < addr.length; i++) {
113                 // test all addresses retrieved from the local machine
114
if (addr[i].getHostAddress().equals(reqIP))
115                     return true;
116             }
117         } catch (IOException JavaDoc ioe) {
118         }
119         return false;
120     }
121
122     /**
123      * Returns a URL that can be loaded from a browser. This method is used for
124      * all url's except those from the webapp plugin.
125      *
126      * @param url
127      * @return String
128      */

129     public static String JavaDoc getHelpURL(String JavaDoc url) {
130         if (url == null || url.length() == 0)
131             url = "about:blank"; //$NON-NLS-1$
132
else if (url.startsWith("http:/") || url.startsWith("https:/")); //$NON-NLS-1$ //$NON-NLS-2$
133
else if (url.startsWith("file:/") || url.startsWith("jar:file:/")) //$NON-NLS-1$ //$NON-NLS-2$
134
url = "../topic/" + url; //$NON-NLS-1$
135
else
136             url = "../topic" + url; //$NON-NLS-1$
137
return url;
138     }
139     
140     /**
141      * Returns a path to the given topic in the form of child indexes. For
142      * example, if the path points to the 3rd subtopic under the 2nd topic of
143      * the 4th toc, it will return { 3, 1, 2 }.
144      *
145      * @param path the path portion of the url, e.g. "/help/topic/my.plugin/foo.html"
146      * @return path to the topic using zero-based indexes
147      */

148     public static int[] getTopicPath(String JavaDoc path) {
149         if (path.startsWith("/help/nav/")) { //$NON-NLS-1$
150
path = path.substring(10);
151             StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(path, "_"); //$NON-NLS-1$
152
int[] array = new int[tok.countTokens()];
153             for (int i=0;i<array.length;++i) {
154                 array[i] = Integer.parseInt(tok.nextToken());
155             }
156             return array;
157         }
158         else {
159             // grab the part after /help/*topic/
160
String JavaDoc href = path.substring(path.indexOf('/', 6));
161             return HelpPlugin.getTocManager().getTopicPath(href);
162         }
163     }
164
165     public static boolean isBot(HttpServletRequest JavaDoc request) {
166         String JavaDoc agent = request.getHeader("User-Agent"); //$NON-NLS-1$
167
if (agent==null)
168             return false;
169         agent=agent.toLowerCase(Locale.ENGLISH);
170         // sample substring Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
171
return agent.indexOf("bot") >= 0 || agent.indexOf("crawl") >= 0//$NON-NLS-1$ //$NON-NLS-2$
172
|| request.getParameter("bot") != null;//$NON-NLS-1$
173
}
174
175     public static boolean isGecko(HttpServletRequest JavaDoc request) {
176         String JavaDoc agent = request.getHeader("User-Agent"); //$NON-NLS-1$
177
return isGecko(agent);
178     }
179
180     public static boolean isGecko(String JavaDoc agent) {
181         if (agent==null)
182             return false;
183         agent=agent.toLowerCase(Locale.ENGLISH);
184         // sample substring Gecko/20020508
185
// search for "gecko/" not to react to "like Gecko"
186
return agent.indexOf("gecko/") >= 0; //$NON-NLS-1$
187
}
188
189     public static boolean isIE(HttpServletRequest JavaDoc request) {
190         String JavaDoc agent = request.getHeader("User-Agent"); //$NON-NLS-1$
191
return isIE(agent);
192     }
193
194     public static boolean isIE(String JavaDoc agent) {
195         if (agent==null)
196             return false;
197         agent=agent.toLowerCase(Locale.ENGLISH);
198
199         // When accessing with Bobby identified Bobby return 5.5 to allow
200
// testing advanced UI as bobby cannot identifiy as IE >=5.5
201
if (agent.startsWith("bobby/")) { //$NON-NLS-1$
202
return true;
203         }
204         //
205

206         return (agent.indexOf("msie") >= 0); //$NON-NLS-1$
207
}
208
209     public static String JavaDoc getIEVersion(HttpServletRequest JavaDoc request) {
210         String JavaDoc agent = request.getHeader("User-Agent"); //$NON-NLS-1$
211
return getIEVersion(agent);
212     }
213
214     public static String JavaDoc getIEVersion(String JavaDoc agent) {
215         if (agent==null)
216             return "0"; //$NON-NLS-1$
217

218         agent=agent.toLowerCase(Locale.ENGLISH);
219         // When accessing with Bobby identified Bobby return 5.5 to allow
220
// testing advanced UI as bobby cannot identifiy as IE >=5.5
221
if (agent.startsWith("bobby/")) { //$NON-NLS-1$
222
return "5.5"; //$NON-NLS-1$
223
}
224         //
225

226         int start = agent.indexOf("msie ") + "msie ".length(); //$NON-NLS-1$ //$NON-NLS-2$
227
if (start < "msie ".length() || start >= agent.length()) //$NON-NLS-1$
228
return "0"; //$NON-NLS-1$
229
int end = agent.indexOf(";", start); //$NON-NLS-1$
230
if (end <= start)
231             return "0"; //$NON-NLS-1$
232
return agent.substring(start, end);
233     }
234
235     public static boolean isKonqueror(HttpServletRequest JavaDoc request) {
236         String JavaDoc agent = request.getHeader("User-Agent"); //$NON-NLS-1$
237
return isKonqueror(agent);
238     }
239
240     public static boolean isKonqueror(String JavaDoc agent) {
241         if (agent==null)
242             return false;
243         agent=agent.toLowerCase(Locale.ENGLISH);
244         return agent.indexOf("konqueror") >= 0; //$NON-NLS-1$
245
}
246
247     /**
248      * Test to see if this is a "mozilla" browser, i.e.
249      * just about anything other than Internet Explorer
250      * @param request a request from the browser
251      * @return true if the browser is Netcape, Firefox, Safari or Konqueror
252      */

253     public static boolean isMozilla(HttpServletRequest JavaDoc request) {
254         String JavaDoc agent = request.getHeader("User-Agent"); //$NON-NLS-1$
255
return isMozilla(agent);
256     }
257
258     public static boolean isMozilla(String JavaDoc agent) {
259         if (agent==null)
260             return false;
261         agent=agent.toLowerCase(Locale.ENGLISH);
262         return agent.indexOf("mozilla/5") >= 0; //$NON-NLS-1$
263
}
264
265     public static String JavaDoc getMozillaVersion(HttpServletRequest JavaDoc request) {
266         String JavaDoc agent = request.getHeader("User-Agent"); //$NON-NLS-1$
267
return getMozillaVersion(agent);
268     }
269
270     public static String JavaDoc getMozillaVersion(String JavaDoc agent) {
271         if (agent==null)
272             return "0"; //$NON-NLS-1$
273
agent=agent.toLowerCase(Locale.ENGLISH);
274         if (agent.indexOf("mozilla/5") < 0) //$NON-NLS-1$
275
return "0"; //$NON-NLS-1$
276
int start = agent.indexOf("rv:") + "rv:".length(); //$NON-NLS-1$ //$NON-NLS-2$
277
if (start < "rv:".length() || start >= agent.length()) //$NON-NLS-1$
278
return "0"; //$NON-NLS-1$
279
int end = agent.indexOf(")", start); //$NON-NLS-1$
280
if (end <= start)
281             return "0"; //$NON-NLS-1$
282
return agent.substring(start, end);
283     }
284
285     public static boolean isOpera(HttpServletRequest JavaDoc request) {
286         String JavaDoc agent = request.getHeader("User-Agent"); //$NON-NLS-1$
287
return isOpera(agent);
288     }
289
290     public static boolean isOpera(String JavaDoc agent) {
291         if (agent==null)
292             return false;
293         agent=agent.toLowerCase(Locale.ENGLISH);
294         return agent.indexOf("opera") >= 0; //$NON-NLS-1$
295
}
296
297     public static String JavaDoc getOperaVersion(String JavaDoc agent) {
298         if (agent==null)
299             return "0"; //$NON-NLS-1$
300
agent=agent.toLowerCase(Locale.ENGLISH);
301         final String JavaDoc OperaPrefix = "opera/"; //$NON-NLS-1$
302
int start = agent.indexOf(OperaPrefix) + OperaPrefix.length();
303         if (start < OperaPrefix.length() || start >= agent.length())
304             return "0"; //$NON-NLS-1$
305
int end = agent.indexOf(" (", start); //$NON-NLS-1$
306
if (end <= start)
307             return "0"; //$NON-NLS-1$
308
return agent.substring(start, end);
309     }
310
311     public static boolean isSafari(HttpServletRequest JavaDoc request) {
312         String JavaDoc agent = request.getHeader("User-Agent"); //$NON-NLS-1$
313
return isSafari(agent);
314     }
315
316     public static boolean isSafari(String JavaDoc agent) {
317         if (agent==null)
318             return false;
319         agent=agent.toLowerCase(Locale.ENGLISH);
320         return agent.indexOf("safari/") >= 0; //$NON-NLS-1$
321
}
322
323     public static String JavaDoc getSafariVersion(HttpServletRequest JavaDoc request) {
324         String JavaDoc agent = request.getHeader("User-Agent"); //$NON-NLS-1$
325
return getSafariVersion(agent);
326     }
327
328     public static String JavaDoc getSafariVersion(String JavaDoc agent) {
329         String JavaDoc version = "0"; //$NON-NLS-1$
330
if (agent==null)
331             return version;
332         agent=agent.toLowerCase(Locale.ENGLISH);
333         Matcher JavaDoc m = safariPattern.matcher(agent);
334         boolean matched = m.find();
335         if (matched) {
336             version = m.group(1);
337             while (version.length() < 3) {
338                 version = "0" + version; //$NON-NLS-1$
339
}
340         }
341         return version;
342     }
343     /**
344      *
345      * @param request
346      * @param response
347      * HttpServletResponse or null (locale will not be persisted in
348      * session cookie)
349      * @return
350      */

351     public static Locale JavaDoc getLocaleObj(HttpServletRequest JavaDoc request,
352             HttpServletResponse JavaDoc response) {
353         String JavaDoc localeStr = getLocale(request, response);
354         return getLocale(localeStr);
355     }
356     
357     /**
358      * Returns the locale object from the provided string.
359      * @param localeStr the encoded locale string
360      * @return the Locale object
361      *
362      * @since 3.1
363      */

364     public static Locale JavaDoc getLocale(String JavaDoc localeStr) {
365         if (localeStr.length() >= 5) {
366             return new Locale JavaDoc(localeStr.substring(0, 2), localeStr.substring(3,
367                     5));
368         } else if (localeStr.length() >= 2) {
369             return new Locale JavaDoc(localeStr.substring(0, 2), ""); //$NON-NLS-1$
370
} else {
371             return Locale.getDefault();
372         }
373     }
374     /**
375      *
376      * @param request
377      * @param response
378      * HttpServletResponse or null (locale will not be persisted in
379      * session cookie)
380      * @return
381      */

382     public static String JavaDoc getLocale(HttpServletRequest JavaDoc request,
383             HttpServletResponse JavaDoc response) {
384         if (defaultLocale == null) {
385             initializeNL();
386         }
387         if ((BaseHelpSystem.getMode() != BaseHelpSystem.MODE_INFOCENTER)
388                 || request == null) {
389             return defaultLocale;
390         }
391
392         // use locale passed in a request in current user session
393
String JavaDoc forcedLocale = getForcedLocale(request, response);
394         if (forcedLocale != null) {
395             if (locales == null) {
396                 // infocenter set up to serve any locale
397
return forcedLocale;
398             }
399             // match forced locale with one of infocenter locales
400
if (locales.contains(forcedLocale)) {
401                 return forcedLocale;
402             }
403             // match language of forced locale with one of infocenter locales
404
if (forcedLocale.length() > 2) {
405                 String JavaDoc ll = forcedLocale.substring(0, 2);
406                 if (locales.contains(ll)) {
407                     return ll;
408                 }
409             }
410         }
411
412         // use one of the browser locales
413
if (locales == null) {
414             // infocenter set up to serve any locale
415
return request.getLocale().toString();
416         }
417         // match client browser locales with one of infocenter locales
418
for (Enumeration JavaDoc e = request.getLocales(); e.hasMoreElements();) {
419             String JavaDoc locale = ((Locale JavaDoc) e.nextElement()).toString();
420             if (locale.length() >= 5) {
421                 String JavaDoc ll_CC = locale.substring(0, 5);
422                 if (locales.contains(ll_CC)) {
423                     // client locale available
424
return ll_CC;
425                 }
426             }
427             if (locale.length() >= 2) {
428                 String JavaDoc ll = locale.substring(0, 2);
429                 if (locales.contains(ll)) {
430                     // client language available
431
return ll;
432                 }
433             }
434         }
435         // no match
436
return defaultLocale;
437     }
438
439     /**
440      * Obtains locale passed as lang parameter with a request during user
441      * session
442      *
443      * @param request
444      * @param response
445      * response or null; if null, locale will not be persisted (in
446      * session cookie)
447      * @return ll_CC or ll or null
448      */

449     private static String JavaDoc getForcedLocale(HttpServletRequest JavaDoc request,
450             HttpServletResponse JavaDoc response) {
451         // get locale passed in this request
452
String JavaDoc forcedLocale = request.getParameter("lang"); //$NON-NLS-1$
453
if (forcedLocale != null) {
454             // save locale (in session cookie) for later use in a user session
455
if (response != null) {
456                 Cookie JavaDoc cookieTest = new Cookie JavaDoc("lang", forcedLocale); //$NON-NLS-1$
457
response.addCookie(cookieTest);
458             }
459         } else {
460             // check if locale was passed earlier in this session
461
Cookie JavaDoc[] cookies = request.getCookies();
462             if (cookies != null) {
463                     for (int c = 0; c < cookies.length; c++) {
464                         if ("lang".equals(cookies[c].getName())) { //$NON-NLS-1$
465
forcedLocale = cookies[c].getValue();
466                             break;
467                         }
468                     }
469             }
470         }
471
472         // format forced locale
473
if (forcedLocale != null) {
474             if (forcedLocale.length() >= 5) {
475                 forcedLocale = forcedLocale.substring(0, 2) + "_" //$NON-NLS-1$
476
+ forcedLocale.substring(3, 5);
477             } else if (forcedLocale.length() >= 2) {
478                 forcedLocale = forcedLocale.substring(0, 2);
479             }
480         }
481         return forcedLocale;
482     }
483     /**
484      * If locales for infocenter specified in prefernces or as command line
485      * parameters, this methods stores these locales in locales local variable
486      * for later access.
487      */

488     private static synchronized void initializeNL() {
489         if (defaultLocale != null) {
490             // already initialized
491
return;
492         }
493         initializeLocales();
494         if ((BaseHelpSystem.getMode() == BaseHelpSystem.MODE_INFOCENTER)) {
495             initializeIcDirection();
496         }
497
498     }
499     /**
500      *
501      */

502     private static void initializeLocales() {
503         // initialize default locale
504
defaultLocale = Platform.getNL();
505         if (defaultLocale == null) {
506             defaultLocale = Locale.getDefault().toString();
507         }
508         if (BaseHelpSystem.getMode() != BaseHelpSystem.MODE_INFOCENTER) {
509             return;
510         }
511
512         // locale strings as passed in command line or in preferences
513
List JavaDoc infocenterLocales = null;
514
515         // first check if locales passed as command line arguments
516
String JavaDoc[] args = Platform.getCommandLineArgs();
517         boolean localeOption = false;
518         for (int i = 0; i < args.length; i++) {
519             if ("-locales".equalsIgnoreCase(args[i])) { //$NON-NLS-1$
520
localeOption = true;
521                 infocenterLocales = new ArrayList JavaDoc();
522                 continue;
523             } else if (args[i].startsWith("-")) { //$NON-NLS-1$
524
localeOption = false;
525                 continue;
526             }
527             if (localeOption) {
528                 infocenterLocales.add(args[i]);
529             }
530         }
531         // if no locales from command line, get them from preferences
532
if (infocenterLocales == null) {
533             StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(HelpBasePlugin
534                     .getDefault().getPluginPreferences().getString("locales"), //$NON-NLS-1$
535
" ,\t"); //$NON-NLS-1$
536
while (tokenizer.hasMoreTokens()) {
537                 if (infocenterLocales == null) {
538                     infocenterLocales = new ArrayList JavaDoc();
539                 }
540                 infocenterLocales.add(tokenizer.nextToken());
541             }
542         }
543
544         // format locales and collect in a set for lookup
545
if (infocenterLocales != null) {
546             locales = new HashSet JavaDoc(10, 0.4f);
547             for (Iterator JavaDoc it = infocenterLocales.iterator(); it.hasNext();) {
548                 String JavaDoc locale = (String JavaDoc) it.next();
549                 if (locale.length() >= 5) {
550                     locales.add(locale.substring(0, 2).toLowerCase(Locale.ENGLISH) + "_" //$NON-NLS-1$
551
+ locale.substring(3, 5).toUpperCase(Locale.ENGLISH));
552
553                 } else if (locale.length() >= 2) {
554                     locales.add(locale.substring(0, 2).toLowerCase(Locale.ENGLISH));
555                 }
556             }
557         }
558     }
559     
560     private static void initializeIcDirection() {
561         // from property
562
String JavaDoc orientation = System.getProperty("eclipse.orientation"); //$NON-NLS-1$
563
if ("rtl".equals(orientation)) { //$NON-NLS-1$
564
infocenterDirection = INFOCENTER_DIRECTION_RTL;
565             return;
566         } else if ("ltr".equals(orientation)) { //$NON-NLS-1$
567
infocenterDirection = INFOCENTER_DIRECTION_LTR;
568             return;
569         }
570         // from command line
571
String JavaDoc[] args = Platform.getCommandLineArgs();
572         for (int i = 0; i < args.length; i++) {
573             if ("-dir".equalsIgnoreCase(args[i])) { //$NON-NLS-1$
574
if ((i + 1) < args.length
575                         && "rtl".equalsIgnoreCase(args[i + 1])) { //$NON-NLS-1$
576
infocenterDirection = INFOCENTER_DIRECTION_RTL;
577                     return;
578                 }
579                 infocenterDirection = INFOCENTER_DIRECTION_LTR;
580                 return;
581             }
582         }
583         // by client locale
584
}
585     
586     public static boolean isRTL(HttpServletRequest JavaDoc request,
587             HttpServletResponse JavaDoc response) {
588         if (BaseHelpSystem.getMode() != BaseHelpSystem.MODE_INFOCENTER) {
589             return BaseHelpSystem.isRTL();
590         }
591         {
592             if (infocenterDirection == INFOCENTER_DIRECTION_RTL) {
593                 return true;
594             } else if (infocenterDirection == INFOCENTER_DIRECTION_LTR) {
595                 return false;
596             }
597             String JavaDoc locale = getLocale(request, response);
598             if (locale.startsWith("ar") || locale.startsWith("fa") //$NON-NLS-1$ //$NON-NLS-2$
599
|| locale.startsWith("he") || locale.startsWith("iw") //$NON-NLS-1$ //$NON-NLS-2$
600
| locale.startsWith("ur")) { //$NON-NLS-1$
601
return true;
602             }
603             return false;
604         }
605     }
606     
607     /*
608      * Get the version from a string of the form mm.nn
609      */

610     private static int getMajorVersion(String JavaDoc version) {
611         int result = 0;
612         for (int i = 0; i < version.length(); i++) {
613             char next = version.charAt(i);
614             if (next >= '0' && next <= '9') {
615                 result = result * 10 + next - '0';
616             } else {
617                 break;
618             }
619         }
620         return result;
621     }
622
623     public static boolean isAdvanced(String JavaDoc agent) {
624             if (agent == null) return false;
625         if (isIE(agent) && "5.5".compareTo(getIEVersion(agent)) <= 0) return true; //$NON-NLS-1$
626
if (isMozilla(agent) && isGecko(agent)) return true;
627         if (isSafari(agent) && "120".compareTo(getSafariVersion(agent)) <= 0) return true; //$NON-NLS-1$
628
if (isOpera(agent) && getMajorVersion(getOperaVersion(agent)) >= 9) return true;
629         return false;
630     }
631 }
632
Popular Tags