HTMLCreator { public static String createChangedPathsTable(final SortedSet<ChangedPath> changedPaths, final long revision, final String pathAtRevision, final String baseURL, final RepositoryName repositoryName, final boolean showLatestRevInfo, final boolean linkToHead, final HttpServletResponse response) { final StringBuilder sb = new StringBuilder("<table class=\"changedPathsTable\">\n"); sb.append(" <tr>\n"); sb.append(" <th align=\"left\">Action</th>\n"); sb.append(" <th align=\"left\">Path</th>\n"); sb.append(" </tr>\n"); for (final ChangedPath path : changedPaths) { final ChangeType changeType = path.getType(); sb.append(" <tr>\n"); sb.append(" <td valign=\"top\"><i>").append(changeType).append("</i></td>\n"); sb.append(" <td>"); String goToUrl; switch (changeType) { case ADDED: case REPLACED: goToUrl = createGoToUrl(baseURL, path.getPath(), revision, repositoryName, linkToHead); if (response != null) { goToUrl = response.encodeURL(goToUrl); } sb.append("<a href=\"").append(goToUrl); if (showLatestRevInfo) { sb.append("&showlatestrevinfo=true"); } sb.append("\" title=\"Show\">"); if (path.getPath().equals(pathAtRevision)) { sb.append("<i>").append(path.getPath()).append("</i>").append("</a>"); } else { sb.append(path.getPath()).append("</a>"); } break; case MODIFIED: String diffUrl = createDiffUrl(baseURL, path.getPath(), revision, repositoryName, linkToHead); if (response != null) { diffUrl = response.encodeURL(diffUrl); } sb.append("<a href=\"").append(diffUrl); if (showLatestRevInfo) { sb.append("&showlatestrevinfo=true"); } sb.append("\" title=\"Diff with previous version\">"); if (path.getPath().equals(pathAtRevision)) { sb.append("<i>").append(path.getPath()).append("</i>").append("</a>"); } else { sb.append(path.getPath()).append("</a>"); } break; case DELETED: goToUrl = createGoToUrl(baseURL, path.getPath(), revision - 1, repositoryName, false); if (response != null) { goToUrl = response.encodeURL(goToUrl); } sb.append("<a href=\"").append(goToUrl); sb.append("\" title=\"Show previous revision\"><del>").append(path.getPath()).append("</del></a>"); break; default: throw new IllegalArgumentException("Unsupported type: " + changeType); } if (path.getCopyPath() != null) { sb.append("<br>(<i>Copy from</i> "); goToUrl = createGoToUrl(baseURL, path.getCopyPath(), path.getCopyRevision(), repositoryName, false); if (response != null) { goToUrl = response.encodeURL(goToUrl); } sb.append("<a href=\"").append(goToUrl); if (showLatestRevInfo) { sb.append("&showlatestrevinfo=true"); } sb.append("\" title=\"Show\">").append(path.getCopyPath()).append("</a>").append(" @ "); String revisionInfoUrl = createRevisionInfoUrl(baseURL, path.getCopyRevision(), repositoryName); if (response != null) { revisionInfoUrl = response.encodeURL(revisionInfoUrl); } sb.append("<a href=\"").append(revisionInfoUrl); sb.append("\">"); sb.append(path.getCopyRevision()).append("</a>)"); } sb.append("</td>\n"); sb.append(" </tr>\n"); } sb.append("</table>"); return sb.toString(); } private  HTMLCreator(); static String createRevisionDetailBody(final String bodyTemplate, final LogEntry logEntry, final String baseURL,
                                                final RepositoryName repositoryName, final DateFormat dateFormat,
                                                final HttpServletResponse response); static String createChangedPathsTable(final SortedSet<ChangedPath> changedPaths, final long revision,
                                               final String pathAtRevision, final String baseURL,
                                               final RepositoryName repositoryName, final boolean showLatestRevInfo,
                                               final boolean linkToHead, final HttpServletResponse response); static final String LOG_MESSAGE_KEY; static final String AUTHOR_KEY; static final String DATE_KEY; static final String ADDED_COUNT_KEY; static final String MODIFIED_COUNT_KEY; static final String REPLACED_COUNT_KEY; static final String DELETED_COUNT_KEY; static final String CHANGED_PATHS_KEY; }
@Test public void testCreateChangedPathsTable() throws Exception { final String result = "<table class=\"changedPathsTable\">\n" + " <tr>\n" + " <th align=\"left\">Action</th>\n" + " <th align=\"left\">Path</th>\n" + " </tr>\n" + " <tr>\n" + " <td valign=\"top\"><i>Modified</i></td>\n" + " <td><a href=\"repos/sandbox/diff/file1.java?revision=1&entries=/file1.java@1&entries=/file1.java@0\" title=\"Diff with previous version\"><i>/file1.java</i></a></td>\n" + " </tr>\n" + " <tr>\n" + " <td valign=\"top\"><i>Deleted</i></td>\n" + " <td><a href=\"repos/sandbox/goto/file2.html?revision=0\" title=\"Show previous revision\"><del>/file2.html</del></a></td>\n" + " </tr>\n" + " <tr>\n" + " <td valign=\"top\"><i>Added</i></td>\n" + " <td><a href=\"repos/sandbox/goto/file3.abc?revision=1\" title=\"Show\">/file3.abc</a><br>(<i>Copy from</i> <a href=\"repos/sandbox/goto/branch/file3.abc?revision=1\" title=\"Show\">/branch/file3.abc</a> @ <a href=\"repos/sandbox/info?revision=1\">1</a>)</td>\n" + " </tr>\n" + " <tr>\n" + " <td valign=\"top\"><i>Replaced</i></td>\n" + " <td><a href=\"repos/sandbox/goto/file4.def?revision=1\" title=\"Show\">/file4.def</a></td>\n" + " </tr>\n" + "</table>"; final SortedSet<ChangedPath> changedPaths = new TreeSet<ChangedPath>(); changedPaths.add(new ChangedPath("/file1.java", null, 1, ChangeType.MODIFIED)); changedPaths.add(new ChangedPath("/file2.html", null, 1, ChangeType.DELETED)); changedPaths.add(new ChangedPath("/file3.abc", "/branch/file3.abc", 1, ChangeType.ADDED)); changedPaths.add(new ChangedPath("/file4.def", null, 1, ChangeType.REPLACED)); final LogEntry logEntry = TestUtils.createLogEntry(1, "jesper", new Date(), "Testing", changedPaths); assertEquals(result, HTMLCreator.createChangedPathsTable(logEntry.getChangedPaths(), logEntry.getRevision(), "/file1.java", "", new RepositoryName("sandbox"), false, false, new MockHttpServletResponse())); }