Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
UtilsResponse |
|
| 4.0;4 |
1 | /* | |
2 | * FCKeditor - The text editor for Internet - http://www.fckeditor.net | |
3 | * Copyright (C) 2004-2009 Frederico Caldeira Knabben | |
4 | * | |
5 | * == BEGIN LICENSE == | |
6 | * | |
7 | * Licensed under the terms of any of the following licenses at your | |
8 | * choice: | |
9 | * | |
10 | * - GNU General Public License Version 2 or later (the "GPL") | |
11 | * http://www.gnu.org/licenses/gpl.html | |
12 | * | |
13 | * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") | |
14 | * http://www.gnu.org/licenses/lgpl.html | |
15 | * | |
16 | * - Mozilla Public License Version 1.1 or later (the "MPL") | |
17 | * http://www.mozilla.org/MPL/MPL-1.1.html | |
18 | * | |
19 | * == END LICENSE == | |
20 | */ | |
21 | package net.fckeditor.tool; | |
22 | ||
23 | import javax.servlet.http.HttpServletRequest; | |
24 | ||
25 | import net.fckeditor.handlers.ConnectorHandler; | |
26 | import net.fckeditor.handlers.ResourceTypeHandler; | |
27 | ||
28 | /** | |
29 | * Some static helper methods in conjunction with the servlet response. | |
30 | * | |
31 | * @version $Id: UtilsResponse.java 3840 2009-07-08 20:29:46Z mosipov $ | |
32 | */ | |
33 | 0 | public class UtilsResponse { |
34 | ||
35 | /** | |
36 | * Constructs a URL from different parameters. This method is about to | |
37 | * change in version 2.5. | |
38 | * | |
39 | * @param request | |
40 | * @param resourceType | |
41 | * @param urlPath | |
42 | * @param prependContextPath | |
43 | * @param fullUrl | |
44 | * @return constructed url | |
45 | */ | |
46 | public static String constructResponseUrl(HttpServletRequest request, | |
47 | ResourceTypeHandler resourceType, String urlPath, | |
48 | boolean prependContextPath, boolean fullUrl) { | |
49 | ||
50 | 0 | StringBuffer sb = new StringBuffer(); |
51 | ||
52 | 0 | if (fullUrl) { |
53 | 0 | String address = request.getRequestURL().toString(); |
54 | 0 | sb.append(address.substring(0, address.indexOf('/', 8)) |
55 | + request.getContextPath()); | |
56 | } | |
57 | ||
58 | 0 | if (prependContextPath && !fullUrl) |
59 | 0 | sb.append(request.getContextPath()); |
60 | ||
61 | 0 | sb.append(ConnectorHandler.getUserFilesPath(request)); |
62 | 0 | sb.append(resourceType.getPath()); |
63 | ||
64 | 0 | if (Utils.isNotEmpty(urlPath)) |
65 | 0 | sb.append(urlPath); |
66 | ||
67 | 0 | return sb.toString(); |
68 | } | |
69 | ||
70 | } |