From f5654729757eedefc1c656ac4be764b6a19ada2e Mon Sep 17 00:00:00 2001 From: James Moger Date: Fri, 29 Mar 2013 10:59:26 -0400 Subject: Add more error checking to blob page --- .../com/gitblit/wicket/GitBlitWebApp.properties | 3 ++- .../java/com/gitblit/wicket/pages/BlobPage.java | 23 ++++++++++++++++++++-- .../gitblit/wicket/panels/CommitHeaderPanel.java | 1 + 3 files changed, 24 insertions(+), 3 deletions(-) (limited to 'src/main/java/com/gitblit') diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties index 7a2b1bb3..b0d559f6 100644 --- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties +++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties @@ -444,4 +444,5 @@ gb.excludeFromActivity = exclude from activity page gb.isSparkleshared = repository is Sparkleshared gb.owners = owners gb.sessionEnded = Session has been closed -gb.closeBrowser = Please close the browser to properly end the session. \ No newline at end of file +gb.closeBrowser = Please close the browser to properly end the session. +gb.doesNotExistInTree = {0} does not exist in tree {1} \ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/pages/BlobPage.java b/src/main/java/com/gitblit/wicket/pages/BlobPage.java index e2b8546b..ab0f0f16 100644 --- a/src/main/java/com/gitblit/wicket/pages/BlobPage.java +++ b/src/main/java/com/gitblit/wicket/pages/BlobPage.java @@ -124,20 +124,39 @@ public class BlobPage extends RepositoryPage { 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, type == 1); + } add(new Label("blobText", table).setEscapeModelStrings(false)); add(new Image("blobImage").setVisible(false)); } } 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, false); + } add(new Label("blobText", table).setEscapeModelStrings(false)); add(new Image("blobImage").setVisible(false)); } } } + protected String missingBlob(String blobPath, RevCommit commit) { + StringBuilder sb = new StringBuilder(); + sb.append("
"); + String pattern = getString("gb.doesNotExistInTree").replace("{0}", "{0}").replace("{1}", "{1}"); + sb.append(MessageFormat.format(pattern, blobPath, commit.getTree().getId().getName())); + sb.append("
"); + return sb.toString(); + } + protected String generateSourceView(String source, boolean prettyPrint) { String [] lines = source.split("\n"); diff --git a/src/main/java/com/gitblit/wicket/panels/CommitHeaderPanel.java b/src/main/java/com/gitblit/wicket/panels/CommitHeaderPanel.java index bb960cca..eb757501 100644 --- a/src/main/java/com/gitblit/wicket/panels/CommitHeaderPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/CommitHeaderPanel.java @@ -33,6 +33,7 @@ public class CommitHeaderPanel extends BasePanel { add(new Label("commitid")); add(new Label("author")); add(new Label("date")); + add(new Label("authorAvatar")); } public CommitHeaderPanel(String id, String repositoryName, RevCommit c) { -- cgit v1.2.3