]> source.dussan.org Git - gitblit.git/commitdiff
Replaced getRelativePathPrefixToContextRoot with method in
authorMartin Spielmann <martin.spielmann@pingunaut.com>
Sat, 30 Jul 2016 09:07:56 +0000 (11:07 +0200)
committerMartin Spielmann <martin.spielmann@pingunaut.com>
Sat, 30 Jul 2016 09:07:56 +0000 (11:07 +0200)
GitBlitRequestUtils

src/main/java/com/gitblit/utils/GitBlitRequestUtils.java
src/main/java/com/gitblit/wicket/MarkupProcessor.java
src/main/java/com/gitblit/wicket/pages/BasePage.java
src/main/java/com/gitblit/wicket/pages/EditTeamPage.java
src/main/java/com/gitblit/wicket/pages/ProjectPage.java
src/main/java/com/gitblit/wicket/pages/RawPage.java
src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
src/main/java/com/gitblit/wicket/pages/TreePage.java
src/main/java/com/gitblit/wicket/panels/ProjectRepositoryPanel.java

index 7a7e52905f00cbc9f2da510201d4ab9774ba3599..74b3854b03edbf5c6e5cafbba1507d8f914fd987 100644 (file)
@@ -4,22 +4,44 @@ import javax.servlet.http.HttpServletRequest;
 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;
+       }
+}
index 7826a3b2e2535b8688af5d5a69e88cc5c5c39668..50d64697470389f627f14291a65a1f2581527566 100644 (file)
@@ -57,6 +57,7 @@ import com.gitblit.IStoredSettings;
 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;
@@ -268,7 +269,7 @@ public class MarkupProcessor {
                                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
@@ -325,7 +326,7 @@ public class MarkupProcessor {
                                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);
                                }
@@ -339,7 +340,7 @@ public class MarkupProcessor {
                                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 {
index 1b44e87578f7e3dd36c74eb4a6ee98c15792405c..06b6a6b834a864219adac4906ace779eb1ad6231 100644 (file)
@@ -105,7 +105,7 @@ public abstract class BasePage extends SessionPage {
        }\r
 \r
        protected String getContextUrl() {\r
-               return getRequest().getRelativePathPrefixToContextRoot();\r
+               return GitBlitRequestUtils.getRelativePathPrefixToContextRoot();\r
        }\r
 \r
        protected String getCanonicalUrl() {\r
index 9f9e6b1cb1a1773679272edb1eb68c133b1a40b8..8c735a5deb8b012b2ebe39b2567c7255a99b28c1 100644 (file)
@@ -25,6 +25,7 @@ import java.util.List;
 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
index 5da07e6dc4c21356c2f152edd05a9436bde68a04..101f89e1f07b8cd285c83d00f34e322cf696bbaa 100644 (file)
@@ -35,6 +35,7 @@ import com.gitblit.models.ProjectModel;
 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
@@ -107,7 +108,7 @@ public class ProjectPage extends DashboardPage {
                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
index 2faa418520c1dc55b12f5d11ec3a56b029c5ed47..5f94198eaad6d7a95cc421fa639b9b91e2461f60 100644 (file)
@@ -27,8 +27,8 @@ import javax.servlet.http.HttpServletResponse;
 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
@@ -37,6 +37,7 @@ import org.slf4j.LoggerFactory;
 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
@@ -95,7 +96,7 @@ public class RawPage extends SessionPage {
                                                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
@@ -112,7 +113,7 @@ public class RawPage extends SessionPage {
                                                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
@@ -148,7 +149,7 @@ public class RawPage extends SessionPage {
                                                        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
@@ -164,7 +165,7 @@ public class RawPage extends SessionPage {
                                                        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
@@ -172,7 +173,7 @@ public class RawPage extends SessionPage {
 \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
@@ -201,7 +202,7 @@ public class RawPage extends SessionPage {
                                                                        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
@@ -218,7 +219,7 @@ public class RawPage extends SessionPage {
                                                                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
index dd8df4a3e782b3ed2297785363f2efe7339de92f..504d83c14aa157b9218e87dd0bda5aa9b02c0f0d 100644 (file)
@@ -168,7 +168,7 @@ public abstract class RepositoryPage extends RootPage {
                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
@@ -246,7 +246,7 @@ public abstract class RepositoryPage extends RootPage {
                // 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
@@ -426,7 +426,7 @@ public abstract class RepositoryPage extends RootPage {
 \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
index 73a03f86bf13ad53809b759796f299fb12165459..c1adf6e1d8eb9afaed5dd9a5c2b8af08deeaec44 100644 (file)
@@ -39,6 +39,7 @@ import com.gitblit.models.SubmoduleModel;
 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
@@ -64,7 +65,7 @@ public class TreePage extends RepositoryPage {
                // 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
index 73b72bbc019d4a78d8bf2d0ebee6e68364b00f20..503b3d129d4531d4fbd3a23d99f320d67ca936ad 100644 (file)
@@ -31,6 +31,7 @@ import com.gitblit.models.RepositoryModel;
 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
@@ -158,7 +159,7 @@ public class ProjectRepositoryPanel extends BasePanel {
                        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