Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.devbliss.doctest.renderer.html;
  
  import java.util.List;
  import java.util.Map;
  
Html-implementation of the com.devbliss.doctest.renderer.ReportRenderer.

Each time that the function render(java.util.List,java.lang.String,java.lang.String) is called, a report file is created for the test case and an index file will be generated.

Author(s):
bmary
 
 public class HtmlRenderer extends AbstractHtmlReportRenderer implements ReportRenderer {
 
     private final HtmlIndexFileRenderer indexFileGenerator;
     private int sectionNumber = 0;
     private final Map<StringStringsections;
     private final FileHelper helper;
     private final JSONHelper jsonhelper;
 
     @Inject
     public HtmlRenderer(
             HtmlIndexFileRenderer indexFileGenerator,
             HtmlItems htmlItems,
             FileHelper abstractReportRenderer,
             JSONHelper jsonhelper) {
         super(htmlItems);
         this. = indexFileGenerator;
         this. = abstractReportRenderer;
         this. = jsonhelper;
          = new LinkedHashMap<StringString>();
     }
 
     public void render(List<DocItemlistTemplatesString nameString introduction)
             throws Exception {
         if (listTemplates != null && !listTemplates.isEmpty()) {
             String items = appendItemsToBuffer(listTemplates);
             ReportFileDocItem report = new ReportFileDocItem(nameintroductionitems);
             String nameWithExtension = .getCompleteFileName(name);
             .writeFile(nameWithExtension.getReportFileTemplate(report));
 
             .render(nullintroduction);
         }
     }
 
     private String appendItemsToBuffer(List<DocItemlistTemplates) {
         .clear();
         StringBuffer buffer = new StringBuffer();
         StringBuffer tempBuffer = new StringBuffer();
         for (DocItem item : listTemplates) {
             if (item instanceof SectionDocItem) {
                 tempBuffer.append(getSectionDocItem((SectionDocItemitem));
             } else if (item instanceof MultipleTextDocItem) {
                 tempBuffer.append(getMultipleTextDocItem((MultipleTextDocItemitem));
             } else {
                 tempBuffer.append(getTemplateForItem(item));
             }
         }
 
         appendSectionList(buffer);
         buffer.append(tempBuffer);
         return buffer.toString();
     }

    
Renders a MultipleTextDocItem consisting of multiple Json and Text Elements.

Parameters:
item
Returns:
 
         for (int i = 0; i < item.getAdditionalStrings().lengthi++) {
             if (.isJsonValid(item.getAdditionalStrings()[i])) {
                 item.getAdditionalStrings()[i] =
                         getTemplateForItem(new JsonDocItem(item.getAdditionalStrings()[i]));
             } else {
                 item.getAdditionalStrings()[i] =
                         getTemplateForItem(new HighlightedTextDocItem(
                                 item.getAdditionalStrings()[i]));
            }
        }
        item.setText(String.format(item.getText(), (Object[]) item.getAdditionalStrings()));
        return getTemplateForItem(item);
    }
    private String getTemplateForItem(DocItem item) {
        return .getTemplateForItem(item);
    }
    private String getSectionDocItem(SectionDocItem item) {
        String sectionId = getSectionId();
        String sectionName = item.getTitle();
        .put("#" + sectionIdsectionName);
        item.setHref(sectionId);
        return getTemplateForItem(item);
    }
    private void appendSectionList(StringBuffer buffer) {
        List<LinkDocItemfiles = new ArrayList<LinkDocItem>();
        for (Entry<StringStringsection : .entrySet()) {
            files.add(new LinkDocItem(section.getKey(), section.getValue()));
        }
        buffer.append(.getListFilesTemplate(new MenuDocItem(""files)));
    }
    private String getSectionId() {
        return "section" + ++;
    }
New to GrepCode? Check out our FAQ X