You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PagesServlet.java 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2012 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.servlet;
  17. import javax.servlet.http.HttpServletRequest;
  18. import com.gitblit.Constants;
  19. /**
  20. * Serves the content of a gh-pages branch.
  21. *
  22. * @author James Moger
  23. *
  24. */
  25. public class PagesServlet extends BranchServlet {
  26. private static final long serialVersionUID = 1L;
  27. /**
  28. * Returns an url to this servlet for the specified parameters.
  29. *
  30. * @param baseURL
  31. * @param repository
  32. * @param path
  33. * @return an url
  34. */
  35. public static String asLink(String baseURL, String repository, String path) {
  36. if (baseURL.length() > 0 && baseURL.charAt(baseURL.length() - 1) == '/') {
  37. baseURL = baseURL.substring(0, baseURL.length() - 1);
  38. }
  39. return baseURL + Constants.PAGES + repository + "/" + (path == null ? "" : ("/" + path));
  40. }
  41. @Override
  42. protected String getBranch(String repository, HttpServletRequest request) {
  43. return "gh-pages";
  44. }
  45. @Override
  46. protected String getPath(String repository, String branch, HttpServletRequest request) {
  47. String pi = request.getPathInfo().substring(1);
  48. if (pi.equals(repository)) {
  49. return "";
  50. }
  51. String path = pi.substring(pi.indexOf(repository) + repository.length() + 1);
  52. if (path.endsWith("/")) {
  53. path = path.substring(0, path.length() - 1);
  54. }
  55. return path;
  56. }
  57. @Override
  58. protected boolean renderIndex() {
  59. return true;
  60. }
  61. }