View Javadoc

1   /*
2    * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3    * Copyright (C) 2003-2008 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 2151 2008-07-02 22:03:15Z mosipov $
32   */
33  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      	StringBuffer sb = new StringBuffer();
51      	
52      	if (fullUrl) {
53      		String address = request.getRequestURL().toString();
54      		sb.append(address.substring(0, address.indexOf('/', 8))
55      				+ request.getContextPath());
56      	}
57      	
58      	if (prependContextPath && !fullUrl)
59      		sb.append(request.getContextPath());
60      	
61      	sb.append(ConnectorHandler.getUserFilesPath(request));
62      	sb.append(resourceType.getPath());
63      	
64      	if (Utils.isNotEmpty(urlPath))
65      		sb.append(urlPath);
66      	
67      	return sb.toString();
68      }
69  
70  }