PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/atlassian-docco/src/main/java/com/atlassian/docco/Header.java

https://bitbucket.org/Arnauld/atlassian-docco
Java | 67 lines | 51 code | 13 blank | 3 comment | 5 complexity | e1b26f1931fd7d9685de18b6fecbc443 MD5 | raw file
  1. package com.atlassian.docco;
  2. import java.util.Map;
  3. import org.apache.commons.lang.StringUtils;
  4. import org.pegdown.PegDownProcessor;
  5. /**
  6. * @since 1.0
  7. */
  8. public class Header
  9. {
  10. private String doc;
  11. private String markdown;
  12. private PegDownProcessor pegDown;
  13. public Header()
  14. {
  15. this(new PegDownProcessor());
  16. }
  17. public Header(PegDownProcessor pegDown)
  18. {
  19. this.doc = "";
  20. this.markdown = null;
  21. this.pegDown = pegDown;
  22. }
  23. public Header addDoc(String doc)
  24. {
  25. this.doc += doc + "\n";
  26. this.markdown = null;
  27. return this;
  28. }
  29. public boolean isEmpty()
  30. {
  31. return StringUtils.isBlank(doc);
  32. }
  33. public String getDoc()
  34. {
  35. if(null == markdown)
  36. {
  37. markdown = pegDown.markdownToHtml(doc);
  38. }
  39. return markdown;
  40. }
  41. public String getDocWithTokenReplacement(Map<String,String> replaceMap)
  42. {
  43. String replacedDoc = doc;
  44. for(Map.Entry<String,String> entry : replaceMap.entrySet())
  45. {
  46. replacedDoc = StringUtils.replace(doc,entry.getKey(),entry.getValue());
  47. }
  48. if(null == markdown)
  49. {
  50. markdown = pegDown.markdownToHtml(replacedDoc);
  51. }
  52. return markdown;
  53. }
  54. }