You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BlobPage.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package com.gitblit.wicket.pages;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. import org.apache.wicket.Component;
  5. import org.apache.wicket.PageParameters;
  6. import org.apache.wicket.markup.html.basic.Label;
  7. import org.eclipse.jgit.lib.Repository;
  8. import org.eclipse.jgit.revwalk.RevCommit;
  9. import com.gitblit.StoredSettings;
  10. import com.gitblit.utils.JGitUtils;
  11. import com.gitblit.wicket.LinkPanel;
  12. import com.gitblit.wicket.RepositoryPage;
  13. import com.gitblit.wicket.WicketUtils;
  14. import com.gitblit.wicket.panels.PathBreadcrumbsPanel;
  15. public class BlobPage extends RepositoryPage {
  16. public BlobPage(PageParameters params) {
  17. super(params, "blob");
  18. final String blobPath = params.getString("f", null);
  19. Repository r = getRepository();
  20. RevCommit commit = JGitUtils.getCommit(r, commitId);
  21. // blob page links
  22. add(new Label("historyLink", "history"));
  23. add(new Label("rawLink", "raw"));
  24. add(new Label("headLink", "HEAD"));
  25. add(new LinkPanel("shortlog", "title", commit.getShortMessage(), CommitPage.class, newCommitParameter()));
  26. add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, blobPath, commitId));
  27. String extension = null;
  28. if (blobPath.lastIndexOf('.') > -1) {
  29. extension = blobPath.substring(blobPath.lastIndexOf('.') + 1);
  30. }
  31. // Map the extensions to types
  32. Map<String, Integer> map = new HashMap<String, Integer>();
  33. for (String ext : StoredSettings.getStrings("prettyPrintExtensions")) {
  34. map.put(ext.toLowerCase(), 1);
  35. }
  36. for (String ext : StoredSettings.getStrings("imageExtensions")) {
  37. map.put(ext.toLowerCase(), 2);
  38. }
  39. for (String ext : StoredSettings.getStrings("binaryExtensions")) {
  40. map.put(ext.toLowerCase(), 3);
  41. }
  42. if (extension != null) {
  43. int type = 0;
  44. if (map.containsKey(extension)) {
  45. type = map.get(extension);
  46. }
  47. Component c = null;
  48. switch (type) {
  49. case 1:
  50. // PrettyPrint blob text
  51. c = new Label("blobText", JGitUtils.getRawContentAsString(r, commit, blobPath));
  52. WicketUtils.setCssClass(c, "prettyprint");
  53. break;
  54. case 2:
  55. // TODO image blobs
  56. c = new Label("blobText", "Image File");
  57. break;
  58. case 3:
  59. // TODO binary blobs
  60. c = new Label("blobText", "Binary File");
  61. break;
  62. default:
  63. // plain text
  64. c = new Label("blobText", JGitUtils.getRawContentAsString(r, commit, blobPath));
  65. WicketUtils.setCssClass(c, "plainprint");
  66. }
  67. add(c);
  68. } else {
  69. // plain text
  70. Label blobLabel = new Label("blobText", JGitUtils.getRawContentAsString(r, commit, blobPath));
  71. WicketUtils.setCssClass(blobLabel, "plainprint");
  72. add(blobLabel);
  73. }
  74. // close repository
  75. r.close();
  76. // footer
  77. addFooter();
  78. }
  79. }