All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.cukedoctor.extension.CukedoctorFooterExtension Maven / Gradle / Ivy

There is a newer version: 3.9.0
Show newest version
package com.github.cukedoctor.extension;

import java.text.DateFormat;
import java.util.*;
import java.util.logging.Logger;

import org.asciidoctor.ast.Document;
import org.asciidoctor.extension.Postprocessor;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;

/**
 * Created by pestano on 20/07/15. adds search box to rendered html
 * documentation
 */
public class CukedoctorFooterExtension extends Postprocessor {

  private static final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT);

  public CukedoctorFooterExtension(Map config) {
    super(config);
  }

  @Override
  public String process(Document document, String output) {
    if (document.basebackend("html") && System.getProperty("cukedoctor.disable.footer") == null) {
      String stopWatch = System.getProperty("cukedoctor.stopwatch");
      Double generationTimeInSeconds = new Double(0);
      String documentationDate = dateFormat.format(new Date());
      String cukedoctorVersion = "";
      try {
        ResourceBundle bundle = new PropertyResourceBundle(CukedoctorFooterExtension.class.getResourceAsStream("/cukedoctor-extension.properties"));
        cukedoctorVersion = bundle.getString("cukedoctor.version");
      } catch (Exception e) {
        Logger.getLogger(getClass().getName()).warning("Could not find bundle cukedoctor-extension");
      }

      if (stopWatch != null && !"".equals(stopWatch)) {
        long begin = 0;
        try {
          begin = Long.parseLong(stopWatch);
          generationTimeInSeconds = (System.currentTimeMillis() - begin) / 1000.0;
        } catch (NumberFormatException e) {
        }
      }
      org.jsoup.nodes.Document doc = Jsoup.parse(output, "UTF-8");
      Element contentElement = doc.getElementById("footer");
      contentElement.attr("style","color:gray;font-size:11px");
      contentElement.text("Generated by ").append(" Cukedoctor " +
          cukedoctorVersion +
          "");
      contentElement.append(" - " + documentationDate);
      contentElement.append(" Execution time: " +
          + generationTimeInSeconds + " seconds");
      return doc.html();
    } else {
      return output;
    }
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy