PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/atlassian-docco/src/main/java/com/atlassian/docco/builder/DoccoBuilder.java

https://bitbucket.org/Arnauld/atlassian-docco
Java | 158 lines | 129 code | 26 blank | 3 comment | 14 complexity | 03513e7521dbcfaa3e54bb5fac7c804e MD5 | raw file
  1. package com.atlassian.docco.builder;
  2. import java.io.File;
  3. import java.net.MalformedURLException;
  4. import java.net.URISyntaxException;
  5. import java.net.URL;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8. import com.atlassian.docco.Docco;
  9. import com.atlassian.docco.mapping.DoccoFileMappingManager;
  10. import org.pegdown.PegDownProcessor;
  11. import static com.google.common.base.Preconditions.checkState;
  12. /**
  13. * @since 1.0
  14. */
  15. public class DoccoBuilder
  16. {
  17. private URL hSoyTemplate;
  18. private URL vSoyTemplate;
  19. private Boolean stripJavadoc;
  20. private DoccoFileMappingManager fileMappings;
  21. private PegDownProcessor pegDown;
  22. private Boolean includeDefaultResources;
  23. private List<File> customResources;
  24. public DoccoBuilder()
  25. {
  26. }
  27. public DoccoBuilder horizontalTemplate(File soyTemplate)
  28. {
  29. try
  30. {
  31. this.hSoyTemplate = soyTemplate.toURI().toURL();
  32. }
  33. catch (MalformedURLException e)
  34. {
  35. e.printStackTrace();
  36. }
  37. return this;
  38. }
  39. public DoccoBuilder horizontalTemplate(URL soyTemplate)
  40. {
  41. this.hSoyTemplate = soyTemplate;
  42. return this;
  43. }
  44. public DoccoBuilder verticalTemplate(File soyTemplate)
  45. {
  46. try
  47. {
  48. this.vSoyTemplate = soyTemplate.toURI().toURL();
  49. }
  50. catch (MalformedURLException e)
  51. {
  52. e.printStackTrace();
  53. }
  54. return this;
  55. }
  56. public DoccoBuilder verticalTemplate(URL soyTemplate)
  57. {
  58. this.vSoyTemplate = soyTemplate;
  59. return this;
  60. }
  61. public DoccoBuilder stripJavadoc(Boolean stripJavadoc)
  62. {
  63. this.stripJavadoc = stripJavadoc;
  64. return this;
  65. }
  66. public DoccoBuilder fileMappings(DoccoFileMappingManager fileMappings)
  67. {
  68. this.fileMappings = fileMappings;
  69. return this;
  70. }
  71. public DoccoBuilder pegdownProcessor(PegDownProcessor pegDown)
  72. {
  73. this.pegDown = pegDown;
  74. return this;
  75. }
  76. public DoccoBuilder includeDefaultResources(Boolean defaultResources)
  77. {
  78. this.includeDefaultResources = defaultResources;
  79. return this;
  80. }
  81. public DoccoBuilder resources(List<File> customResources)
  82. {
  83. this.customResources = customResources;
  84. return this;
  85. }
  86. public Docco build()
  87. {
  88. if(null == hSoyTemplate)
  89. {
  90. try
  91. {
  92. hSoyTemplate = Docco.getDefaultHorizontalTemplate();
  93. }
  94. catch (URISyntaxException e)
  95. {
  96. throw new IllegalStateException("Unable to load default horizontal soy template!", e);
  97. }
  98. }
  99. if(null == vSoyTemplate)
  100. {
  101. try
  102. {
  103. vSoyTemplate = Docco.getDefaultVerticalTemplate();
  104. }
  105. catch (URISyntaxException e)
  106. {
  107. throw new IllegalStateException("Unable to load default vertical soy template!", e);
  108. }
  109. }
  110. if(null == stripJavadoc)
  111. {
  112. this.stripJavadoc = Boolean.TRUE;
  113. }
  114. if(null == fileMappings)
  115. {
  116. this.fileMappings = new DoccoFileMappingManager();
  117. }
  118. if(null == pegDown)
  119. {
  120. this.pegDown = new PegDownProcessor();
  121. }
  122. if(null == includeDefaultResources)
  123. {
  124. this.includeDefaultResources = Boolean.TRUE;
  125. }
  126. if(null == customResources)
  127. {
  128. customResources = new ArrayList<File>();
  129. }
  130. return new Docco(hSoyTemplate,vSoyTemplate,fileMappings,stripJavadoc.booleanValue(),includeDefaultResources.booleanValue(),customResources,pegDown);
  131. }
  132. }