James Moger
2013-05-28 034e4bc7cd5ca3271e59ebdba1b25beb37b4b73c
src/main/java/com/gitblit/wicket/pages/BlobPage.java
@@ -39,6 +39,8 @@
public class BlobPage extends RepositoryPage {
   protected String fileExtension;
   public BlobPage(PageParameters params) {
      super(params);
@@ -124,21 +126,41 @@
            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();
@@ -161,7 +183,7 @@
      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\">");
      }
@@ -191,4 +213,9 @@
   protected String getPageName() {
      return getString("gb.view");
   }
   @Override
   protected Class<? extends BasePage> getRepoNavPageClass() {
      return TreePage.class;
   }
}