create url from current request

This commit is contained in:
Sebastian Sdorra
2012-05-29 10:36:20 +02:00
parent b2dc85636c
commit a087a45fb4
3 changed files with 88 additions and 29 deletions

View File

@@ -52,6 +52,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
/**
*
* @author Sebastian Sdorra
@@ -73,7 +75,7 @@ public class RepositoryUtil
* @param configuration
* @param repositoryManager
* @param repository
*
*
* @since 1.16
*/
public static void appendUrl(ScmConfiguration configuration,
@@ -92,6 +94,33 @@ public class RepositoryUtil
}
}
/**
* Method description
*
*
*
* @param request
* @param repositoryManager
* @param repository
*
* @since 1.16
*/
public static void appendUrl(HttpServletRequest request,
RepositoryManager repositoryManager,
Repository repository)
{
RepositoryHandler handler =
repositoryManager.getHandler(repository.getType());
if (handler != null)
{
String url = handler.createResourcePath(repository);
url = HttpUtil.getCompleteUrl(request, url);
repository.setUrl(url);
}
}
/**
* Method description
*

View File

@@ -293,6 +293,34 @@ public class HttpUtil
//~--- get methods ----------------------------------------------------------
/**
* Returns an absolute url with context path.
*
*
* @param request http client request
* @param pathSegments
*
* @return absolute url with context path
* @since 1.16
*/
public static String getCompleteUrl(HttpServletRequest request,
String... pathSegments)
{
String baseUrl =
request.getRequestURL().toString().replace(request.getRequestURI(),
Util.EMPTY_STRING).concat(request.getContextPath());
if (Util.isNotEmpty(pathSegments))
{
for (String ps : pathSegments)
{
baseUrl = append(baseUrl, ps);
}
}
return baseUrl;
}
/**
* Return the complete url of the given path.
*