mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-06 06:39:15 +01:00
create url from current request
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user