James Moger
2011-05-28 28d6b2a860740557bf93dd0f9a48d059379ed696
commit | author | age
f13c4c 1 /*
JM 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  */
531cd2 16 package com.gitblit.wicket.pages;
JM 17
3e087a 18 import java.text.ParseException;
531cd2 19
JM 20 import org.apache.wicket.PageParameters;
21 import org.apache.wicket.markup.html.basic.Label;
22 import org.apache.wicket.markup.html.link.BookmarkablePageLink;
23 import org.eclipse.jgit.lib.Constants;
24 import org.eclipse.jgit.lib.Repository;
25 import org.eclipse.jgit.revwalk.RevCommit;
26
27 import com.gitblit.utils.JGitUtils;
cf9550 28 import com.gitblit.utils.MarkdownUtils;
531cd2 29 import com.gitblit.wicket.WicketUtils;
JM 30
31 public class MarkdownPage extends RepositoryPage {
2a7306 32
531cd2 33     public MarkdownPage(PageParameters params) {
JM 34         super(params);
35
36         final String markdownPath = WicketUtils.getPath(params);
37
38         Repository r = getRepository();
39         RevCommit commit = JGitUtils.getCommit(r, objectId);
40
41         // markdown page links
42         add(new Label("blameLink", getString("gb.blame")));
2a7306 43         add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,
JM 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)));
531cd2 49
2a7306 50         // Read raw markdown content and transform it to html
3e087a 51         String markdownText = JGitUtils.getRawContentAsString(r, commit, markdownPath);
JM 52         String htmlText;
531cd2 53         try {
cf9550 54             htmlText = MarkdownUtils.transformMarkdown(markdownText);
531cd2 55         } catch (ParseException p) {
3e087a 56             error(p.getMessage());
JM 57             htmlText = markdownText;
531cd2 58         }
2a7306 59
531cd2 60         // Add the html to the page
JM 61         add(new Label("markdownText", htmlText).setEscapeModelStrings(false));
62     }
63
64     @Override
65     protected String getPageName() {
66         return getString("gb.markdown");
67     }
68 }