Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

BlobPage.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.apache.wicket.markup.html.link.BookmarkablePageLink;
  8. import org.eclipse.jgit.lib.Constants;
  9. import org.eclipse.jgit.lib.Repository;
  10. import org.eclipse.jgit.revwalk.RevCommit;
  11. import com.gitblit.Keys;
  12. import com.gitblit.StoredSettings;
  13. import com.gitblit.utils.JGitUtils;
  14. import com.gitblit.wicket.LinkPanel;
  15. import com.gitblit.wicket.RepositoryPage;
  16. import com.gitblit.wicket.WicketUtils;
  17. import com.gitblit.wicket.panels.PathBreadcrumbsPanel;
  18. public class BlobPage extends RepositoryPage {
  19. public BlobPage(PageParameters params) {
  20. super(params);
  21. final String blobPath = WicketUtils.getPath(params);
  22. Repository r = getRepository();
  23. RevCommit commit = JGitUtils.getCommit(r, objectId);
  24. // blob page links
  25. add(new Label("blameLink", getString("gb.blame")));
  26. add(new Label("historyLink", getString("gb.history")));
  27. add(new BookmarkablePageLink<Void>("rawLink", RawPage.class, WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));
  28. add(new BookmarkablePageLink<Void>("headLink", BlobPage.class, WicketUtils.newPathParameter(repositoryName, Constants.HEAD, blobPath)));
  29. add(new LinkPanel("shortlog", "title", commit.getShortMessage(), CommitPage.class, newCommitParameter()));
  30. add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, blobPath, objectId));
  31. String extension = null;
  32. if (blobPath.lastIndexOf('.') > -1) {
  33. extension = blobPath.substring(blobPath.lastIndexOf('.') + 1);
  34. }
  35. // Map the extensions to types
  36. Map<String, Integer> map = new HashMap<String, Integer>();
  37. for (String ext : StoredSettings.getStrings(Keys.web_prettyPrintExtensions)) {
  38. map.put(ext.toLowerCase(), 1);
  39. }
  40. for (String ext : StoredSettings.getStrings(Keys.web_imageExtensions)) {
  41. map.put(ext.toLowerCase(), 2);
  42. }
  43. for (String ext : StoredSettings.getStrings(Keys.web_binaryExtensions)) {
  44. map.put(ext.toLowerCase(), 3);
  45. }
  46. if (extension != null) {
  47. int type = 0;
  48. if (map.containsKey(extension)) {
  49. type = map.get(extension);
  50. }
  51. Component c = null;
  52. switch (type) {
  53. case 1:
  54. // PrettyPrint blob text
  55. c = new Label("blobText", JGitUtils.getRawContentAsString(r, commit, blobPath));
  56. WicketUtils.setCssClass(c, "prettyprint");
  57. break;
  58. case 2:
  59. // TODO image blobs
  60. c = new Label("blobText", "Image File");
  61. break;
  62. case 3:
  63. // TODO binary blobs
  64. c = new Label("blobText", "Binary File");
  65. break;
  66. default:
  67. // plain text
  68. c = new Label("blobText", JGitUtils.getRawContentAsString(r, commit, blobPath));
  69. WicketUtils.setCssClass(c, "plainprint");
  70. }
  71. add(c);
  72. } else {
  73. // plain text
  74. Label blobLabel = new Label("blobText", JGitUtils.getRawContentAsString(r, commit, blobPath));
  75. WicketUtils.setCssClass(blobLabel, "plainprint");
  76. add(blobLabel);
  77. }
  78. }
  79. @Override
  80. protected String getPageName() {
  81. return getString("gb.view");
  82. }
  83. }