commit | author | age
|
dc7c2f
|
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 |
*/
|
|
16 |
package com.gitblit.wicket.pages;
|
|
17 |
|
|
18 |
import java.util.List;
|
|
19 |
|
|
20 |
import org.apache.wicket.PageParameters;
|
|
21 |
import org.apache.wicket.markup.html.basic.Label;
|
|
22 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
ff17f7
|
23 |
import org.apache.wicket.markup.html.link.ExternalLink;
|
8a71a1
|
24 |
import org.apache.wicket.markup.html.panel.Fragment;
|
dc7c2f
|
25 |
import org.eclipse.jgit.lib.Repository;
|
JM |
26 |
import org.eclipse.jgit.revwalk.RevCommit;
|
|
27 |
|
ff17f7
|
28 |
import com.gitblit.servlet.RawServlet;
|
fef234
|
29 |
import com.gitblit.utils.BugtraqProcessor;
|
dc7c2f
|
30 |
import com.gitblit.utils.JGitUtils;
|
JM |
31 |
import com.gitblit.utils.StringUtils;
|
|
32 |
import com.gitblit.wicket.CacheControl;
|
|
33 |
import com.gitblit.wicket.CacheControl.LastModified;
|
|
34 |
import com.gitblit.wicket.MarkupProcessor;
|
|
35 |
import com.gitblit.wicket.MarkupProcessor.MarkupDocument;
|
8a71a1
|
36 |
import com.gitblit.wicket.MarkupProcessor.MarkupSyntax;
|
dc7c2f
|
37 |
import com.gitblit.wicket.WicketUtils;
|
JM |
38 |
|
|
39 |
@CacheControl(LastModified.BOOT)
|
|
40 |
public class DocPage extends RepositoryPage {
|
|
41 |
|
|
42 |
public DocPage(PageParameters params) {
|
|
43 |
super(params);
|
|
44 |
|
|
45 |
final String path = WicketUtils.getPath(params).replace("%2f", "/").replace("%2F", "/");
|
11a173
|
46 |
MarkupProcessor processor = new MarkupProcessor(app().settings(), app().xssFilter());
|
dc7c2f
|
47 |
|
JM |
48 |
Repository r = getRepository();
|
|
49 |
RevCommit commit = JGitUtils.getCommit(r, objectId);
|
99d0d4
|
50 |
String [] encodings = getEncodings();
|
dc7c2f
|
51 |
|
JM |
52 |
// Read raw markup content and transform it to html
|
|
53 |
String documentPath = path;
|
|
54 |
String markupText = JGitUtils.getStringContent(r, commit.getTree(), path, encodings);
|
|
55 |
|
|
56 |
// Hunt for document
|
|
57 |
if (StringUtils.isEmpty(markupText)) {
|
|
58 |
String name = StringUtils.stripFileExtension(path);
|
|
59 |
|
e13171
|
60 |
List<String> docExtensions = processor.getAllExtensions();
|
dc7c2f
|
61 |
for (String ext : docExtensions) {
|
JM |
62 |
String checkName = name + "." + ext;
|
|
63 |
markupText = JGitUtils.getStringContent(r, commit.getTree(), checkName, encodings);
|
|
64 |
if (!StringUtils.isEmpty(markupText)) {
|
|
65 |
// found it
|
|
66 |
documentPath = path;
|
|
67 |
break;
|
|
68 |
}
|
|
69 |
}
|
|
70 |
}
|
|
71 |
|
b635f4
|
72 |
if (markupText == null) {
|
JM |
73 |
markupText = "";
|
|
74 |
}
|
|
75 |
|
fef234
|
76 |
BugtraqProcessor bugtraq = new BugtraqProcessor(app().settings());
|
JM |
77 |
markupText = bugtraq.processText(getRepository(), repositoryName, markupText);
|
|
78 |
|
8a71a1
|
79 |
Fragment fragment;
|
JM |
80 |
MarkupDocument markupDoc = processor.parse(repositoryName, getBestCommitId(commit), documentPath, markupText);
|
|
81 |
if (MarkupSyntax.PLAIN.equals(markupDoc.syntax)) {
|
|
82 |
fragment = new Fragment("doc", "plainContent", this);
|
|
83 |
} else {
|
|
84 |
fragment = new Fragment("doc", "markupContent", this);
|
|
85 |
}
|
|
86 |
|
dc7c2f
|
87 |
// document page links
|
275496
|
88 |
fragment.add(new BookmarkablePageLink<Void>("editLink", EditFilePage.class,
|
PM |
89 |
WicketUtils.newPathParameter(repositoryName, objectId, documentPath)));
|
8a71a1
|
90 |
fragment.add(new BookmarkablePageLink<Void>("blameLink", BlamePage.class,
|
dc7c2f
|
91 |
WicketUtils.newPathParameter(repositoryName, objectId, documentPath)));
|
8a71a1
|
92 |
fragment.add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,
|
dc7c2f
|
93 |
WicketUtils.newPathParameter(repositoryName, objectId, documentPath)));
|
ff17f7
|
94 |
String rawUrl = RawServlet.asLink(getContextUrl(), repositoryName, objectId, documentPath);
|
JM |
95 |
fragment.add(new ExternalLink("rawLink", rawUrl));
|
dc7c2f
|
96 |
|
8a71a1
|
97 |
fragment.add(new Label("content", markupDoc.html).setEscapeModelStrings(false));
|
JM |
98 |
add(fragment);
|
dc7c2f
|
99 |
}
|
JM |
100 |
|
|
101 |
@Override
|
|
102 |
protected String getPageName() {
|
|
103 |
return getString("gb.docs");
|
|
104 |
}
|
|
105 |
|
|
106 |
@Override
|
5d5e55
|
107 |
protected boolean isCommitPage() {
|
JM |
108 |
return true;
|
|
109 |
}
|
|
110 |
|
|
111 |
@Override
|
dc7c2f
|
112 |
protected Class<? extends BasePage> getRepoNavPageClass() {
|
JM |
113 |
return DocsPage.class;
|
|
114 |
}
|
|
115 |
}
|