KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > gargoylesoftware > htmlunit > BrowserVersion


1 /*
2  * Copyright (c) 2002, 2005 Gargoyle Software Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * 3. The end-user documentation included with the redistribution, if any, must
13  * include the following acknowledgment:
14  *
15  * "This product includes software developed by Gargoyle Software Inc.
16  * (http://www.GargoyleSoftware.com/)."
17  *
18  * Alternately, this acknowledgment may appear in the software itself, if
19  * and wherever such third-party acknowledgments normally appear.
20  * 4. The name "Gargoyle Software" must not be used to endorse or promote
21  * products derived from this software without prior written permission.
22  * For written permission, please contact info@GargoyleSoftware.com.
23  * 5. Products derived from this software may not be called "HtmlUnit", nor may
24  * "HtmlUnit" appear in their name, without prior written permission of
25  * Gargoyle Software Inc.
26  *
27  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
28  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
29  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARGOYLE
30  * SOFTWARE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
33  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
36  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  */

38 package com.gargoylesoftware.htmlunit;
39
40
41 /**
42  * Objects of this class represent one specific version of a given browser. Predefined
43  * constants are provided for common browser versions.
44  *
45  * If you wish to create a BrowserVersion for a browser that doesn't have a constant defined
46  * but aren't sure what values to pass into the constructor then point your browser at
47  * <a HREF="http://htmlunit.sourceforge.net/cgi-bin/browserVersion">
48  * http://htmlunit.sourceforge.net/cgi-bin/browserVersion</a>
49  * and the code will be generated for you.
50  *
51  * @version $Revision: 100 $
52  * @author <a HREF="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
53  * @author Daniel Gredler
54  * @author Marc Guillemot
55  * @author Chris Erskine
56  */

