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.

MarkdownPage.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright 2011 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.wicket.pages;
  17. import java.text.MessageFormat;
  18. import java.text.ParseException;
  19. import org.apache.wicket.PageParameters;
  20. import org.apache.wicket.markup.html.basic.Label;
  21. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  22. import org.eclipse.jgit.lib.Constants;
  23. import org.eclipse.jgit.lib.Repository;
  24. import org.eclipse.jgit.revwalk.RevCommit;
  25. import com.gitblit.GitBlit;
  26. import com.gitblit.utils.JGitUtils;
  27. import com.gitblit.utils.MarkdownUtils;
  28. import com.gitblit.utils.StringUtils;
  29. import com.gitblit.wicket.CacheControl;
  30. import com.gitblit.wicket.WicketUtils;
  31. import com.gitblit.wicket.CacheControl.LastModified;
  32. @CacheControl(LastModified.BOOT)
  33. public class MarkdownPage extends RepositoryPage {
  34. public MarkdownPage(PageParameters params) {
  35. super(params);
  36. final String markdownPath = WicketUtils.getPath(params);
  37. Repository r = getRepository();
  38. RevCommit commit = JGitUtils.getCommit(r, objectId);
  39. String [] encodings = GitBlit.getEncodings();
  40. // markdown page links
  41. add(new BookmarkablePageLink<Void>("blameLink", BlamePage.class,
  42. WicketUtils.newPathParameter(repositoryName, objectId, markdownPath)));
  43. add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,
  44. WicketUtils.newPathParameter(repositoryName, objectId, markdownPath)));
  45. add(new BookmarkablePageLink<Void>("rawLink", RawPage.class, WicketUtils.newPathParameter(
  46. repositoryName, objectId, markdownPath)));
  47. add(new BookmarkablePageLink<Void>("headLink", MarkdownPage.class,
  48. WicketUtils.newPathParameter(repositoryName, Constants.HEAD, markdownPath)));
  49. // Read raw markdown content and transform it to html
  50. String markdownText = JGitUtils.getStringContent(r, commit.getTree(), markdownPath, encodings);
  51. String htmlText;
  52. try {
  53. htmlText = MarkdownUtils.transformMarkdown(markdownText);
  54. } catch (ParseException p) {
  55. markdownText = MessageFormat.format("<div class=\"alert alert-error\"><strong>{0}:</strong> {1}</div>{2}", getString("gb.error"), getString("gb.markdownFailure"), markdownText);
  56. htmlText = StringUtils.breakLinesForHtml(markdownText);
  57. }
  58. // Add the html to the page
  59. add(new Label("markdownText", htmlText).setEscapeModelStrings(false));
  60. }
  61. @Override
  62. protected String getPageName() {
  63. return getString("gb.markdown");
  64. }
  65. @Override
  66. protected Class<? extends BasePage> getRepoNavPageClass() {
  67. return DocsPage.class;
  68. }
  69. }