James Moger
2012-02-09 5cc40c89abafdcccbc8a5b2cf3890780ccff908e
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
5450d0 42         add(new BookmarkablePageLink<Void>("blameLink", BlamePage.class,
JM 43                 WicketUtils.newPathParameter(repositoryName, objectId, markdownPath)));
2a7306 44         add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,
JM 45                 WicketUtils.newPathParameter(repositoryName, objectId, markdownPath)));
46         add(new BookmarkablePageLink<Void>("rawLink", RawPage.class, WicketUtils.newPathParameter(
47                 repositoryName, objectId, markdownPath)));
48         add(new BookmarkablePageLink<Void>("headLink", MarkdownPage.class,
49                 WicketUtils.newPathParameter(repositoryName, Constants.HEAD, markdownPath)));
531cd2 50
2a7306 51         // Read raw markdown content and transform it to html
4ab184 52         String markdownText = JGitUtils.getStringContent(r, commit.getTree(), markdownPath);
3e087a 53         String htmlText;
531cd2 54         try {
cf9550 55             htmlText = MarkdownUtils.transformMarkdown(markdownText);
531cd2 56         } catch (ParseException p) {
3e087a 57             error(p.getMessage());
JM 58             htmlText = markdownText;
531cd2 59         }
2a7306 60
531cd2 61         // Add the html to the page
JM 62         add(new Label("markdownText", htmlText).setEscapeModelStrings(false));
63     }
64
65     @Override
66     protected String getPageName() {
67         return getString("gb.markdown");
68     }
69 }