Source Code Cross Referenced for ClientImpl.java in  » Portal » gridsphere » org » gridsphere » portletcontainer » impl » 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 » Portal » gridsphere » org.gridsphere.portletcontainer.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003:         * @version $Id: ClientImpl.java 6385 2007-10-25 14:02:26Z wehrens $
004:         */
005:        package org.gridsphere.portletcontainer.impl;
006:
007:        import org.gridsphere.portletcontainer.Client;
008:
009:        import javax.servlet.http.HttpServletRequest;
010:        import java.io.Serializable;
011:
012:        /**
013:         * The <code>ClientImpl</code> class represents the client device that the user
014:         * connects to the portal with. It defines methods to obtain information about
015:         * clients, e.g. browsers running on PCs, WAP phones, PDAs etc.
016:         */
017:        public class ClientImpl implements  Client, Serializable {
018:
019:            public static final String[] MIME_TYPES = { "text/html",
020:                    "text/vnd.wap.wml" };
021:            public static final String[] MARKUP_TYPES = { "html", "wml",
022:                    "chtml" };
023:            public static final String[] MANUFACTURER_NAMES = { "opera",
024:                    "netscape", "mozilla", "IE", "4thpass", "Alcatel",
025:                    "BlackBerry", "jBrowser", "M3Gate", "Motorola", "Sony",
026:                    "Nokia", "Panasonic", "Philips", "Sagem", "Samsung",
027:                    "Siemens", "SonyEricsson", "WinWAP" };
028:            public static final String[] WAP_IDENTIFIER = { "4thpass",
029:                    "Alcatel-", "BlackBerry/", "jBrowser", "M3GATE/", "MOT-",
030:                    "Sony CMD", "Nokia", "Panasonic", "PHILIPS", "SAGEM-",
031:                    "SAMSUNG-", "SIE-", "SonyEricsson", "WinWAP" };
032:            private String manufacturer = null;
033:            private String model = null;
034:            private String version = null;
035:            private String userAgent = null;
036:            private String mimeType = null;
037:            private String markupName = null;
038:
039:            /**
040:             * Constructs an instance of ClientImpl from a servlet request
041:             *
042:             * @param req an <code>HttpServletRequest</code>
043:             */
044:            public ClientImpl(HttpServletRequest req) {
045:                // get the user-agent string containg client browser information
046:                userAgent = req.getHeader("user-agent");
047:                //System.err.println("User-agent: " + userAgent);
048:                // parse it!
049:                // below are Mac OS X
050:                // Netscape 6.2: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US; rv:0.9.4.1) Gecko/20020315 Netscape6/6.2.2
051:                // Netscape 7.0: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US; rv:1.0.1) Gecko/20020823 Netscape/7.0
052:                // IE 5.2:       Mozilla/4.0 (compatible; MSIE 5.22; Mac_PowerPC)
053:                // Mozilla 1.0:  Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US; rv:1.0.1) Gecko/20020826
054:                // Opera 6.0b2:  Mozilla/4.0 (compatible; MSIE 5.0; Mac_PowerPC) Opera 6.0  [en]
055:
056:                // Compaq IPAQ: Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; PPC; 240x320)
057:
058:                String browserInfo = "Unknown browser";
059:                //WAP 2.0 identifification begins here:
060:                for (int identString = 0; identString < 15; identString++) {
061:                    if (userAgent == null)
062:                        continue;
063:                    if (userAgent.indexOf(WAP_IDENTIFIER[identString]) != -1) {
064:                        browserInfo = MANUFACTURER_NAMES[identString + 4];
065:                        manufacturer = MANUFACTURER_NAMES[identString + 4];
066:                        mimeType = MIME_TYPES[0];
067:                        markupName = MARKUP_TYPES[1];
068:                    }
069:                }
070:                //WAP 2.0 identification ends here
071:
072:                if (browserInfo.equals("Unknown browser")) {//WAP 2.0
073:                    if (userAgent != null) {
074:                        int i = userAgent.indexOf(" ");
075:
076:                        //System.err.println("mozilla version: " + mozillaVersion);
077:                        int j = userAgent.lastIndexOf(")");
078:
079:                        if (j >= 0) {
080:                            browserInfo = userAgent.substring(j + 1).trim();
081:                        }
082:                    }
083:                }
084:                //System.err.println("browser info: " + browserInfo);
085:                mimeType = req.getHeader("accept");
086:
087:                //System.err.println("MIME types: " + mimeTypes);
088:                // Netscape 6.2: text/xml, application/xml, application/xhtml+xml, text/html;q=0.9, image/png, image/jpeg, image/gif;q=0.2, text/plain;q=0.8, text/css, */*;q=0.1
089:                // IE 5.2:       */*
090:                // Mozilla 1.0: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1
091:                // Opera 6.0b2: text/html, image/png, image/jpeg, image/gif, image/x-xbitmap, */*
092:
093:                // get manufacturer
094:                if (browserInfo.startsWith("Opera")) {
095:                    manufacturer = MANUFACTURER_NAMES[0];
096:                } else if (browserInfo.startsWith("Gecko")) {
097:                    int i = browserInfo.indexOf(" ");
098:                    if (i > 0) {
099:                        if (browserInfo.substring(i).trim().startsWith(
100:                                "Netscape")) {
101:                            manufacturer = MANUFACTURER_NAMES[1];
102:                        } else {
103:                            manufacturer = MANUFACTURER_NAMES[2];
104:                        }
105:                    } else {
106:                        manufacturer = MANUFACTURER_NAMES[2];
107:                    }
108:                } else {
109:                    manufacturer = MANUFACTURER_NAMES[3];
110:                }
111:
112:                if (markupName == null) {//WAP 2.0
113:                    if (mimeType != null) {
114:                        int i = mimeType.indexOf("html");
115:                        if (i < 0) {
116:                            // IE 5.2 on  Mac OS X
117:                            if (mimeType.indexOf("*/*") >= 0) {
118:                                mimeType = MIME_TYPES[0];
119:                                markupName = MARKUP_TYPES[0];
120:                            }
121:                        } else {
122:                            mimeType = MIME_TYPES[0];
123:                            markupName = MARKUP_TYPES[0];
124:                        }
125:                    }
126:                }
127:                // make up version for now
128:                version = "1.0";
129:                // make up model for now
130:                model = "gridsphere model";
131:
132:                // if all else fails, it is html
133:                if (markupName == null)
134:                    markupName = MARKUP_TYPES[0];
135:                if (mimeType == null)
136:                    mimeType = MIME_TYPES[0];
137:
138:                //logRequest(req);
139:            }
140:
141:            /**
142:             * Returns the name of the manufacturer of this client, or
143:             * <code>null</code> if the name is not available.
144:             *
145:             * @return the manufacturer
146:             */
147:            public String getManufacturer() {
148:                return manufacturer;
149:            }
150:
151:            /**
152:             * Returns the name of the model of this client, or <code>null</code>
153:             * if the name is not available.
154:             *
155:             * @return the model
156:             */
157:            public String getModel() {
158:                return model;
159:            }
160:
161:            /**
162:             * Returns the version of the model of this client, or <code>null</code>
163:             * if the version is not available.
164:             *
165:             * @return the version
166:             */
167:            public String getVersion() {
168:                return version;
169:            }
170:
171:            /**
172:             * Returns the exact user agent that this client uses to identify
173:             * itself to the portal. If the client does not send a user agent,
174:             * this method returns <code>null</code>
175:             *
176:             * @return the user agent
177:             */
178:            public String getUserAgent() {
179:                return userAgent;
180:            }
181:
182:            /**
183:             * Returns the preferred mime-type that this client device supports.
184:             *
185:             * @return the mime-type
186:             */
187:            public String getMimeType() {
188:                return mimeType;
189:            }
190:
191:            /**
192:             * Returns the preferred markup name that this client device supports.
193:             *
194:             * @return the name of the markup
195:             */
196:            public String getMarkupName() {
197:                return markupName;
198:            }
199:
200:            /**
201:             * Return a <code>String</code> representation of the <code>Client</code>
202:             *
203:             * @return a <code>String</code> representation of the <code>Client</code>
204:             */
205:            public String toString() {
206:                StringBuffer sb = new StringBuffer("\n");
207:                sb.append("User-agent: " + userAgent + "\n");
208:                sb.append("manufacturer: " + manufacturer + "\n");
209:                sb.append("model: " + model + "\n");
210:                sb.append("version: " + version + "\n");
211:                sb.append("markup: " + markupName + "\n");
212:                sb.append("mimeType: " + mimeType);
213:                return sb.toString();
214:            }
215:
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.