Source Code Cross Referenced for DeviceUtils.java in  » J2EE » Enhydra-Demos » com » lutris » airsent » presentation » 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 » J2EE » Enhydra Demos » com.lutris.airsent.presentation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 1999-2001 Lutris Technologies, Inc. All Rights
003:         * Reserved.
004:         * 
005:         * This source code file is distributed by Lutris Technologies, Inc. for
006:         * use only by licensed users of product(s) that include this source
007:         * file. Use of this source file or the software that uses it is covered
008:         * by the terms and conditions of the Lutris Enhydra Development License
009:         * Agreement included with this product.
010:         * 
011:         * This Software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
012:         * ANY KIND, either express or implied. See the License for the specific terms
013:         * governing rights and limitations under the License.
014:         * 
015:         * Contributor(s):
016:         * 
017:         * $Id: DeviceUtils.java,v 1.1 2006-09-11 12:29:11 sinisa Exp $
018:         */
019:
020:        package com.lutris.airsent.presentation;
021:
022:        import com.lutris.airsent.presentation.*;
023:        import com.lutris.appserver.server.httpPresentation.*;
024:        import javax.servlet.http.HttpServletRequest;
025:        import org.enhydra.xml.xmlc.*;
026:        import org.w3c.dom.*;
027:
028:        /**
029:         *  Provides utilities for outputing and forewarding to devices. 
030:         * 
031:         * 
032:         * 
033:         */
034:        public class DeviceUtils {
035:            /**
036:             * Method that determines which content to output based on
037:             * the accept type.
038:             * Current types:
039:             * text/html
040:             * text/xml
041:             * text/vnd.wap.wml
042:             * 
043:             * 
044:             */
045:            public static void rerouteForContent(HttpPresentationComms comms)
046:                    throws AirSentPresentationException {
047:                String header = null;
048:                String userAgent = null;
049:                String flashClient = null;
050:                try {
051:                    flashClient = comms.request.getParameter("flash");
052:                    userAgent = comms.request.getHeader("User-Agent");
053:                    if (flashClient != null) {
054:                        comms.response.setEncoding("ISO8859_1");
055:                        throw new ClientPageRedirectException(
056:                                AirSentConstants.XML_PAGE);
057:                    } else if (userAgent != null
058:                            && userAgent.indexOf("DoCoMo") != -1) {
059:                        throw new ClientPageRedirectException(
060:                                AirSentConstants.CHTML_PAGE);
061:                    } else if (userAgent != null
062:                            && userAgent.indexOf("Pixo") != -1) {
063:                        throw new ClientPageRedirectException(
064:                                AirSentConstants.CHTML_PAGE);
065:                    } else if (userAgent != null
066:                            && userAgent.indexOf("RIM") != -1) {
067:                        throw new ClientPageRedirectException(
068:                                AirSentConstants.CHTML_PAGE);
069:                    } else if (userAgent != null
070:                            && userAgent.indexOf("Digital Paths") != -1) {
071:                        throw new ClientPageRedirectException(
072:                                AirSentConstants.CHTML_PAGE);
073:                    } else if (userAgent != null
074:                            && userAgent.indexOf("UP.") != -1) {
075:                        throw new ClientPageRedirectException(
076:                                AirSentConstants.WAP_PAGE);
077:                    } else if ((header = comms.request
078:                            .getHeader(AirSentConstants.ACCEPT)) == null) {
079:                        // Just display HTML
080:                        return;
081:                    } else if (header != null
082:                            && header.indexOf(AirSentConstants.HTML_CONTENT) != -1
083:                            || flashClient != null) {
084:                        return;
085:                    } else if (header != null
086:                            && header.indexOf(AirSentConstants.XML_CONTENT) != -1
087:                            || flashClient != null) {
088:                        throw new ClientPageRedirectException(
089:                                AirSentConstants.XML_PAGE);
090:                    } else if (header != null
091:                            && header.indexOf(AirSentConstants.WAP_CONTENT) != -1) {
092:                        throw new ClientPageRedirectException(
093:                                AirSentConstants.WAP_PAGE);
094:                    } else if (header != null
095:                            && header.indexOf(AirSentConstants.XHTML_CONTENT) != -1) {
096:                    } else if (header != null
097:                            && header.indexOf(AirSentConstants.CHTML_CONTENT) != -1) {
098:                        //????
099:                    } else {
100:                        if (userAgent == null) {
101:                            throw new ClientPageRedirectException(
102:                                    AirSentConstants.CHTML_PAGE);
103:                        }
104:                    }
105:                } catch (Exception e) {
106:                    throw new AirSentPresentationException(
107:                            "Trouble rerouting header:" + header, e);
108:                }
109:            }
110:
111:            /**
112:             * Gets the suffix of a PO name based on the
113:             * accept type.
114:             * @param String PO classname
115:             * @return PO new full classname with suffix.
116:             */
117:            public static String getPageName(HttpPresentationComms comms,
118:                    String poName) throws AirSentPresentationException {
119:                String header = null;
120:                String userAgent = null;
121:                String flashClient = null;
122:
123:                try {
124:                    flashClient = comms.request.getParameter("flash");
125:                    userAgent = comms.request.getHeader("User-Agent");
126:                    if (flashClient != null) {
127:                        comms.response.setEncoding("ISO-8859-1");
128:                        return poName + "XML";
129:                    }
130:                    //
131:                    //DoCoMo code thanks to Ray Mercer
132:                    //
133:                    else if (userAgent != null
134:                            && userAgent.indexOf("DoCoMo") != -1) {
135:                        return poName + "CHTML";
136:                    } else if (userAgent != null
137:                            && userAgent.indexOf("Pixo") != -1) {
138:                        return poName + "CHTML";
139:                    } else if (userAgent != null
140:                            && userAgent.indexOf("RIM") != -1) {
141:                        return poName + "HTML";
142:                    } else if (userAgent != null
143:                            && userAgent.indexOf("UP.") != -1) {
144:                        return poName + "WML";
145:                    } else if ((header = comms.request
146:                            .getHeader(AirSentConstants.ACCEPT)) == null) {
147:                        // Can't decipher accept type.
148:                        return null;
149:                    } else if (header.indexOf(AirSentConstants.HTML_CONTENT) != -1) {
150:                        //Defaulting to html.
151:                        return poName + "HTML";
152:                    } else if (header.indexOf(AirSentConstants.XML_CONTENT) != -1) {
153:                        return poName + "XML";
154:                    } else if (header.indexOf(AirSentConstants.WAP_CONTENT) != -1) {
155:                        return poName + "WML";
156:                    } else if (header.indexOf(AirSentConstants.XHTML_CONTENT) != -1) {
157:                        return poName + "XHTML";
158:                    } else if (header.indexOf(AirSentConstants.CHTML_CONTENT) != -1) {
159:                        return poName + "CHTML";
160:                    } else {
161:                        if (userAgent == null) {
162:                            //Defaulting to chtml.
163:                            return poName + "CHTML";
164:                        } else {
165:                            //Defaulting to html.
166:                            return poName + "HTML";
167:                        }
168:                    }
169:                } catch (Exception e) {
170:                    throw new AirSentPresentationException(
171:                            "Trouble rerouting header:" + header, e);
172:                }
173:            }
174:
175:            /**
176:             *Recursivly walk the dom and replace any url with the
177:             *url + a timestamp=current time in millis.
178:             **!!Hack for buggy phone caching!!
179:             */
180:            public static void setURLTimeStamp(
181:                    org.enhydra.xml.xmlc.XMLObject dom) {
182:                DeviceUtils.setNodeTimeStamp(dom.getDocumentElement());
183:            }
184:
185:            /**
186:             *Recursivly walk the DOM replacing urls.  
187:             **!!Hack for buggy phone caching!!
188:             */
189:            public static void setNodeTimeStamp(Node node) {
190:                if (Node.ELEMENT_NODE == node.getNodeType()) {
191:                    String urlValue = null;
192:                    if (!(urlValue = ((Element) node).getAttribute("href"))
193:                            .equals("")) {
194:                        ((Element) node).setAttribute("href", DeviceUtils
195:                                .getTimeStampParam(urlValue));
196:                    }
197:                    NodeList nodeList = node.getChildNodes();
198:                    for (int curNode = 0; curNode < nodeList.getLength(); curNode++) {
199:                        DeviceUtils.setNodeTimeStamp(nodeList.item(curNode));
200:                    }
201:                }
202:            }
203:
204:            /**
205:             **Append timestamp to force caching
206:             **!!Hack for buggy phone caching!!
207:             **
208:             */
209:            public static String getTimeStampParam(String url) {
210:                String delimiter = url.indexOf("?") != -1 ? "&" : "?";
211:                return url + delimiter + "timestamp="
212:                        + System.currentTimeMillis();
213:            }
214:
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.