James Moger
2011-05-11 dfb88962fdbd29f59abe92178bb042738d57c3e1
commit | author | age
531cd2 1 package com.gitblit.wicket.pages;
JM 2
3e087a 3 import java.text.ParseException;
531cd2 4
JM 5 import org.apache.wicket.PageParameters;
6 import org.apache.wicket.markup.html.basic.Label;
7 import org.apache.wicket.markup.html.link.BookmarkablePageLink;
8 import org.eclipse.jgit.lib.Constants;
9 import org.eclipse.jgit.lib.Repository;
10 import org.eclipse.jgit.revwalk.RevCommit;
11
12 import com.gitblit.utils.JGitUtils;
cf9550 13 import com.gitblit.utils.MarkdownUtils;
531cd2 14 import com.gitblit.wicket.RepositoryPage;
JM 15 import com.gitblit.wicket.WicketUtils;
16
17 public class MarkdownPage extends RepositoryPage {
18     
19     public MarkdownPage(PageParameters params) {
20         super(params);
21
22         final String markdownPath = WicketUtils.getPath(params);
23
24         Repository r = getRepository();
25         RevCommit commit = JGitUtils.getCommit(r, objectId);
26
27         // markdown page links
28         add(new Label("blameLink", getString("gb.blame")));
29         add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class, WicketUtils.newPathParameter(repositoryName, objectId, markdownPath)));
30         add(new BookmarkablePageLink<Void>("rawLink", RawPage.class, WicketUtils.newPathParameter(repositoryName, objectId, markdownPath)));
31         add(new BookmarkablePageLink<Void>("headLink", MarkdownPage.class, WicketUtils.newPathParameter(repositoryName, Constants.HEAD, markdownPath)));
32
3e087a 33         // Read raw markdown content and transform it to html        
JM 34         String markdownText = JGitUtils.getRawContentAsString(r, commit, markdownPath);
35         String htmlText;
531cd2 36         try {
cf9550 37             htmlText = MarkdownUtils.transformMarkdown(markdownText);
531cd2 38         } catch (ParseException p) {
3e087a 39             error(p.getMessage());
JM 40             htmlText = markdownText;
531cd2 41         }
JM 42         
43         // Add the html to the page
44         add(new Label("markdownText", htmlText).setEscapeModelStrings(false));
45     }
46
47     @Override
48     protected String getPageName() {
49         return getString("gb.markdown");
50     }
51 }