| 1 5 6 package com.raptus.vr; 7 8 import java.io.IOException ; 9 import java.util.Locale ; 10 11 import javax.servlet.ServletException ; 12 import javax.servlet.http.*; 13 14 import org.apache.struts.Globals; 15 import org.apache.struts.action.*; 16 17 import com.raptus.owxv3.*; 18 19 41 public class VRAction extends org.apache.struts.action.Action 42 { 43 public final static String VRLOCALE = Globals.LOCALE_KEY; 44 public final static String VRCURRENT = "_vr_current"; 45 public final static String VRRESOLUTION = "_vr_res"; 46 public final static String VRBROWSER = "_vr_browser"; 47 public final static String VRJSCRIPT = "_vr_jscript"; 48 public final static String VRFLASH = "_vr_flash"; 49 50 61 public ActionForward perform(ActionMapping mapping, 62 ActionForm form, 63 HttpServletRequest request, 64 HttpServletResponse response) 65 throws IOException , ServletException  66 { 67 77 VRBean myform = (VRBean) form; 78 String ovrloc = myform.getLocale(); 79 String cmd = myform.getCmd(); 80 String val = myform.getValue(); 81 String nex = myform.getNext(); 82 String res = myform.getRes(); 83 boolean csd = myform.getCsdetect(); 84 boolean js = myform.getJscript(); 85 boolean fla = myform.getFlash(); 86 boolean redirForward = true; 87 88 HttpSession session = request.getSession(); 89 90 if(cmd.equalsIgnoreCase("swlocale")) 92 { 93 if(val != null && verifyLocaleString(val)) 94 { 95 setLocale(session, val); 96 LoggingManager.log("switched locale to " + val, this); 97 } 98 else 99 { 100 setDefaultLocale(session); 101 LoggingManager.log("invalid locale: " + val + 102 ". switched to default locale.", this); 103 } 104 } 105 else if(ovrloc != null) 106 { 107 if(verifyLocaleString(ovrloc)) 109 { 110 setLocale(session, ovrloc); 111 LoggingManager.log("switched locale to " + ovrloc + " !override mode!", this); 112 } 113 else 114 LoggingManager.log("invalid override locale <" + ovrloc + "> doing nothing.", this); 115 116 } 117 118 if(cmd.equalsIgnoreCase("swactive")) 120 { 121 122 if(val != null) 123 { 124 session.setAttribute(VRCURRENT, val); 125 LoggingManager.log("new current id is " + val, this); 126 } 127 else 128 LoggingManager.log("invalid value for <swactive>: " + val, this); 129 } 130 131 if(cmd.equalsIgnoreCase("csd")) 133 { 134 myform.setCsdetect(false); 135 csd = false; 136 redirForward = false; 137 LoggingManager.log("client detection: res: " + res, this); 138 LoggingManager.log("client detection: flash: " + fla, this); 139 LoggingManager.log("client detection: js: " + js, this); 140 141 if(res != null && res.equalsIgnoreCase("big")) 143 session.setAttribute(VRRESOLUTION, res); 144 else 145 session.setAttribute(VRRESOLUTION, "small"); 146 147 session.setAttribute(VRFLASH, new Boolean (fla)); 148 session.setAttribute(VRJSCRIPT, new Boolean (js)); 149 } 150 151 Object o = session.getAttribute(VRBROWSER); 153 if(o == null) 154 { 155 String bro = detectBrowser(request.getHeader("User-Agent")); 156 session.setAttribute(VRBROWSER, bro); 157 158 LoggingManager.log("server detection: browser: " + bro, this); 159 } 160 161 String loc = ((Locale ) session.getAttribute(VRLOCALE)).toString(); 163 if(!verifyLocaleString(loc)) 164 { 165 setDefaultLocale(session); 166 LoggingManager.log("switched to default locale!", this); 167 } 168 else 169 LoggingManager.log("current locale: " + loc, this); 170 171 if(csd == true && nex != null) 173 { 174 LoggingManager.log("invoking clientside detection. (Next: " + nex + ")", this); 176 String enc = "ISO-8859-1"; 177 String csdurl = "/owxv3/vrmenu/clientside-detection.jsp?next=" + 178 java.net.URLEncoder.encode(nex, enc); 179 response.sendRedirect(csdurl); 180 return null; } 182 183 if(nex != null && nex.length() > 0) 185 { 186 LoggingManager.log("redirecting to " + nex, this); 187 if(redirForward) 188 request.getRequestDispatcher(nex).forward(request, response); 189 else 190 response.sendRedirect(nex); 191 } 192 else 193 LoggingManager.log("no redirection", this); 194 195 return null; 196 } 197 198 201 protected String detectBrowser(String ua) 202 { 203 String val = "msie"; 204 if(ua != null && ua.length() > 0) 205 { 206 if(ua.toLowerCase().indexOf("msie") != -1) 207 { 208 val = "msie"; 209 } 210 else if(ua.toLowerCase().indexOf("gecko") != -1) 211 { 212 val = "ns6"; 213 } 214 else if(ua.toLowerCase().indexOf("mozilla") != -1) 215 { 216 val = "ns4"; 217 } 218 } 219 220 return val; 221 } 222 223 226 protected boolean verifyLocaleString(String locale) 227 { 228 return( locale.equals("de_CH") || 229 locale.equals("fr_CH") || 230 locale.equals("en_GB") || 231 locale.equals("it_CH") ); 232 } 233 234 237 protected void setLocale(HttpSession session, String locale) 238 { 239 PairOfObjects po = LocaleManager.stripLocaleString(locale); 240 Locale l = new Locale ((String ) po.getObjectOne(), 241 (String ) po.getObjectTwo()); 242 session.setAttribute(VRLOCALE, l); 243 } 244 245 248 protected void setDefaultLocale(HttpSession session) 249 { 250 Locale l = new Locale ("de", "CH"); 251 session.setAttribute(VRLOCALE, l); 252 } 253 254 } 255 256 | Popular Tags |