mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
use viewable for repository root resource
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.api.rest.resources;
|
package sonia.scm.api.rest.resources;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
@@ -43,15 +44,15 @@ import com.google.inject.Inject;
|
|||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
import sonia.scm.repository.RepositoryManager;
|
import sonia.scm.repository.RepositoryManager;
|
||||||
import sonia.scm.repository.RepositoryTypePredicate;
|
import sonia.scm.repository.RepositoryTypePredicate;
|
||||||
import sonia.scm.template.TemplateHandler;
|
|
||||||
import sonia.scm.url.UrlProvider;
|
import sonia.scm.url.UrlProvider;
|
||||||
import sonia.scm.url.UrlProviderFactory;
|
import sonia.scm.url.UrlProviderFactory;
|
||||||
import sonia.scm.util.HttpUtil;
|
import sonia.scm.util.HttpUtil;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import com.sun.jersey.api.view.Viewable;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@@ -76,7 +77,7 @@ public class RepositoryRootResource
|
|||||||
{
|
{
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String TEMPLATE = "/repository-root";
|
public static final String TEMPLATE = "/templates/repository-root.ftl";
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
@@ -89,10 +90,8 @@ public class RepositoryRootResource
|
|||||||
* @param repositoryManager
|
* @param repositoryManager
|
||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
public RepositoryRootResource(TemplateHandler templateHandler,
|
public RepositoryRootResource(RepositoryManager repositoryManager)
|
||||||
RepositoryManager repositoryManager)
|
|
||||||
{
|
{
|
||||||
this.templateHandler = templateHandler;
|
|
||||||
this.repositoryManager = repositoryManager;
|
this.repositoryManager = repositoryManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,9 +111,9 @@ public class RepositoryRootResource
|
|||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.TEXT_HTML)
|
@Produces(MediaType.TEXT_HTML)
|
||||||
public String renderRepositoriesRoot(@Context HttpServletRequest request,
|
public Viewable renderRepositoriesRoot(@Context HttpServletRequest request,
|
||||||
@PathParam("type") final String type)
|
@PathParam("type") final String type)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
String baseUrl = HttpUtil.getCompleteUrl(request);
|
String baseUrl = HttpUtil.getCompleteUrl(request);
|
||||||
UrlProvider uiUrlProvider = UrlProviderFactory.createUrlProvider(baseUrl,
|
UrlProvider uiUrlProvider = UrlProviderFactory.createUrlProvider(baseUrl,
|
||||||
@@ -135,11 +134,7 @@ public class RepositoryRootResource
|
|||||||
|
|
||||||
environment.put("repositories", repositories);
|
environment.put("repositories", repositories);
|
||||||
|
|
||||||
StringWriter writer = new StringWriter();
|
return new Viewable(TEMPLATE, environment);
|
||||||
|
|
||||||
templateHandler.render(TEMPLATE, writer, environment);
|
|
||||||
|
|
||||||
return writer.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- inner classes --------------------------------------------------------
|
//~--- inner classes --------------------------------------------------------
|
||||||
@@ -163,7 +158,7 @@ public class RepositoryRootResource
|
|||||||
* @param baseUrl
|
* @param baseUrl
|
||||||
*/
|
*/
|
||||||
public RepositoryTemplateElement(Repository repository,
|
public RepositoryTemplateElement(Repository repository,
|
||||||
UrlProvider uiUrlProvider, String baseUrl)
|
UrlProvider uiUrlProvider, String baseUrl)
|
||||||
{
|
{
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.urlProvider = uiUrlProvider;
|
this.urlProvider = uiUrlProvider;
|
||||||
@@ -181,7 +176,7 @@ public class RepositoryRootResource
|
|||||||
public String getCommitUrl()
|
public String getCommitUrl()
|
||||||
{
|
{
|
||||||
return urlProvider.getRepositoryUrlProvider().getChangesetUrl(
|
return urlProvider.getRepositoryUrlProvider().getChangesetUrl(
|
||||||
repository.getId(), 0, 20);
|
repository.getId(), 0, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -193,7 +188,7 @@ public class RepositoryRootResource
|
|||||||
public String getDetailUrl()
|
public String getDetailUrl()
|
||||||
{
|
{
|
||||||
return urlProvider.getRepositoryUrlProvider().getDetailUrl(
|
return urlProvider.getRepositoryUrlProvider().getDetailUrl(
|
||||||
repository.getId());
|
repository.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -227,7 +222,7 @@ public class RepositoryRootResource
|
|||||||
public String getSourceUrl()
|
public String getSourceUrl()
|
||||||
{
|
{
|
||||||
return urlProvider.getRepositoryUrlProvider().getBrowseUrl(
|
return urlProvider.getRepositoryUrlProvider().getBrowseUrl(
|
||||||
repository.getId(), null, null);
|
repository.getId(), null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -262,7 +257,7 @@ public class RepositoryRootResource
|
|||||||
* @author Enter your name here...
|
* @author Enter your name here...
|
||||||
*/
|
*/
|
||||||
private static class RepositoryTemplateElementComparator
|
private static class RepositoryTemplateElementComparator
|
||||||
implements Comparator<RepositoryTemplateElement>
|
implements Comparator<RepositoryTemplateElement>
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -276,7 +271,7 @@ public class RepositoryRootResource
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int compare(RepositoryTemplateElement left,
|
public int compare(RepositoryTemplateElement left,
|
||||||
RepositoryTemplateElement right)
|
RepositoryTemplateElement right)
|
||||||
{
|
{
|
||||||
return left.getName().compareTo(right.getName());
|
return left.getName().compareTo(right.getName());
|
||||||
}
|
}
|
||||||
@@ -291,7 +286,7 @@ public class RepositoryRootResource
|
|||||||
* @author Enter your name here...
|
* @author Enter your name here...
|
||||||
*/
|
*/
|
||||||
private static class RepositoryTransformFunction
|
private static class RepositoryTransformFunction
|
||||||
implements Function<Repository, RepositoryTemplateElement>
|
implements Function<Repository, RepositoryTemplateElement>
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -341,7 +336,4 @@ public class RepositoryRootResource
|
|||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private RepositoryManager repositoryManager;
|
private RepositoryManager repositoryManager;
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private TemplateHandler templateHandler;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user