1 20 package org.enhydra.barracuda.core.view; 21 22 import java.util.*; 23 import javax.servlet.*; 24 import javax.servlet.http.*; 25 26 import org.enhydra.barracuda.core.helper.servlet.*; 27 28 38 public class ViewUtil { 39 40 private static int HTML = 0; 42 private static int CHTML = 1; 43 private static int XML = 2; 44 private static int VXML = 3; 45 private static int WML = 4; 46 private static int XHTML_BASIC = 5; 47 private static int XHTML_STANDARD = 6; 48 49 57 public static FormatType getFormatType(HttpServletRequest req) { 58 FormatType ft = FormatType.UNKNOWN_FORMAT; 59 int baseType = getBaseType(req); 60 61 if (baseType==HTML) { 64 ft = FormatType.HTML_4_0; 65 } else if (baseType==CHTML) { 67 ft = FormatType.CHTML_1_0; 68 } else if (baseType==XML) { 70 ft = FormatType.XML_1_0; 71 } else if (baseType==VXML) { 73 ft = FormatType.VXML_1_0; 74 } else if (baseType==WML) { 76 ft = FormatType.WML_1_0; 77 } else if (baseType==XHTML_BASIC) { 79 ft = FormatType.XHTML_BASIC_1_0; 80 } else if (baseType==XHTML_STANDARD) { 82 ft = FormatType.XHTML_STANDARD_1_0; 83 } 84 85 return ft; 86 } 87 88 98 public static ScriptingType getScriptingType(HttpServletRequest req) { 99 ScriptingType st = ScriptingType.NONE; 100 if (req!=null) { 101 102 Boolean enabled = ScriptDetector.scriptingEnabled(req); 110 if (enabled!=null) { 111 if (enabled.booleanValue()==false) return ScriptingType.NONE; 112 else st = ScriptingType.JAVASCRIPT_1_0; 113 } 114 115 ClientType ct = getClientType(req); 117 118 if (ct instanceof ClientType.HtmlBrowser) { 123 if (ct instanceof ClientType.IE5x) st = ScriptingType.JAVASCRIPT_1_3; 124 else if (ct instanceof ClientType.IE4x) st = ScriptingType.JAVASCRIPT_1_2; else if (ct instanceof ClientType.IE3x) st = ScriptingType.JAVASCRIPT_1_0; 126 else if (ct instanceof ClientType.NN6x) st = ScriptingType.JAVASCRIPT_1_5; 127 else if (ct instanceof ClientType.NN4x) st = ScriptingType.JAVASCRIPT_1_3; 128 else if (ct instanceof ClientType.NN3x) st = ScriptingType.JAVASCRIPT_1_1; else if (ct instanceof ClientType.Opera4x) st = ScriptingType.JAVASCRIPT_1_3; 130 else if (ct instanceof ClientType.Html32Browser) st = ScriptingType.JAVASCRIPT_1_0; 131 } else if (ct instanceof ClientType.WmlBrowser) { 132 st = ScriptingType.WMLSCRIPT_1x; 133 } 134 } 135 return st; 136 } 137 138 146 public static ClientType getClientType(HttpServletRequest req) { 147 ClientType ct = ClientType.UNKNOWN_BROWSER; 148 chk: if (req!=null) { 149 String uas = req.getHeader("User-Agent"); 151 if (uas==null) uas = req.getHeader("user-agent"); 152 if (uas==null) break chk; 153 uas = uas.toLowerCase(); 154 155 int baseType = getBaseType(req); 156 157 if (baseType==HTML) { 160 if (uas.indexOf("opera")!=-1) { 163 if (uas.indexOf("opera/5")!=-1) ct = ClientType.OPERA_5x; 164 else if (uas.indexOf("opera/4")!=-1) ct = ClientType.OPERA_4x; 165 else if (uas.indexOf("opera 5")!=-1) ct = ClientType.OPERA_5x; 166 else if (uas.indexOf("opera 4")!=-1) ct = ClientType.OPERA_4x; 167 else if (uas.indexOf("opera/2")!=-1) ct = ClientType.HTML_BROWSER; 168 else if (uas.indexOf("opera 2")!=-1) ct = ClientType.HTML_BROWSER; 169 else ct = ClientType.HTML_3_2_BROWSER; 170 } else if (uas.indexOf("msie ")!=-1) { 172 if (uas.indexOf("msie 6")!=-1) ct = ClientType.IE_6x; 173 else if (uas.indexOf("msie 5")!=-1) ct = ClientType.IE_5x; 174 else if (uas.indexOf("msie 4")!=-1) ct = ClientType.IE_4x; 175 else if (uas.indexOf("msie 3")!=-1) ct = ClientType.IE_3x; 176 else if (uas.indexOf("msie 2")!=-1) ct = ClientType.HTML_BROWSER; 177 else ct = ClientType.HTML_3_2_BROWSER; 178 } else if (uas.indexOf("mozilla")!=-1) { 180 if (uas.indexOf("netscape6")!=-1) ct = ClientType.NN_6x; 181 else if (uas.indexOf("gecko")!=-1) ct = ClientType.NN_6x; 182 else if (uas.indexOf("mozilla/5")!=-1) ct = ClientType.HTML_4_0_BROWSER; 183 else if (uas.indexOf("mozilla/4")!=-1) ct = ClientType.NN_4x; 184 else if (uas.indexOf("mozilla/3")!=-1) ct = ClientType.NN_3x; 185 else if (uas.indexOf("mozilla 5")!=-1) ct = ClientType.HTML_4_0_BROWSER; 186 else if (uas.indexOf("mozilla 4")!=-1) ct = ClientType.NN_4x; 187 else if (uas.indexOf("mozilla 3")!=-1) ct = ClientType.NN_3x; 188 else ct = ClientType.HTML_BROWSER; 189 } 190 if (ct!=ClientType.UNKNOWN_BROWSER) break chk; 191 192 193 if (uas.indexOf("lynx")!=-1) ct = ClientType.HTML_3_2_BROWSER; 197 else if (uas.indexOf("konqueror")!=-1) ct = ClientType.HTML_BROWSER; 198 else if (uas.indexOf("mozilla")!=-1) ct = ClientType.HTML_BROWSER; 199 } else if (baseType==CHTML) { 201 ct = ClientType.CHTML_BROWSER; 203 } else if (baseType==XML) { 205 ct = ClientType.XML_BROWSER; 207 } else if (baseType==VXML) { 209 ct = ClientType.VXML_BROWSER; 211 } else if (baseType==WML) { 213 ct = ClientType.WML_BROWSER; 217 } else if (baseType==XHTML_BASIC) { 219 ct = ClientType.XHTML_BROWSER; 221 } else if (baseType==XHTML_STANDARD) { 223 ct = ClientType.XHTML_BROWSER; 225 } 226 } 227 return ct; 228 } 229 230 private static int getBaseType(HttpServletRequest req) { 232 int baseType = HTML; chk: if (req!=null) { 234 String acc = req.getHeader("Accept"); 236 if (acc==null) acc = req.getHeader("accept"); 237 if (acc==null) break chk; 238 acc = acc.toLowerCase(); 239 240 if (acc.indexOf("text/html")!=-1) baseType = HTML; 242 else if (acc.indexOf("text/vnd.wap.wml")!=-1) baseType = WML; 243 else if (acc.indexOf("text/chtml")!=-1) baseType = CHTML; 244 else if (acc.indexOf("text/xml")!=-1) baseType = XML; 245 } 249 return baseType; 250 } 251 } | Popular Tags |