1 19 20 package com.lutris.airsent.presentation; 21 22 import com.lutris.airsent.presentation.*; 23 import com.lutris.appserver.server.httpPresentation.*; 24 import javax.servlet.http.HttpServletRequest ; 25 import org.enhydra.xml.xmlc.*; 26 import org.w3c.dom.*; 27 33 public class DeviceUtils { 34 44 public static void rerouteForContent(HttpPresentationComms comms) 45 throws AirSentPresentationException { 46 String header = null; 47 String userAgent = null; 48 String flashClient = null; 49 try { 50 flashClient = comms.request.getParameter("flash"); 51 userAgent = comms.request.getHeader("User-Agent"); 52 if (flashClient != null) { 53 comms.response.setEncoding("ISO8859_1"); 54 throw new ClientPageRedirectException(AirSentConstants.XML_PAGE); 55 } 56 else if(userAgent != null && userAgent.indexOf("DoCoMo") != -1) { 57 throw new ClientPageRedirectException(AirSentConstants.CHTML_PAGE); 58 } 59 else if(userAgent != null && userAgent.indexOf("Pixo") != -1) { 60 throw new ClientPageRedirectException(AirSentConstants.CHTML_PAGE); 61 } 62 else if(userAgent != null && userAgent.indexOf("RIM") != -1) { 63 throw new ClientPageRedirectException(AirSentConstants.CHTML_PAGE); 64 } 65 else if(userAgent != null && userAgent.indexOf("Digital Paths") != -1) { 66 throw new ClientPageRedirectException(AirSentConstants.CHTML_PAGE); 67 } 68 else if(userAgent != null && userAgent.indexOf("UP.") != -1) { 69 throw new ClientPageRedirectException(AirSentConstants.WAP_PAGE); 70 } 71 else if ((header = comms.request.getHeader(AirSentConstants.ACCEPT)) 72 == null) { 73 return; 75 }else if (header != null && header.indexOf(AirSentConstants.HTML_CONTENT) != -1 || 76 flashClient != null) { 77 return; 78 } 79 else if (header != null && header.indexOf(AirSentConstants.XML_CONTENT) != -1 || 80 flashClient != null) { 81 throw new ClientPageRedirectException(AirSentConstants.XML_PAGE); 82 } 83 else if ( header != null && header.indexOf(AirSentConstants.WAP_CONTENT) != -1) { 84 throw new ClientPageRedirectException(AirSentConstants.WAP_PAGE); 85 } 86 else if (header != null && header.indexOf(AirSentConstants.XHTML_CONTENT) 87 != -1) {} 88 else if (header != null && header.indexOf(AirSentConstants.CHTML_CONTENT) != -1) { 89 } 91 else { 92 if(userAgent == null) { 93 throw new ClientPageRedirectException(AirSentConstants.CHTML_PAGE); 94 } 95 } 96 } catch (Exception e) { 97 throw new AirSentPresentationException("Trouble rerouting header:" 98 + header, e); 99 } 100 } 101 102 108 public static String getPageName(HttpPresentationComms comms, String poName) 109 throws AirSentPresentationException { 110 String header = null; 111 String userAgent = null; 112 String flashClient = null; 113 114 try { 115 flashClient = comms.request.getParameter("flash"); 116 userAgent = comms.request.getHeader("User-Agent"); 117 if (flashClient != null) { 118 comms.response.setEncoding("ISO-8859-1"); 119 return poName + "XML"; 120 } 121 else if(userAgent != null && userAgent.indexOf("DoCoMo") != -1) { 125 return poName + "CHTML"; 126 } else if(userAgent != null && userAgent.indexOf("Pixo") != -1) { 127 return poName + "CHTML"; 128 } else if(userAgent != null && userAgent.indexOf("RIM") != -1) { 129 return poName + "HTML"; 130 } else if(userAgent != null && userAgent.indexOf("UP.") != -1) { 131 return poName + "WML"; 132 } else if ((header = comms.request.getHeader(AirSentConstants.ACCEPT)) 133 == null) { 134 return null; 136 }else if (header.indexOf(AirSentConstants.HTML_CONTENT) != -1) { 137 return poName + "HTML"; 139 } else if (header.indexOf(AirSentConstants.XML_CONTENT) != -1) { 140 return poName + "XML"; 141 } else if (header.indexOf(AirSentConstants.WAP_CONTENT) != -1) { 142 return poName + "WML"; 143 } else if (header.indexOf(AirSentConstants.XHTML_CONTENT) != -1) { 144 return poName + "XHTML"; 145 } else if (header.indexOf(AirSentConstants.CHTML_CONTENT) != -1) { 146 return poName + "CHTML"; 147 } 148 else { 149 if(userAgent == null) { 150 return poName + "CHTML"; 152 } 153 else { 154 return poName + "HTML"; 156 } 157 } 158 } catch (Exception e) { 159 throw new AirSentPresentationException("Trouble rerouting header:" 160 + header, e); 161 } 162 } 163 164 169 public static void setURLTimeStamp(org.enhydra.xml.xmlc.XMLObject dom) { 170 DeviceUtils.setNodeTimeStamp(dom.getDocumentElement()); 171 } 172 173 174 178 public static void setNodeTimeStamp(Node node) { 179 if (Node.ELEMENT_NODE == node.getNodeType()){ 180 String urlValue = null; 181 if(!(urlValue = ((Element)node).getAttribute("href")).equals("")) { 182 ((Element)node).setAttribute("href", DeviceUtils.getTimeStampParam(urlValue)); 183 } 184 NodeList nodeList = node.getChildNodes(); 185 for(int curNode = 0; curNode < nodeList.getLength(); curNode++){ 186 DeviceUtils.setNodeTimeStamp(nodeList.item(curNode)); 187 } 188 } 189 } 190 191 196 public static String getTimeStampParam(String url) { 197 String delimiter = url.indexOf("?") != -1 ? "&" : "?"; 198 return url + delimiter + "timestamp=" + System.currentTimeMillis(); 199 } 200 201 202 203 204 205 } 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
| Popular Tags
|