Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. package de.intersales.qbus2;
  2.  
  3. import static org.asciidoctor.Asciidoctor.Factory.create;
  4.  
  5. import io.vertx.core.Vertx;
  6. import io.vertx.ext.web.Router;
  7. import org.asciidoctor.Asciidoctor;
  8. import org.slf4j.LoggerFactory;
  9.  
  10. import java.io.*;
  11. import java.util.HashMap;
  12.  
  13. import org.slf4j.Logger;
  14.  
  15. public class DocumentRendererUtil {
  16.  
  17.  
  18. private Asciidoctor asciidoctor;
  19. Logger logger = LoggerFactory.getLogger(DocumentRendererUtil.class);
  20.  
  21.  
  22. public DocumentRendererUtil(Vertx vertx){
  23. vertx.executeBlocking(future ->{
  24. asciidoctor = create();
  25. future.complete(asciidoctor);
  26. }, res-> {
  27. logger.info("AsciidoctorJ created");
  28. });
  29. }
  30. public void extend(Router router){
  31.  
  32. router.get("/readme.html").handler( ctx -> {
  33. String html = asciidoctor.convert(
  34. getDocFileContent(),
  35. new HashMap<String, Object>());
  36. ctx.response().end(html);
  37. });
  38.  
  39. }
  40.  
  41. private String getDocFileContent() {
  42. try {
  43. InputStream is = getClass().getResourceAsStream("/doc/readme.adoc");
  44. java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
  45. return s.hasNext() ? s.next() : "";
  46. }
  47. catch (Exception e){
  48. logger.error("Could not load readme file", e);
  49. logger.error("Working Directory = " +
  50. System.getProperty("user.dir"));
  51. return "";
  52. }
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement