| | |
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | | import com.gitblit.utils.StringUtils;
|
| | | import com.gitblit.wicket.CacheControl;
|
| | | import com.gitblit.wicket.CacheControl.LastModified;
|
| | | import com.gitblit.wicket.ExternalImage;
|
| | | import com.gitblit.wicket.MarkupProcessor;
|
| | | import com.gitblit.wicket.WicketUtils;
|
| | | import com.gitblit.wicket.panels.CommitHeaderPanel;
|
| | | import com.gitblit.wicket.panels.PathBreadcrumbsPanel;
|
| | |
|
| | | @CacheControl(LastModified.BOOT)
|
| | | public class BlobPage extends RepositoryPage {
|
| | |
|
| | | protected String fileExtension;
|
| | |
| | | Repository r = getRepository();
|
| | | final String blobPath = WicketUtils.getPath(params);
|
| | | String [] encodings = GitBlit.getEncodings();
|
| | | |
| | |
|
| | | if (StringUtils.isEmpty(blobPath)) {
|
| | | // blob by objectid
|
| | |
|
| | |
| | | extension = blobPath.substring(blobPath.lastIndexOf('.') + 1).toLowerCase();
|
| | | }
|
| | |
|
| | | // see if we should redirect to the markdown page
|
| | | for (String ext : GitBlit.getStrings(Keys.web.markdownExtensions)) {
|
| | | // see if we should redirect to the doc page
|
| | | MarkupProcessor processor = new MarkupProcessor(GitBlit.getSettings());
|
| | | for (String ext : processor.getMarkupExtensions()) {
|
| | | if (ext.equals(extension)) {
|
| | | setResponsePage(MarkdownPage.class, params);
|
| | | setResponsePage(DocPage.class, params);
|
| | | return;
|
| | | }
|
| | | }
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | protected String missingBlob(String blobPath, RevCommit commit) {
|
| | | StringBuilder sb = new StringBuilder();
|
| | | sb.append("<div class=\"alert alert-error\">");
|
| | |
| | |
|
| | | protected String generateSourceView(String source, String extension, boolean prettyPrint) {
|
| | | String [] lines = source.split("\n");
|
| | | |
| | |
|
| | | StringBuilder sb = new StringBuilder();
|
| | | sb.append("<!-- start blob table -->");
|
| | | sb.append("<table width=\"100%\"><tbody><tr>");
|
| | | |
| | |
|
| | | // nums column
|
| | | sb.append("<!-- start nums column -->");
|
| | | sb.append("<td id=\"nums\">");
|
| | | sb.append("<pre>");
|
| | | String numPattern = "<span id=\"L{0}\" class=\"num\">{0}</span>\n";
|
| | | String numPattern = "<span id=\"L{0}\" class=\"jump\"></span><a href=\"#L{0}\">{0}</a>\n";
|
| | | for (int i = 0; i < lines.length; i++) {
|
| | | sb.append(MessageFormat.format(numPattern, "" + (i + 1)));
|
| | | }
|
| | | sb.append("</pre>");
|
| | | sb.append("<!-- end nums column -->");
|
| | | sb.append("</td>");
|
| | | |
| | |
|
| | | sb.append("<!-- start lines column -->");
|
| | | sb.append("<td id=\"lines\">");
|
| | | sb.append("<div class=\"sourceview\">");
|
| | |
| | | sb.append("<pre class=\"plainprint\">");
|
| | | }
|
| | | lines = StringUtils.escapeForHtml(source, true).split("\n");
|
| | | |
| | |
|
| | | sb.append("<table width=\"100%\"><tbody>");
|
| | | |
| | | String linePattern = "<tr class=\"{0}\"><td><a href=\"#L{2}\">{1}</a>\r</tr>";
|
| | |
|
| | | String linePattern = "<tr class=\"{0}\"><td><div><span class=\"line\">{1}</span></div>\r</tr>";
|
| | | for (int i = 0; i < lines.length; i++) {
|
| | | String line = lines[i].replace('\r', ' ');
|
| | | String cssClass = (i % 2 == 0) ? "even" : "odd";
|
| | | if (StringUtils.isEmpty(line.trim())) {
|
| | | line = " ";
|
| | | }
|
| | | sb.append(MessageFormat.format(linePattern, cssClass, line, "" + (i + 1)));
|
| | | }
|
| | | sb.append("</tbody></table></pre>");
|
| | |
| | | sb.append("</div>");
|
| | | sb.append("</td>");
|
| | | sb.append("<!-- end lines column -->");
|
| | | |
| | |
|
| | | sb.append("</tr></tbody></table>");
|
| | | sb.append("<!-- end blob table -->");
|
| | | |
| | |
|
| | | return sb.toString();
|
| | | }
|
| | |
|
| | |
| | | protected String getPageName() {
|
| | | return getString("gb.view");
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | protected Class<? extends BasePage> getRepoNavPageClass() {
|
| | | return TreePage.class;
|