| | |
| | |
|
| | | public class BlobPage extends RepositoryPage {
|
| | |
|
| | | protected String fileExtension;
|
| | |
|
| | | public BlobPage(PageParameters params) {
|
| | | super(params);
|
| | |
|
| | |
| | | default:
|
| | | // plain text
|
| | | String source = JGitUtils.getStringContent(r, commit.getTree(), blobPath, encodings);
|
| | | String table = generateSourceView(source, type == 1);
|
| | | String table;
|
| | | if (source == null) {
|
| | | table = missingBlob(blobPath, commit);
|
| | | } else {
|
| | | table = generateSourceView(source, extension, type == 1);
|
| | | }
|
| | | add(new Label("blobText", table).setEscapeModelStrings(false));
|
| | | add(new Image("blobImage").setVisible(false));
|
| | | fileExtension = extension;
|
| | | }
|
| | | } else {
|
| | | // plain text
|
| | | String source = JGitUtils.getStringContent(r, commit.getTree(), blobPath, encodings);
|
| | | String table = generateSourceView(source, false);
|
| | | String table;
|
| | | if (source == null) {
|
| | | table = missingBlob(blobPath, commit);
|
| | | } else {
|
| | | table = generateSourceView(source, null, false);
|
| | | }
|
| | | add(new Label("blobText", table).setEscapeModelStrings(false));
|
| | | add(new Image("blobImage").setVisible(false));
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | protected String generateSourceView(String source, boolean prettyPrint) {
|
| | | protected String missingBlob(String blobPath, RevCommit commit) {
|
| | | StringBuilder sb = new StringBuilder();
|
| | | sb.append("<div class=\"alert alert-error\">");
|
| | | String pattern = getString("gb.doesNotExistInTree").replace("{0}", "<b>{0}</b>").replace("{1}", "<b>{1}</b>");
|
| | | sb.append(MessageFormat.format(pattern, blobPath, commit.getTree().getId().getName()));
|
| | | sb.append("</div>");
|
| | | return sb.toString();
|
| | | }
|
| | |
|
| | | protected String generateSourceView(String source, String extension, boolean prettyPrint) {
|
| | | String [] lines = source.split("\n");
|
| | |
|
| | | StringBuilder sb = new StringBuilder();
|
| | |
| | | sb.append("<td id=\"lines\">");
|
| | | sb.append("<div class=\"sourceview\">");
|
| | | if (prettyPrint) {
|
| | | sb.append("<pre class=\"prettyprint\">");
|
| | | sb.append("<pre class=\"prettyprint lang-" + extension + "\">");
|
| | | } else {
|
| | | sb.append("<pre class=\"plainprint\">");
|
| | | }
|
| | |
| | | protected String getPageName() {
|
| | | return getString("gb.view");
|
| | | }
|
| | | |
| | | @Override
|
| | | protected Class<? extends BasePage> getRepoNavPageClass() {
|
| | | return TreePage.class;
|
| | | }
|
| | | }
|