1 64 65 package com.jcorporate.expresso.core.misc; 66 67 import com.jcorporate.expresso.core.jsdkapi.GenericSession; 68 import com.jcorporate.expresso.kernel.util.FastStringBuffer; 69 70 import javax.servlet.ServletException ; 71 import javax.servlet.http.HttpServletRequest ; 72 import javax.servlet.http.HttpServletResponse ; 73 74 75 85 public class HTTPUtil { 86 89 public HTTPUtil() { 90 super(); 91 } 92 93 99 public static String getContinueURL(HttpServletRequest request) 100 throws ServletException { 101 return GenericSession.getAttributeString(request, 102 "expresso.continueURL"); 103 } 104 105 106 112 public static String getNextURI(HttpServletRequest req) { 113 String uri = req.getRequestURI(); 114 115 return uri; 116 } 117 118 123 135 public static String qualifyURLIfNeeded(String url, HttpServletRequest req) { 136 if ("".equals(url) || url == null) { 137 return null; 138 } 139 if (url.startsWith("http") || url.startsWith("HTTP")) { 140 141 return url; 143 } 144 145 FastStringBuffer sb = new FastStringBuffer(128); 147 sb.append(req.getScheme()); 148 sb.append("://"); 149 sb.append(req.getServerName()); 150 151 if (req.getServerPort() != 80) { 153 sb.append(":"); 154 sb.append(req.getServerPort()); 155 } 156 if (!('/' == url.charAt(0))) { 157 sb.append("/"); 158 } 159 160 sb.append(url); 161 162 return sb.toString(); 163 } 164 165 173 public static void setBackURL(String newURL, HttpServletRequest request) 174 throws ServletException { 175 newURL = StringUtil.notNull(newURL); 176 177 if (newURL.equals("")) { 178 GenericSession.removeAttribute(request, "expresso.backURL"); 179 } 180 181 newURL = qualifyURLIfNeeded(newURL, request); 183 GenericSession.setAttribute(request, "expresso.backURL", newURL); 184 } 185 186 187 195 public static void setBackURL(HttpServletRequest request) 196 throws ServletException { 197 setBackURL(request.getParameter("back"), request); 198 } 199 200 201 208 public static String getBackURL(HttpServletRequest request) 209 throws ServletException { 210 return GenericSession.getAttributeString(request, "expresso.backURL"); 211 } 212 213 214 218 public static void setContinueURL(String newURL, 219 HttpServletRequest request) 220 throws ServletException { 221 if (!(newURL.equals("")) || newURL == null) { 222 GenericSession.removeAttribute(request, "expresso.continueURL"); 223 } 224 225 newURL = qualifyURLIfNeeded(newURL, request); 227 GenericSession.removeAttribute(request, "expresso.continueURL"); 228 GenericSession.setAttribute(request, "expresso.continueURL", newURL); 229 } 230 231 232 239 public static void setContinueURL(String newURL, 240 HttpServletRequest request, 241 HttpServletResponse response) 242 throws ServletException { 243 if (!"".equals(newURL) || newURL == null) { 244 GenericSession.removeAttribute(request, "expresso.continueURL"); 245 } 246 247 newURL = qualifyURLIfNeeded(newURL, request); 249 GenericSession.removeAttribute(request, "expresso.continueURL"); 250 GenericSession.setAttribute(request, "expresso.continueURL", 251 response.encodeURL(newURL)); 252 } 253 254 255 264 public static void setContinueURL(HttpServletRequest req) 265 throws ServletException { 266 String qstring = StringUtil.notNull(req.getQueryString()); 267 268 StringBuffer urlsb = req.getRequestURL(); 270 if (!qstring.equals("")) { 271 urlsb.append("?"); 272 urlsb.append(qstring); 273 } 274 275 setContinueURL(urlsb.toString(), req); 276 } 277 278 279 289 public static void setContinueURL(HttpServletRequest req, 290 HttpServletResponse res) 291 throws ServletException { 292 String qstring = StringUtil.notNull(req.getQueryString()); 293 StringBuffer urlsb = req.getRequestURL(); 295 if (!(qstring.equals(""))) { 296 urlsb.append("?"); 297 urlsb.append(qstring); 298 } 299 300 setContinueURL(urlsb.toString(), req, res); 301 } 302 303 304 311 public static void setContinueURLFromQueryString(HttpServletRequest req) 312 throws ServletException { 313 String nextURL = req.getParameter("next"); 314 315 if (nextURL != null && !"".equals(nextURL)) { 316 setContinueURL(nextURL, req); 317 } 318 } 319 } 320 321 | Popular Tags |