Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.selesse.jxlint.report;
  
 
 import java.util.*;
 
 public class SequentialHtmlReporter extends Reporter {
     private final String nameAndVersion = .getProgramName() + " " + .getProgramVersion();
     private final Pattern alphanumeric = Pattern.compile("[a-zA-Z0-9_]");
 
 
     public SequentialHtmlReporter(PrintStream outProgramSettings programSettingsList<LintErrorlintErrorList) {
         super(outprogramSettingslintErrorList);
          = TreeMultimap.create(new Comparator<LintRule>() {
             @Override
             public int compare(LintRule o1LintRule o2) {
                 return LintRuleComparator.compareCategoryThenName(o1o2);
             }
         }, new Comparator<LintError>() {
             @Override
             public int compare(LintError o1LintError o2) {
                 return LintRuleComparator.compareLineNumbers(o1o2);
             }
         });
     }
 
     @Override
     protected void printHeader() {
         .println("<!doctype HTML>");
         .println("<head>");
         .println("<title> " +  + " - Report </title>");
         .println("</head>");
         .println("<body>");
         .println("<h1> <center> " +  + " - Lint Report </center> </h1>");
         .println("<h2> <center> " + new Date() + " </center> </h2>");
         printErrorSummary();
     }
 
     private void printErrorSummary() {
         .println("<div>" + getErrorReportString() + "</div>");
 
         for (LintError lintError : ) {
             .put(lintError.getViolatedRule(), lintError);
         }
 
         if (!.isEmpty()) {
             .println("<ul>");
             for (LintRule lintRule : .keySet()) {
                 Collection<LintErrorerrorCollection = .get(lintRule);
 
                 .println("<li> " + errorCollection.size() + " violations for " + lintRule.getName() + "</li>");
             }
             .println("</ul>");
         }
     }
 
     @Override
     protected void printCategoryHeader(Enum<?> category) {
         .println("<h2> <u> " + category + " </u> </h2>");
     }
 
     @Override
     protected void printError(LintError error) {
         .println("<b>[" + error.getSeverity() + "] <a href=\"#" + getHrefSafeName(error) + "\">" +
                 error.getViolatedRule().getName() + "</a></b>");
         .print("violated in <a href=\"" + error.getFile() + "\">" +
                 FileUtils.getRelativePath(LintRulesImpl.getInstance().getSourceDirectory(), error.getFile()) + "</a>");
         if (error.getLineNumber() > 0) {
             .print(" on line " + error.getLineNumber());
         }
         .println("<br/>");
         .println(HtmlEscapers.htmlEscaper().escape(error.getMessage()) + "<br>");
         if (error.getException() != null) {
             String exceptionLines = Joiner.on("<br>").join(error.getException().getStackTrace());
             .println("<pre>" + exceptionLines + "</pre>");
         }
         .println("<hr>");
     }

    
Returns a href-safe name. Something that can be put in 'a href="HERE"'.
 
     private String getHrefSafeName(LintError lintError) {
         String hrefSafeName = "" + lintError.getViolatedRule().hashCode();
 
         Matcher matcher = .matcher(lintError.getViolatedRule().getName());
        StringBuilder stringBuilder = new StringBuilder();
        while (matcher.find()) {
            stringBuilder.append(matcher.group());
        }
        if (stringBuilder.length() > 0) {
            hrefSafeName = stringBuilder.toString();
        }
        return hrefSafeName.toLowerCase();
    }
    @Override
    protected void printFooter() {
        .println("<hr>");
        .println("<div>");
        printUniqueErrors();
        .println("</div>");
        .println("</body>");
        .println("</html>");
    }
    private void printUniqueErrors() {
        List<StringuniqueErrorTypes = Lists.newArrayList();
        for (LintError lintError : ) {
            String className = lintError.getViolatedRule().getClass().getSimpleName();
            if (!uniqueErrorTypes.contains(className)) {
                uniqueErrorTypes.add(className);
                printDetailedHtmlError(lintError);
            }
        }
    }
    private void printDetailedHtmlError(LintError lintError) {
        .println("<h3 id=\"" + getHrefSafeName(lintError) + "\"> " + lintError.getViolatedRule().getName() +
                "</h3>");
        .println("<h4>" + lintError.getViolatedRule().getSummary() + "</h4>");
        .println("<b>Category</b> : " + lintError.getViolatedRule().getCategory() + " <br>");
        .println("<b>Severity</b> : " + lintError.getViolatedRule().getSeverity() + " <br>");
        if (!lintError.getViolatedRule().isEnabled()) {
            .println("<b> This rule is disabled by default </b> <br>");
        }
        PegDownProcessor pegDownProcessor = new PegDownProcessor();
        .println(pegDownProcessor.markdownToHtml(lintError.getViolatedRule().getDetailedDescription()));
    }
New to GrepCode? Check out our FAQ X