1
2
3
4
5 package net.sf.wfnm.web;
6
7 import java.io.Serializable;
8
9 import javax.servlet.http.HttpServletRequest;
10
11
12 /***
13 * Implements the function that calculate the URL as the name of the page with its query string.
14 *
15 * @author <a href="mailto:malbari@users.sourceforge.net">Maurizio Albari</a>
16 * @version 1.0.6
17 */
18 public class QueryStringUrlCalculator implements UrlCalculator, Serializable {
19 /***
20 * Creates a new QueryStringUrlCalculator object.
21 */
22 public QueryStringUrlCalculator() {
23 super();
24 }
25
26 /***
27 * Calculates the URl of the page given the HttpServletRequest.
28 *
29 * @param request the HttpServletRequest
30 *
31 * @return the calculated URL
32 */
33 public String calculateUrl(HttpServletRequest request) {
34 String queryString = request.getQueryString();
35 String reqUri = request.getRequestURI();
36
37 if ((queryString != null) && (queryString.length() != 0)) {
38 reqUri = reqUri + '?' + queryString;
39 }
40
41 String ctPath = request.getContextPath();
42 String url = reqUri.startsWith(ctPath) ? reqUri.substring(ctPath.length()) : reqUri;
43
44 return url;
45 }
46 }