57 public class BrowserVersion {
58     private String JavaDoc applicationCodeName_ = APP_CODE_NAME;
59     private String JavaDoc applicationMinorVersion_ = "0";
60     private String JavaDoc applicationName_;
61     private String JavaDoc applicationVersion_;
62     private String JavaDoc browserLanguage_ = LANGUAGE_ENGLISH_US;
63     private String JavaDoc cpuClass_ = CPU_CLASS_X86;
64     private boolean onLine_ = true;
65     private String JavaDoc platform_ = PLATFORM_WIN32;
66     private String JavaDoc systemLanguage_ = LANGUAGE_ENGLISH_US;
67     private String JavaDoc userAgent_;
68     private String JavaDoc userLanguage_ = LANGUAGE_ENGLISH_US;
69     private String JavaDoc javaScriptVersion_;
70     private float javaScriptVersionNumeric_;
71     private float browserVersionNumeric_;
72
73     /** Application code name for both Microsoft Internet Explorer and Netscape series */
74     public static final String JavaDoc APP_CODE_NAME = "Mozilla";
75
76     /** Application name for the Microsoft Internet Explorer series of browsers */
77     public static final String JavaDoc INTERNET_EXPLORER = "Microsoft Internet Explorer";
78
79     /** Application name the Netscape navigator series of browsers */
80     public static final String JavaDoc NETSCAPE = "Netscape";
81
82     /** United States English language identifier. */
83     public static final String JavaDoc LANGUAGE_ENGLISH_US = "en-us";
84
85     /** The X86 CPU class. */
86     public static final String JavaDoc CPU_CLASS_X86 = "x86";
87
88     /** The WIN32 platform. */
89     public static final String JavaDoc PLATFORM_WIN32 = "Win32";
90
91     /**
92      * A fake browser that supports all the new features. This constant is used whenever
93      * you don't care which browser is being simulated.
94      */

95     public static final BrowserVersion FULL_FEATURED_BROWSER = new BrowserVersion(
96         INTERNET_EXPLORER, "4.0 (compatible; MSIE 6.0b; Windows 98)",
97         "Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)", "1.2", 6);
98
99     /** Mozilla 1.0 */
100     public static final BrowserVersion MOZILLA_1_0 = new BrowserVersion(
101         NETSCAPE, "5.0 (Windows; en-US)",
102         "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.0) Gecko/20020530", "1.2", 6);
103
104     /** Netscape 4.79 */
105     public static final BrowserVersion NETSCAPE_4_7_9 = new BrowserVersion(
106         NETSCAPE, "4.79 [en] (Windows NT 5.0; U)",
107         "Mozilla/4.79 [en] (Windows NT 5.0; U)", "1.2", 4.79f);
108
109     /** Netscape 6.2.3 */
110     public static final BrowserVersion NETSCAPE_6_2_3 = new BrowserVersion(
111         NETSCAPE, "5.0 (Windows; en-US)",
112         "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US;rv:0.9.4.1) Gecko/20020508 Netscape6/6.2.3",
113         "1.2", 6);
114
115     /** Internet explorer 6.0 */
116     public static final BrowserVersion INTERNET_EXPLORER_6_0 = new BrowserVersion(
117         INTERNET_EXPLORER, "4.0 (compatible; MSIE 6.0b; Windows 98)",
118         "4.0 (compatible; MSIE 6.0; Windows 98)", "1.2", 6);
119
120     private static BrowserVersion DefaultBrowserVersion_ = FULL_FEATURED_BROWSER;
121
122
123     /**
124      * Instantiate one.
125      *
126      * @param applicationName The name of the application
127      * @param applicationVersion The version string of the application
128      * @param userAgent The user agent string that will be sent to the server
129      * @param javaScriptVersion The version of JavaScript
130      * @param browserVersionNumeric The floating number version of the browser
131      */

132     public BrowserVersion( final String JavaDoc applicationName, final String JavaDoc applicationVersion,
133         final String JavaDoc userAgent, final String JavaDoc javaScriptVersion, final float browserVersionNumeric) {
134
135         applicationName_ = applicationName;
136         setApplicationVersion(applicationVersion);
137         userAgent_ = userAgent;
138         setJavaScriptVersion(javaScriptVersion);
139         browserVersionNumeric_ = browserVersionNumeric;
140     }
141
142
143     /**
144      * Return the default version that is used whenever a specific version isn't specified.
145      * @return The default version.
146      */

147     public static BrowserVersion getDefault() {
148         return DefaultBrowserVersion_;
149     }
150
151
152     /**
153      * Set the default version that is used whenever a specific version isn't specified.
154      * @param newBrowserVersion The new default version.
155      */

156     public static void setDefault( final BrowserVersion newBrowserVersion ) {
157         Assert.notNull("newBrowserVersion", newBrowserVersion);
158         DefaultBrowserVersion_ = newBrowserVersion;
159     }
160
161
162     /**
163      * Returns <tt>true</tt> if this <tt>BrowserVersion</tt> instance represents some
164      * version of Microsoft Internet Explorer.
165      * @return Whether or not this version is a version of IE.
166      */

167     public final boolean isIE() {
168         return INTERNET_EXPLORER.equals( getApplicationName() );
169     }
170
171
172     /**
173      * Returns <tt>true</tt> if this <tt>BrowserVersion</tt> instance represents some
174      * version of a Netscape browser, including Mozilla and Firefox.
175      * @return Whether or not this version is a version of a Netscape browser.
176      */

177     public final boolean isNetscape() {
178         return NETSCAPE.equals( getApplicationName() );
179     }
180
181
182     /**
183      * Return the application code name, for example "Mozilla".
184      * Default value is {@link #APP_CODE_NAME} if not explicitely configured.
185      * @return The application code name.
186      * @see <a HREF="http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/appcodename.asp">
187      * MSDN documentation</a>
188      */

189     public String JavaDoc getApplicationCodeName() {
190         return applicationCodeName_;
191     }
192
193
194     /**
195      * Return the application minor version, for example "0".
196      * Default value is "0" if not explicitely configured.
197      * @return The application minor version.
198      * @see <a HREF="http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/appminorversion.asp">
199      * MSDN documentation</a>
200      */

201     public String JavaDoc getApplicationMinorVersion() {
202         return applicationMinorVersion_;
203     }
204
205
206     /**
207      * Return the application name, for example "Microsoft Internet Explorer".
208      * @return The application name.
209      * @see <a HREF="http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/appname.asp">
210      * MSDN documentation</a>
211      */

212     public String JavaDoc getApplicationName() {
213         return applicationName_;
214     }
215
216
217     /**
218      * Return the application version, for example "4.0 (compatible; MSIE 6.0b; Windows 98)".
219      * @return The application version.
220      * @see <a HREF="http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/appversion.asp">
221      * MSDN documentation</a>
222      */

223     public String JavaDoc getApplicationVersion() {
224         return applicationVersion_;
225     }
226
227
228     /**
229      * Return the browser application language, for example "en-us".
230      * Default value is {@link #LANGUAGE_ENGLISH_US} if not explicitely configured.
231      * @return The browser application language.
232      * @see <a HREF="http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/browserlanguage.asp">
233      * MSDN documentation</a>
234      */

235     public String JavaDoc getBrowserLanguage() {
236         return browserLanguage_;
237     }
238
239
240     /**
241      * Return the type of CPU in the machine, for example "x86".
242      * Default value is {@link #CPU_CLASS_X86} if not explicitely configured.
243      * @return The type of CPU in the machine.
244      * @see <a HREF="http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/cpuclass.asp">
245      * MSDN documentation</a>
246      */

247     public String JavaDoc getCpuClass() {
248         return cpuClass_;
249     }
250
251
252     /**
253      * Return <tt>true</tt> if the browser is currently online.
254      * Default value is <code>true</code> if not explicitely configured.
255      * @return <tt>true</tt> if the browser is currently online.
256      * @see <a HREF="http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/online.asp">
257      * MSDN documentation</a>
258      */

259     public boolean isOnLine() {
260         return onLine_;
261     }
262
263
264     /**
265      * Return the platform on which the application is running, for example "Win32".
266      * Default value is {@link #PLATFORM_WIN32} if not explicitely configured.
267      * @return the platform on which the application is running.
268      * @see <a HREF="http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/platform.asp">
269      * MSDN documentation</a>
270      */

271     public String JavaDoc getPlatform() {
272         return platform_;
273     }
274
275
276     /**
277      * Return the system language, for example "en-us".
278      * Default value is {@link #LANGUAGE_ENGLISH_US} if not explicitely configured.
279      * @return The system language.
280      * @see <a HREF="http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/systemlanguage.asp">
281      * MSDN documentation</a>
282      */

283     public String JavaDoc getSystemLanguage() {
284         return systemLanguage_;
285     }
286
287
288     /**
289      * Return the user agent string, for example "Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)".
290      * @return The user agent string.
291      */

292     public String JavaDoc getUserAgent() {
293         return userAgent_;
294     }
295
296
297     /**
298      * Return the user language, for example "en-us".
299      * Default value is {@link #LANGUAGE_ENGLISH_US} if not explicitely configured.
300      * @return The user language.
301      * @see <a HREF="http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/userlanguage.asp">
302      * MSDN documentation</a>
303      */

304     public String JavaDoc getUserLanguage() {
305         return userLanguage_;
306     }
307
308
309     /**
310      * Return the version of javascript used by the browser, for example "1.2".
311      * @return the version of javascript used by the browser.
312      */

313     public String JavaDoc getJavaScriptVersion() {
314         return javaScriptVersion_;
315     }
316
317     /**
318      * @param applicationCodeName The applicationCodeName to set.
319      */

320     public void setApplicationCodeName(final String JavaDoc applicationCodeName) {
321         applicationCodeName_ = applicationCodeName;
322     }
323
324     /**
325      * @param applicationMinorVersion The applicationMinorVersion to set.
326      */

327     public void setApplicationMinorVersion(final String JavaDoc applicationMinorVersion) {
328         applicationMinorVersion_ = applicationMinorVersion;
329     }
330
331     /**
332      * @param applicationName The applicationName to set.
333      */

334     public void setApplicationName(final String JavaDoc applicationName) {
335         applicationName_ = applicationName;
336     }
337
338     /**
339      * @param applicationVersion The applicationVersion to set.
340      */

341     public void setApplicationVersion(final String JavaDoc applicationVersion) {
342         applicationVersion_ = applicationVersion;
343     }
344
345     /**
346      * @param browserLanguage The browserLanguage to set.
347      */

348     public void setBrowserLanguage(final String JavaDoc browserLanguage) {
349         browserLanguage_ = browserLanguage;
350     }
351
352     /**
353      * @param cpuClass The cpuClass to set.
354      */

355     public void setCpuClass(final String JavaDoc cpuClass) {
356         cpuClass_ = cpuClass;
357     }
358
359     /**
360      * @param javaScriptVersion The javaScriptVersion to set.
361      */

362     public void setJavaScriptVersion(final String JavaDoc javaScriptVersion) {
363         javaScriptVersion_ = javaScriptVersion;
364         javaScriptVersionNumeric_ = Float.parseFloat(javaScriptVersion);
365     }
366
367     /**
368      * @param onLine The onLine to set.
369      */

370     public void setOnLine(final boolean onLine) {
371         onLine_ = onLine;
372     }
373
374     /**
375      * @param platform The platform to set.
376      */

377     public void setPlatform(final String JavaDoc platform) {
378         platform_ = platform;
379     }
380
381     /**
382      * @param systemLanguage The systemLanguage to set.
383      */

384     public void setSystemLanguage(final String JavaDoc systemLanguage) {
385         systemLanguage_ = systemLanguage;
386     }
387
388     /**
389      * @param userAgent The userAgent to set.
390      */

391     public void setUserAgent(final String JavaDoc userAgent) {
392         userAgent_ = userAgent;
393     }
394
395     /**
396      * @param userLanguage The userLanguage to set.
397      */

398     public void setUserLanguage(final String JavaDoc userLanguage) {
399         userLanguage_ = userLanguage;
400     }
401     /**
402      * @param browserVersion The browserVersion to set.
403      */

404     public void setBrowserVersion(float browserVersion) {
405         browserVersionNumeric_ = browserVersion;
406     }
407     /**
408      * @return Returns the browserVersionNumeric.
409      */

410     public float getBrowserVersionNumeric() {
411         return browserVersionNumeric_;
412     }
413     /**
414      * @return Returns the javaScriptVersionNumeric.
415      */

416     public float getJavaScriptVersionNumeric() {
417         return javaScriptVersionNumeric_;
418     }
419 }
420
Popular Tags