import javax.servlet.http.HttpServletResponse;
import org.apache.wicket.Page;
+import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
+import org.apache.wicket.request.Request;
import org.apache.wicket.request.Url;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.mapper.parameter.PageParameters;
public class GitBlitRequestUtils {
- public static HttpServletRequest getServletRequest(){
- return (HttpServletRequest)RequestCycle.get().getRequest().getContainerRequest();
+ public static HttpServletRequest getServletRequest() {
+ return (HttpServletRequest) RequestCycle.get().getRequest().getContainerRequest();
}
-
- public static HttpServletResponse getServletResponse(){
- return (HttpServletResponse)RequestCycle.get().getResponse().getContainerResponse();
+
+ public static HttpServletResponse getServletResponse() {
+ return (HttpServletResponse) RequestCycle.get().getResponse().getContainerResponse();
}
- public static String toAbsoluteUrl(Class<? extends Page> pageClass, PageParameters params){
+ public static String toAbsoluteUrl(Class<? extends Page> pageClass, PageParameters params) {
String relativeUrl = RequestCycle.get().urlFor(pageClass, params).toString();
return RequestCycle.get().getUrlRenderer().renderFullUrl(Url.parse(relativeUrl));
}
-}
+ /**
+ * COPIED FROM WICKET 1.3 Docs:
+ *
+ * Gets a prefix to make this relative to the context root.
+ *
+ * For example, if your context root is http://server.com/myApp/ and the
+ * request is for /myApp/mountedPage/, then the prefix returned might be
+ * "../../".
+ *
+ * For a particular technology, this might return either an absolute prefix
+ * or a relative one.
+ */
+ public static String getRelativePathPrefixToContextRoot() {
+ // String contextUrl =
+ // RequestCycle.get().getRequest().getRelativePathPrefixToContextRoot();
+ // TODO: test it! i thing deeper mounted pages will not work yet
+ Request r = RequestCycle.get().getRequest();
+ String p = r.getPrefixToContextPath();
+ return p;
+ }
+}
import com.gitblit.Keys;
import com.gitblit.models.PathModel;
import com.gitblit.servlet.RawServlet;
+import com.gitblit.utils.GitBlitRequestUtils;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.MarkdownUtils;
import com.gitblit.utils.StringUtils;
if (imagePath.indexOf("://") == -1) {
// relative image
String path = doc.getRelativePath(imagePath);
- String contextUrl = RequestCycle.get().getRequest().getRelativePathPrefixToContextRoot();
+ String contextUrl = GitBlitRequestUtils.getRelativePathPrefixToContextRoot();
url = RawServlet.asLink(contextUrl, repositoryName, commitId, path);
} else {
// absolute image
if (node.url.indexOf("://") == -1) {
// repository-relative image link
String path = doc.getRelativePath(node.url);
- String contextUrl = RequestCycle.get().getRequest().getRelativePathPrefixToContextRoot();
+ String contextUrl = GitBlitRequestUtils.getRelativePathPrefixToContextRoot();
String url = RawServlet.asLink(contextUrl, repositoryName, commitId, path);
return new Rendering(url, text);
}
if (url.indexOf("://") == -1) {
// repository-relative image link
String path = doc.getRelativePath(url);
- String contextUrl = RequestCycle.get().getRequest().getRelativePathPrefixToContextRoot();
+ String contextUrl = GitBlitRequestUtils.getRelativePathPrefixToContextRoot();
String wurl = RawServlet.asLink(contextUrl, repositoryName, commitId, path);
rendering = new Rendering(wurl, alt);
} else {
}\r
\r
protected String getContextUrl() {\r
- return getRequest().getRelativePathPrefixToContextRoot();\r
+ return GitBlitRequestUtils.getRelativePathPrefixToContextRoot();\r
}\r
\r
protected String getCanonicalUrl() {\r
import java.util.Set;\r
\r
import org.apache.wicket.request.mapper.parameter.PageParameters;\r
+import org.apache.wicket.AttributeModifier;\r
import org.apache.wicket.extensions.markup.html.form.palette.Palette;\r
import org.apache.wicket.markup.html.form.Button;\r
import org.apache.wicket.markup.html.form.CheckBox;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.servlet.SyndicationServlet;\r
+import com.gitblit.utils.GitBlitRequestUtils;\r
import com.gitblit.utils.MarkdownUtils;\r
import com.gitblit.utils.StringUtils;\r
import com.gitblit.wicket.CacheControl;\r
add(new Label("projectTitle", project.getDisplayName()));\r
add(new Label("projectDescription", project.description));\r
\r
- String feedLink = SyndicationServlet.asLink(getRequest().getRelativePathPrefixToContextRoot(), projectName, null, 0);\r
+ String feedLink = SyndicationServlet.asLink(GitBlitRequestUtils.getRelativePathPrefixToContextRoot(), projectName, null, 0);\r
add(new ExternalLink("syndication", feedLink));\r
\r
add(WicketUtils.syndicationDiscoveryLink(SyndicationServlet.getTitle(project.getDisplayName(),\r
import org.apache.wicket.request.cycle.RequestCycle;\r
import org.apache.wicket.request.http.WebRequest;\r
import org.apache.wicket.request.http.WebResponse;\r
+import org.apache.wicket.request.http.flow.AbortWithHttpErrorCodeException;\r
import org.apache.wicket.request.mapper.parameter.PageParameters;\r
-import org.apache.wicket.protocol.http.servlet.AbortWithWebErrorCodeException;\r
import org.eclipse.jgit.lib.Repository;\r
import org.eclipse.jgit.revwalk.RevCommit;\r
import org.slf4j.Logger;\r
import com.gitblit.Keys;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
+import com.gitblit.utils.GitBlitRequestUtils;\r
import com.gitblit.utils.JGitUtils;\r
import com.gitblit.utils.StringUtils;\r
import com.gitblit.wicket.GitBlitWebSession;\r
final String objectNotFound = MessageFormat.format("Raw page failed to find object {0} in {1}",\r
objectId, repositoryName);\r
logger.error(objectNotFound);\r
- throw new AbortWithWebErrorCodeException(HttpServletResponse.SC_NOT_FOUND, objectNotFound);\r
+ throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, objectNotFound);\r
}\r
contentType = "application/octet-stream";\r
response.setContentType(contentType);\r
final String commitNotFound = MessageFormat.format("Raw page failed to find commit {0} in {1}",\r
objectId, repositoryName);\r
logger.error(commitNotFound);\r
- throw new AbortWithWebErrorCodeException(HttpServletResponse.SC_NOT_FOUND, commitNotFound);\r
+ throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, commitNotFound);\r
}\r
\r
String filename = blobPath;\r
byte[] image = JGitUtils.getByteContent(r, commit.getTree(), blobPath, true);\r
if (image == null) {\r
logger.error(blobNotFound);\r
- throw new AbortWithWebErrorCodeException(HttpServletResponse.SC_NOT_FOUND, blobNotFound);\r
+ throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, blobNotFound);\r
}\r
contentType = "image/" + extension.toLowerCase();\r
response.setContentType(contentType);\r
byte[] binary = JGitUtils.getByteContent(r, commit.getTree(), blobPath, true);\r
if (binary == null) {\r
logger.error(blobNotFound);\r
- throw new AbortWithWebErrorCodeException(HttpServletResponse.SC_NOT_FOUND, blobNotFound);\r
+ throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, blobNotFound);\r
}\r
contentType = "application/octet-stream";\r
response.setContentLength(binary.length);\r
\r
try {\r
WebRequest request = (WebRequest) requestCycle.getRequest();\r
- String userAgent = request.getHttpServletRequest().getHeader("User-Agent");\r
+ String userAgent = GitBlitRequestUtils.getServletRequest().getHeader("User-Agent");\r
\r
if (userAgent != null && userAgent.indexOf("MSIE 5.5") > -1) {\r
response.setHeader("Content-Disposition", "filename=\""\r
blobPath, encodings);\r
if (content == null) {\r
logger.error(blobNotFound);\r
- throw new AbortWithWebErrorCodeException(HttpServletResponse.SC_NOT_FOUND, blobNotFound);\r
+ throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, blobNotFound);\r
}\r
contentType = "text/plain; charset=UTF-8";\r
response.setContentType(contentType);\r
encodings);\r
if (content == null) {\r
logger.error(blobNotFound);\r
- throw new AbortWithWebErrorCodeException(HttpServletResponse.SC_NOT_FOUND, blobNotFound);\r
+ throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, blobNotFound);\r
}\r
contentType = "text/plain; charset=UTF-8";\r
response.setContentType(contentType);\r
NavigationPanel navigationPanel = new NavigationPanel("repositoryNavPanel", getRepoNavPageClass(), navLinks);\r
add(navigationPanel);\r
\r
- add(new ExternalLink("syndication", SyndicationServlet.asLink(getRequest()\r
+ add(new ExternalLink("syndication", SyndicationServlet.asLink(GitBlitRequestUtils\r
.getRelativePathPrefixToContextRoot(), getRepositoryName(), null, 0)));\r
\r
// add floating search form\r
// per-repository extra navlinks\r
if (JGitUtils.getPagesBranch(r) != null) {\r
ExternalNavLink pagesLink = new ExternalNavLink("gb.pages", PagesServlet.asLink(\r
- getRequest().getRelativePathPrefixToContextRoot(), getRepositoryName(), null), true);\r
+ GitBlitRequestUtils.getRelativePathPrefixToContextRoot(), getRepositoryName(), null), true);\r
navLinks.add(pagesLink);\r
}\r
\r
\r
protected void addSyndicationDiscoveryLink() {\r
add(WicketUtils.syndicationDiscoveryLink(SyndicationServlet.getTitle(repositoryName,\r
- objectId), SyndicationServlet.asLink(getRequest()\r
+ objectId), SyndicationServlet.asLink(GitBlitRequestUtils\r
.getRelativePathPrefixToContextRoot(), repositoryName, objectId, 0)));\r
}\r
\r
import com.gitblit.models.UserModel;\r
import com.gitblit.servlet.RawServlet;\r
import com.gitblit.utils.ByteFormat;\r
+import com.gitblit.utils.GitBlitRequestUtils;\r
import com.gitblit.utils.JGitUtils;\r
import com.gitblit.wicket.CacheControl;\r
import com.gitblit.wicket.GitBlitWebSession;\r
// tree page links\r
add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,\r
WicketUtils.newPathParameter(repositoryName, objectId, path)));\r
- add(new CompressedDownloadsPanel("compressedLinks", getRequest()\r
+ add(new CompressedDownloadsPanel("compressedLinks", GitBlitRequestUtils\r
.getRelativePathPrefixToContextRoot(), repositoryName, objectId, path));\r
\r
add(new CommitHeaderPanel("commitHeader", repositoryName, commit));\r
import com.gitblit.models.UserModel;\r
import com.gitblit.servlet.SyndicationServlet;\r
import com.gitblit.utils.ArrayUtils;\r
+import com.gitblit.utils.GitBlitRequestUtils;\r
import com.gitblit.utils.StringUtils;\r
import com.gitblit.wicket.GitBlitWebSession;\r
import com.gitblit.wicket.WicketUtils;\r
add(new Label("repositorySize", localizer.getString("gb.empty", parent)).setEscapeModelStrings(false));\r
}\r
\r
- add(new ExternalLink("syndication", SyndicationServlet.asLink(getRequest()\r
+ add(new ExternalLink("syndication", SyndicationServlet.asLink(GitBlitRequestUtils\r
.getRelativePathPrefixToContextRoot(), entry.name, null, 0)));\r
}\r
}\r