Source Code Cross Referenced for UserAgentInfo.java in  » Web-Framework » jWic » de » jwic » base » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » jWic » de.jwic.base 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005 jWic group (http://www.jwic.de)
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         *
016:         * de.jwic.web.UserAgentInfo
017:         * Created on 14.02.2006
018:         * $Id: UserAgentInfo.java,v 1.3 2006/08/14 09:34:58 lordsam Exp $
019:         */
020:        package de.jwic.base;
021:
022:        import java.io.Serializable;
023:
024:        import javax.servlet.http.HttpServletRequest;
025:
026:        /**
027:         * Contains information about the user agent (browser). The type and version is
028:         * identified from the requests header informations. 
029:         * @author Florian Lippisch
030:         * @version $Revision: 1.3 $
031:         */
032:        public class UserAgentInfo implements  Serializable {
033:
034:            private static final long serialVersionUID = 1L;
035:
036:            public final static String TYPE_IE = "IE";
037:            public final static String TYPE_NS = "NS";
038:            public final static String TYPE_FIREFOX = "FIREFOX";
039:            public final static String TYPE_OPERA = "OPERA";
040:            public final static String TYPE_KONQUEROR = "KONQUEROR";
041:            public final static String TYPE_UNKNOWN = "UNKNOWN";
042:
043:            private final static String IDENTIFIER_IE = "compatible; MSIE ";
044:            private final static String IDENTIFIER_FIREFOX = "Firefox/";
045:            private final static String IDENTIFIER_OPERA = "Opera/";
046:            private final static String IDENTIFIER_NETSCAPE = "Netscape/";
047:            private final static String IDENTIFIER_KONQUEROR = "Konqueror/";
048:            private final static String IDENTIFIER_GOOGLEBOT = "Googlebot";
049:
050:            private String type = TYPE_UNKNOWN;
051:            private String userAgentID = null;
052:            private String version = "";
053:
054:            private boolean bot = false;
055:
056:            /**
057:             * Construct a new UserAgentInfo based upon the header informations in the request.
058:             * @param request
059:             */
060:            public UserAgentInfo(HttpServletRequest request) {
061:
062:                if (request != null) {
063:                    userAgentID = request.getHeader("user-agent");
064:                    if (userAgentID != null) {
065:
066:                        int idx = userAgentID.indexOf(IDENTIFIER_IE);
067:                        if (idx != -1) {
068:                            // its an IE
069:                            setType(TYPE_IE);
070:                            // identify the version
071:                            int end = userAgentID.indexOf(";", idx
072:                                    + IDENTIFIER_IE.length());
073:                            if (end != -1) {
074:                                setVersion(userAgentID.substring(idx
075:                                        + IDENTIFIER_IE.length(), end));
076:                            }
077:                        } else if ((idx = userAgentID
078:                                .indexOf(IDENTIFIER_FIREFOX)) != -1) {
079:                            // its a firefox
080:                            setType(TYPE_FIREFOX);
081:                            // identify the version
082:                            setVersion(userAgentID.substring(idx
083:                                    + IDENTIFIER_FIREFOX.length()));
084:
085:                        } else if ((idx = userAgentID.indexOf(IDENTIFIER_OPERA)) != -1) {
086:                            // its a opera
087:                            setType(TYPE_OPERA);
088:                            // identify the version
089:                            int end = userAgentID.indexOf(" ", idx
090:                                    + IDENTIFIER_OPERA.length());
091:                            if (end != -1) {
092:                                setVersion(userAgentID.substring(idx
093:                                        + IDENTIFIER_OPERA.length(), end));
094:                            }
095:                        } else if ((idx = userAgentID
096:                                .indexOf(IDENTIFIER_KONQUEROR)) != -1) {
097:                            // its a opera
098:                            setType(TYPE_KONQUEROR);
099:                            // identify the version
100:                            int end = userAgentID.indexOf(")", idx
101:                                    + IDENTIFIER_KONQUEROR.length());
102:                            if (end != -1) {
103:                                setVersion(userAgentID.substring(idx
104:                                        + IDENTIFIER_KONQUEROR.length(), end));
105:                            }
106:                        } else if ((idx = userAgentID
107:                                .indexOf(IDENTIFIER_NETSCAPE)) != -1) {
108:                            // its a opera
109:                            setType(TYPE_NS);
110:                            // identify the version
111:                            setVersion(userAgentID.substring(idx
112:                                    + IDENTIFIER_NETSCAPE.length()));
113:
114:                        } else if (userAgentID.indexOf(IDENTIFIER_GOOGLEBOT) != -1) {
115:                            bot = true;
116:                            setType("GOOGLEBOT");
117:
118:                        } else if (userAgentID.indexOf("NutchCVS") == 0) {
119:                            bot = true;
120:
121:                        } else if (userAgentID.indexOf("msnbot") == 0) {
122:                            bot = true;
123:                            setType("MSNBOT");
124:
125:                        } else if (userAgentID.indexOf("Bot") != -1
126:                                || userAgentID.indexOf("bot") != -1) {
127:                            // an unknown bot
128:                            bot = true;
129:
130:                        } else if (userAgentID.indexOf("Mozilla/4.76") == 0) {
131:                            setType(TYPE_NS);
132:                            setVersion("4.7");
133:                        }
134:                    }
135:                }
136:            }
137:
138:            /**
139:             * Returns true if the user agent is an Internet Explorer.
140:             * @return
141:             */
142:            public boolean isIE() {
143:                return type.equals(TYPE_IE);
144:            }
145:
146:            /**
147:             * Returns true if the user agent is a Netscape.
148:             * @return
149:             */
150:            public boolean isNS() {
151:                return type.equals(TYPE_NS);
152:            }
153:
154:            /**
155:             * Returns true if the user agent is a Firefox.
156:             * @return
157:             */
158:            public boolean isFirefox() {
159:                return type.equals(TYPE_FIREFOX);
160:            }
161:
162:            /**
163:             * Returns true if the user agent is Opera.
164:             * @return
165:             */
166:            public boolean isOpera() {
167:                return type.equals(TYPE_OPERA);
168:            }
169:
170:            /**
171:             * Returns true if the user agent is Konqueror.
172:             * @return
173:             */
174:            public boolean isKonqueror() {
175:                return type.equals(TYPE_KONQUEROR);
176:            }
177:
178:            /**
179:             * @return Returns the type.
180:             */
181:            public String getType() {
182:                return type;
183:            }
184:
185:            /**
186:             * @param type The type to set.
187:             */
188:            private void setType(String type) {
189:                this .type = type;
190:            }
191:
192:            /**
193:             * @return Returns the userAgentID.
194:             */
195:            public String getUserAgentID() {
196:                return userAgentID;
197:            }
198:
199:            /**
200:             * @return Returns the version.
201:             */
202:            public String getVersion() {
203:                return version;
204:            }
205:
206:            /**
207:             * @param version The version to set.
208:             */
209:            public void setVersion(String version) {
210:                this .version = version;
211:            }
212:
213:            /**
214:             * Returns a string representation of this user agent.
215:             */
216:            public String toString() {
217:                return type + " " + version;
218:            }
219:
220:            /**
221:             * @return Returns the bot.
222:             */
223:            public boolean isBot() {
224:                return bot;
225:            }
226:
227:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.