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