Permalink
Browse files

changing project to sourceforge repository

  • Loading branch information...
0 parents commit eb6009931f897197c73956796431ed371031759f jonasabreu committed Mar 5, 2008
Showing with 11,409 additions and 0 deletions.
  1. +19 −0 .classpath
  2. +17 −0 .project
  3. +185 −0 build.xml
  4. +22 −0 docs/01-tubaina-overview.afc
  5. +36 −0 docs/02-how-and-why-we-did-it.afc
  6. +115 −0 docs/06-usage-and-dependencies.afc
  7. +127 −0 docs/07-afc-syntax.afc
  8. +59 −0 docs/08-examples.afc
  9. +144 −0 docs/09-testing-your-layout.afcx
  10. BIN lib/Tidy.jar
  11. BIN lib/commons-cli-1.1.jar
  12. BIN lib/commons-io-1.3.1.jar
  13. BIN lib/freemarker.jar
  14. BIN lib/jai_codec.jar
  15. BIN lib/jai_core.jar
  16. BIN lib/jai_imageio.jar
  17. BIN lib/java2html.jar
  18. BIN lib/log4j-1.2.12.jar
  19. +202 −0 src/etc/LICENSE.txt
  20. +6 −0 src/etc/latex.sh
  21. +17 −0 src/etc/tubaina
  22. +23 −0 src/java/br/com/caelum/tubaina/Book.java
  23. +47 −0 src/java/br/com/caelum/tubaina/Chapter.java
  24. +7 −0 src/java/br/com/caelum/tubaina/Chunk.java
  25. +5 −0 src/java/br/com/caelum/tubaina/CompositeChunk.java
  26. +30 −0 src/java/br/com/caelum/tubaina/Section.java
  27. +219 −0 src/java/br/com/caelum/tubaina/Tubaina.java
  28. +23 −0 src/java/br/com/caelum/tubaina/TubainaException.java
  29. +80 −0 src/java/br/com/caelum/tubaina/builder/BookBuilder.java
  30. +58 −0 src/java/br/com/caelum/tubaina/builder/ChapterBuilder.java
  31. +22 −0 src/java/br/com/caelum/tubaina/builder/ChunkSplitter.java
  32. +37 −0 src/java/br/com/caelum/tubaina/builder/ChunksMaker.java
  33. +161 −0 src/java/br/com/caelum/tubaina/builder/ChunksMakerBuilder.java
  34. +25 −0 src/java/br/com/caelum/tubaina/builder/SectionBuilder.java
  35. +66 −0 src/java/br/com/caelum/tubaina/builder/replacer/AbstractReplacer.java
  36. +27 −0 src/java/br/com/caelum/tubaina/builder/replacer/AnswerReplacer.java
  37. +30 −0 src/java/br/com/caelum/tubaina/builder/replacer/BoxReplacer.java
  38. +25 −0 src/java/br/com/caelum/tubaina/builder/replacer/CodeReplacer.java
  39. +43 −0 src/java/br/com/caelum/tubaina/builder/replacer/ExerciseReplacer.java
  40. +45 −0 src/java/br/com/caelum/tubaina/builder/replacer/ImageReplacer.java
  41. +30 −0 src/java/br/com/caelum/tubaina/builder/replacer/IndexReplacer.java
  42. +89 −0 src/java/br/com/caelum/tubaina/builder/replacer/ItemReplacer.java
  43. +43 −0 src/java/br/com/caelum/tubaina/builder/replacer/JavaReplacer.java
  44. +25 −0 src/java/br/com/caelum/tubaina/builder/replacer/ListReplacer.java
  45. +30 −0 src/java/br/com/caelum/tubaina/builder/replacer/NoteReplacer.java
  46. +41 −0 src/java/br/com/caelum/tubaina/builder/replacer/ParagraphReplacer.java
  47. +31 −0 src/java/br/com/caelum/tubaina/builder/replacer/PatternReplacer.java
  48. +26 −0 src/java/br/com/caelum/tubaina/builder/replacer/QuestionReplacer.java
  49. +13 −0 src/java/br/com/caelum/tubaina/builder/replacer/Replacer.java
  50. +26 −0 src/java/br/com/caelum/tubaina/builder/replacer/TodoReplacer.java
  51. +25 −0 src/java/br/com/caelum/tubaina/builder/replacer/XmlReplacer.java
  52. +43 −0 src/java/br/com/caelum/tubaina/chunk/AnswerChunk.java
  53. +29 −0 src/java/br/com/caelum/tubaina/chunk/BoxChunk.java
  54. +20 −0 src/java/br/com/caelum/tubaina/chunk/CodeChunk.java
  55. +31 −0 src/java/br/com/caelum/tubaina/chunk/ExerciseChunk.java
  56. +23 −0 src/java/br/com/caelum/tubaina/chunk/ImageChunk.java
  57. +17 −0 src/java/br/com/caelum/tubaina/chunk/IndexChunk.java
  58. +25 −0 src/java/br/com/caelum/tubaina/chunk/IntroductionChunk.java
  59. +24 −0 src/java/br/com/caelum/tubaina/chunk/ItemChunk.java
  60. +21 −0 src/java/br/com/caelum/tubaina/chunk/JavaChunk.java
  61. +28 −0 src/java/br/com/caelum/tubaina/chunk/ListChunk.java
  62. +18 −0 src/java/br/com/caelum/tubaina/chunk/MockedChunk.java
  63. +32 −0 src/java/br/com/caelum/tubaina/chunk/NoteChunk.java
  64. +18 −0 src/java/br/com/caelum/tubaina/chunk/ParagraphChunk.java
  65. +25 −0 src/java/br/com/caelum/tubaina/chunk/QuestionChunk.java
  66. +18 −0 src/java/br/com/caelum/tubaina/chunk/TodoChunk.java
  67. +18 −0 src/java/br/com/caelum/tubaina/chunk/XmlChunk.java
  68. +60 −0 src/java/br/com/caelum/tubaina/parser/CodeHighlightTag.java
  69. +13 −0 src/java/br/com/caelum/tubaina/parser/Generator.java
  70. +6 −0 src/java/br/com/caelum/tubaina/parser/Indentator.java
  71. +79 −0 src/java/br/com/caelum/tubaina/parser/MockedParser.java
  72. +19 −0 src/java/br/com/caelum/tubaina/parser/Parser.java
  73. +27 −0 src/java/br/com/caelum/tubaina/parser/RegexConfigurator.java
  74. +23 −0 src/java/br/com/caelum/tubaina/parser/RegexTag.java
  75. +18 −0 src/java/br/com/caelum/tubaina/parser/SimpleIndentator.java
  76. +5 −0 src/java/br/com/caelum/tubaina/parser/Tag.java
  77. +14 −0 src/java/br/com/caelum/tubaina/parser/html/AnswerTag.java
  78. +26 −0 src/java/br/com/caelum/tubaina/parser/html/BookToTOC.java
  79. +13 −0 src/java/br/com/caelum/tubaina/parser/html/BoxTag.java
  80. +41 −0 src/java/br/com/caelum/tubaina/parser/html/ChapterToString.java
  81. +75 −0 src/java/br/com/caelum/tubaina/parser/html/CodeTag.java
  82. +11 −0 src/java/br/com/caelum/tubaina/parser/html/ExerciseTag.java
  83. +180 −0 src/java/br/com/caelum/tubaina/parser/html/HtmlGenerator.java
  84. +102 −0 src/java/br/com/caelum/tubaina/parser/html/HtmlParser.java
  85. +49 −0 src/java/br/com/caelum/tubaina/parser/html/ImageTag.java
  86. +11 −0 src/java/br/com/caelum/tubaina/parser/html/IndexTag.java
  87. +30 −0 src/java/br/com/caelum/tubaina/parser/html/IndexToString.java
  88. +10 −0 src/java/br/com/caelum/tubaina/parser/html/ItemTag.java
  89. +51 −0 src/java/br/com/caelum/tubaina/parser/html/JavaTag.java
  90. +18 −0 src/java/br/com/caelum/tubaina/parser/html/ListTag.java
  91. +11 −0 src/java/br/com/caelum/tubaina/parser/html/NoteTag.java
  92. +11 −0 src/java/br/com/caelum/tubaina/parser/html/ParagraphTag.java
  93. +11 −0 src/java/br/com/caelum/tubaina/parser/html/QuestionTag.java
  94. +43 −0 src/java/br/com/caelum/tubaina/parser/html/SectionToString.java
  95. +24 −0 src/java/br/com/caelum/tubaina/parser/html/TodoTag.java
  96. +121 −0 src/java/br/com/caelum/tubaina/parser/html/XmlTag.java
  97. +12 −0 src/java/br/com/caelum/tubaina/parser/latex/AnswerTag.java
  98. +31 −0 src/java/br/com/caelum/tubaina/parser/latex/BookToLatex.java
  99. +10 −0 src/java/br/com/caelum/tubaina/parser/latex/BoxTag.java
  100. +104 −0 src/java/br/com/caelum/tubaina/parser/latex/CodeTag.java
  101. +44 −0 src/java/br/com/caelum/tubaina/parser/latex/Escape.java
  102. +15 −0 src/java/br/com/caelum/tubaina/parser/latex/EscapeTag.java
  103. +12 −0 src/java/br/com/caelum/tubaina/parser/latex/ExerciseTag.java
  104. +66 −0 src/java/br/com/caelum/tubaina/parser/latex/ImageTag.java
  105. +11 −0 src/java/br/com/caelum/tubaina/parser/latex/IndexTag.java
  106. +11 −0 src/java/br/com/caelum/tubaina/parser/latex/ItemTag.java
  107. +48 −0 src/java/br/com/caelum/tubaina/parser/latex/JavaTag.java
  108. +111 −0 src/java/br/com/caelum/tubaina/parser/latex/LatexGenerator.java
  109. +105 −0 src/java/br/com/caelum/tubaina/parser/latex/LatexParser.java
  110. +23 −0 src/java/br/com/caelum/tubaina/parser/latex/ListTag.java
  111. +12 −0 src/java/br/com/caelum/tubaina/parser/latex/NoteTag.java
  112. +11 −0 src/java/br/com/caelum/tubaina/parser/latex/ParagraphTag.java
  113. +11 −0 src/java/br/com/caelum/tubaina/parser/latex/QuestionTag.java
  114. +24 −0 src/java/br/com/caelum/tubaina/parser/latex/TodoTag.java
  115. +131 −0 src/java/br/com/caelum/tubaina/parser/latex/XmlTag.java
  116. +18 −0 src/java/br/com/caelum/tubaina/resources/AnswerResource.java
  117. +16 −0 src/java/br/com/caelum/tubaina/resources/ExerciseResource.java
  118. +90 −0 src/java/br/com/caelum/tubaina/resources/HtmlResourceManipulator.java
  119. +19 −0 src/java/br/com/caelum/tubaina/resources/ImageResource.java
  120. +19 −0 src/java/br/com/caelum/tubaina/resources/IndexResource.java
  121. +105 −0 src/java/br/com/caelum/tubaina/resources/LatexResourceManipulator.java
  122. +7 −0 src/java/br/com/caelum/tubaina/resources/Resource.java
  123. +48 −0 src/java/br/com/caelum/tubaina/resources/ResourceLocator.java
  124. +13 −0 src/java/br/com/caelum/tubaina/resources/ResourceManipulator.java
  125. +53 −0 src/java/br/com/caelum/tubaina/template/FreemarkerProcessor.java
  126. +40 −0 src/java/br/com/caelum/tubaina/util/ColorXml.java
  127. +91 −0 src/java/br/com/caelum/tubaina/util/FileUtilities.java
  128. +220 −0 src/java/br/com/caelum/tubaina/util/HtmlSanitizer.java
  129. +271 −0 src/java/br/com/caelum/tubaina/util/Utilities.java
  130. +14 −0 src/java/br/com/caelum/tubaina/util/VersionGenerator.java
  131. +64 −0 src/java/br/com/caelum/tubaina/util/XHTMLValidator.java
  132. +28 −0 src/resources/html.properties
  133. +6 −0 src/resources/latex.bat
  134. +34 −0 src/resources/latex.properties
  135. +21 −0 src/resources/log4j.xml
  136. +37 −0 src/resources/regex.properties
  137. +37 −0 src/templates/html/chapter.ftl
  138. +17 −0 src/templates/html/footer.ftl
  139. +29 −0 src/templates/html/header.ftl
  140. +21 −0 src/templates/html/includes/css/java.css
  141. +324 −0 src/templates/html/includes/css/style.css
  142. +115 −0 src/templates/html/includes/css/xml2html.css
  143. BIN src/templates/html/includes/images/next-arrow.png
  144. BIN src/templates/html/includes/images/previous-arrow.png
  145. BIN src/templates/html/includes/images/tubaina-icon.png
  146. BIN src/templates/html/includes/images/up-arrow.png
  147. +10 −0 src/templates/html/includes/javascript/answer.js
  148. +14 −0 src/templates/html/index.ftl
  149. +8 −0 src/templates/html/navigation.ftl
  150. +24 −0 src/templates/html/section.ftl
  151. +42 −0 src/templates/html/toc.ftl
  152. +3 −0 src/templates/latex/answerTemplate.ftl
  153. +86 −0 src/templates/latex/begin.ftl
  154. +16 −0 src/templates/latex/book.ftl
  155. +26 −0 src/templates/latex/cover.ftl
  156. 0 src/templates/latex/definitions.ftl
  157. +11 −0 src/templates/latex/end.ftl
  158. +1,249 −0 src/templates/latex/joseplain.bst
  159. BIN src/templates/latex/tubaina.png
  160. +445 −0 src/templates/latex/tubaina.sty
  161. 0 src/test/baseJpgDone.jpg
  162. BIN src/test/baseJpgImage.jpg
  163. 0 src/test/basePngDone.png
  164. BIN src/test/basePngImage.png
  165. BIN src/test/basePngResized.png
  166. +319 −0 src/test/br/com/caelum/tubaina/builder/BookBuilderTest.java
  167. +197 −0 src/test/br/com/caelum/tubaina/builder/ChunksMakerBuilderTest.java
  168. +63 −0 src/test/br/com/caelum/tubaina/builder/replacer/AnswerReplacerTest.java
  169. +75 −0 src/test/br/com/caelum/tubaina/builder/replacer/BoxReplacerTest.java
  170. +60 −0 src/test/br/com/caelum/tubaina/builder/replacer/CodeReplacerTest.java
  171. +74 −0 src/test/br/com/caelum/tubaina/builder/replacer/ExerciseReplacerTest.java
  172. +52 −0 src/test/br/com/caelum/tubaina/builder/replacer/ImageReplacerTest.java
  173. +69 −0 src/test/br/com/caelum/tubaina/builder/replacer/ItemReplacerTest.java
  174. +60 −0 src/test/br/com/caelum/tubaina/builder/replacer/JavaReplacerTest.java
  175. +136 −0 src/test/br/com/caelum/tubaina/builder/replacer/ListReplacerTest.java
  176. +62 −0 src/test/br/com/caelum/tubaina/builder/replacer/NoteReplacerTest.java
  177. +62 −0 src/test/br/com/caelum/tubaina/builder/replacer/QuestionReplacerTest.java
  178. +53 −0 src/test/br/com/caelum/tubaina/builder/replacer/TodoReplacerTest.java
  179. +61 −0 src/test/br/com/caelum/tubaina/builder/replacer/XmlReplacerTest.java
  180. +17 −0 src/test/br/com/caelum/tubaina/parser/RegexConfiguratorTest.java
  181. +50 −0 src/test/br/com/caelum/tubaina/parser/SimpleIndentatorTest.java
  182. +20 −0 src/test/br/com/caelum/tubaina/parser/html/AnswerTagTest.java
  183. +87 −0 src/test/br/com/caelum/tubaina/parser/html/BookToTOCTest.java
  184. +24 −0 src/test/br/com/caelum/tubaina/parser/html/BoxTagTest.java
  185. +78 −0 src/test/br/com/caelum/tubaina/parser/html/ChapterToStringTest.java
  186. +39 −0 src/test/br/com/caelum/tubaina/parser/html/CodeHighlightTagTest.java
  187. +24 −0 src/test/br/com/caelum/tubaina/parser/html/CodeTagTest.java
  188. +18 −0 src/test/br/com/caelum/tubaina/parser/html/ExerciseTagTest.java
  189. +205 −0 src/test/br/com/caelum/tubaina/parser/html/HtmlGeneratorTest.java
  190. +243 −0 src/test/br/com/caelum/tubaina/parser/html/HtmlParserTest.java
  191. +65 −0 src/test/br/com/caelum/tubaina/parser/html/ImageTagTest.java
  192. +27 −0 src/test/br/com/caelum/tubaina/parser/html/ItemTagTest.java
  193. +50 −0 src/test/br/com/caelum/tubaina/parser/html/JavaTagTest.java
  194. +38 −0 src/test/br/com/caelum/tubaina/parser/html/ListTagTest.java
  195. +16 −0 src/test/br/com/caelum/tubaina/parser/html/NoteTagTest.java
  196. +18 −0 src/test/br/com/caelum/tubaina/parser/html/QuestionTagTest.java
  197. +61 −0 src/test/br/com/caelum/tubaina/parser/html/SectionToStringTest.java
  198. +78 −0 src/test/br/com/caelum/tubaina/parser/html/XmlTagTest.java
  199. +21 −0 src/test/br/com/caelum/tubaina/parser/latex/BoxTagTest.java
  200. +48 −0 src/test/br/com/caelum/tubaina/parser/latex/CodeTagTest.java
  201. +14 −0 src/test/br/com/caelum/tubaina/parser/latex/ExerciseTagTest.java
  202. +82 −0 src/test/br/com/caelum/tubaina/parser/latex/ImageTagTest.java
  203. +24 −0 src/test/br/com/caelum/tubaina/parser/latex/ItemTagTest.java
  204. +18 −0 src/test/br/com/caelum/tubaina/parser/latex/JavaTagTest.java
  205. +225 −0 src/test/br/com/caelum/tubaina/parser/latex/LatexParserTest.java
  206. +37 −0 src/test/br/com/caelum/tubaina/parser/latex/ListTagTest.java
  207. +21 −0 src/test/br/com/caelum/tubaina/parser/latex/NoteTagTest.java
  208. +79 −0 src/test/br/com/caelum/tubaina/parser/latex/XmlTagTest.java
  209. +16 −0 src/test/br/com/caelum/tubaina/util/HtmlSanitizerTest.java
  210. +47 −0 src/test/br/com/caelum/tubaina/util/UtilitiesTest.java
19 .classpath
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/test"/>
+ <classpathentry kind="src" path="src/resources"/>
+ <classpathentry kind="src" path="src/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+ <classpathentry kind="lib" path="lib/freemarker.jar"/>
+ <classpathentry kind="lib" path="lib/java2html.jar"/>
+ <classpathentry kind="lib" path="lib/log4j-1.2.12.jar"/>
+ <classpathentry kind="lib" path="lib/jai_codec.jar"/>
+ <classpathentry kind="lib" path="lib/jai_core.jar"/>
+ <classpathentry kind="lib" path="lib/jai_imageio.jar"/>
+ <classpathentry kind="lib" path="lib/Tidy.jar"/>
+ <classpathentry kind="lib" path="lib/commons-cli-1.1.jar"/>
+ <classpathentry kind="lib" path="lib/commons-io-1.3.1.jar"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/templatesTubaina"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
17 .project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>tubaina</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
185 build.xml
@@ -0,0 +1,185 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="Tubaina" default="dist" basedir=".">
+
+ <property name="root" location="./">
+ </property>
+
+ <property name="lib" location="${root}/lib">
+ </property>
+
+ <property name="src" location="${root}/src">
+ </property>
+
+ <property name="cfg" location="${src}/resources">
+ </property>
+
+ <property name="version" value="1.0">
+ </property>
+
+ <property name="dist" location="${root}/tmp/dist/tubaina-${version}">
+ </property>
+
+ <property name="source" location="${root}/tmp/source/tubaina-${version}-src">
+ </property>
+
+ <property name="tmp" location="${dist}/tmp">
+ </property>
+
+ <target name="init">
+ <!--Build path hierarchy -->
+ <mkdir dir="${dist}" />
+ <mkdir dir="${dist}/lib" />
+ <mkdir dir="${dist}/config" />
+ <mkdir dir="${dist}/bin" />
+ <mkdir dir="${dist}/docs" />
+ <mkdir dir="${dist}/src/templates" />
+ <mkdir dir="${tmp}" />
+ <mkdir dir="${source}" />
+ </target>
+
+ <target name="compile" depends="init" description="Compile the source code">
+ <javac srcdir="${src}/java" destdir="${tmp}">
+ <classpath>
+ <fileset dir="${lib}">
+ <include name="**/*.jar" />
+ </fileset>
+ </classpath>
+ </javac>
+ </target>
+
+ <target name="copyTemplate" description="Copy default templates">
+ <copy todir="${dist}/src/templates">
+ <fileset dir="${src}/templates">
+ <include name="**/*" />
+ <include name="**/*.*" />
+ </fileset>
+ </copy>
+ </target>
+
+ <target name="dist" depends="compile, copyTemplate" description="Generate the distribution">
+
+ <copy todir="${dist}/lib">
+ <fileset dir="${lib}">
+ <include name="*.jar" />
+ </fileset>
+ </copy>
+
+ <!-- TODO property -->
+ <copy todir="${dist}/bin" file="${src}/etc/latex.sh">
+ </copy>
+
+ <copy todir="${dist}" file="${src}/etc/LICENSE.txt">
+ </copy>
+
+ <jar destfile="${dist}/lib/tubaina.jar">
+ <fileset dir="${tmp}">
+ <include name="**/*" />
+ </fileset>
+ <fileset dir="${cfg}">
+ <include name="**/*" />
+ </fileset>
+ <fileset dir="${dist}/src/templates">
+ <include name="**/*" />
+ </fileset>
+ <manifest>
+ <attribute name="Main-Class" value="br.com.caelum.tubaina.Tubaina" />
+ <attribute name="Manifest-Version" value="1.0" />
+ </manifest>
+ </jar>
+
+ <!-- tmp is not useful anymore -->
+ <delete dir="${tmp}">
+ </delete>
+
+ <echo message="Generating docs">
+ </echo>
+
+ <!-- Configuring classpath -->
+ <fileset id="runClasspath" dir="${dist}">
+ <include name="lib/*.jar" />
+ </fileset>
+
+ <property name="tubaina.classpath" refid="runClasspath">
+ </property>
+
+ <path id="classpath">
+ <fileset dir="${dist}/lib">
+ <include name="**/*.jar" />
+ </fileset>
+ </path>
+
+ <java fork="true" dir="${dist}" classname="br.com.caelum.tubaina.Tubaina" classpathref="classpath">
+ <arg id="type" value="-html" />
+ <arg id="n" value="-n" />
+ <arg id="name" value="docs" />
+ <arg id="i" value="-i" />
+ <arg id="inputDir" value="${root}/docs" />
+ <arg id="o" value="-o" />
+ <arg id="outputDir" value="${dist}/docs" />
+
+ </java>
+
+ <!--removing todo.log -->
+ <delete file="${dist}/todo.log">
+ </delete>
+
+ <!-- Generating *nix tubaina launcher script-->
+
+ <copy file="${src}/etc/tubaina" todir="${dist}/bin">
+ </copy>
+
+ <replaceregexp flags="g" file="${dist}/bin/tubaina" match="@CLASSPATH" replace="${tubaina.classpath}">
+ </replaceregexp>
+
+ <replaceregexp flags="g" file="${dist}/bin/tubaina" match=";lib/" replace=":$TUB_REL_PATH/lib/">
+ </replaceregexp>
+
+ <replaceregexp flags="g" file="${dist}/bin/tubaina" match="-classpath " replace="-classpath $TUB_REL_PATH/">
+ </replaceregexp>
+
+ <replaceregexp flags="g" file="${dist}/bin/tubaina" match="@TUB_HOME_MOD" replace="..">
+ </replaceregexp>
+
+ <chmod perm="755" file="${dist}/bin/latex.sh">
+ </chmod>
+ <chmod perm="755" file="${dist}/bin/tubaina">
+ </chmod>
+
+ <!-- Zipping all files -->
+ <zip destfile="${root}/tmp/tubaina-${version}.zip" basedir="${dist}/..">
+ </zip>
+
+ <!-- Tar all files -->
+ <tar destfile="${root}/tmp/tubaina-${version}.tar.gz" basedir="${dist}/.." compression="gzip">
+ </tar>
+
+ <!-- making source folder -->
+ <copy todir="${source}">
+ <fileset dir="${root}">
+ <include name="**/*" />
+ <exclude name="bin/" />
+ <exclude name="src/afc/" />
+ <exclude name="src/templatesCaelum/" />
+ <exclude name="tmp/" />
+ <exclude name="todo.log" />
+ </fileset>
+ </copy>
+
+ <!-- Zipping source -->
+ <zip destfile="${root}/tmp/tubaina-${version}-src.zip" basedir="${source}/..">
+ </zip>
+
+ <!-- Tar source -->
+ <tar destfile="${root}/tmp/tubaina-${version}-src.tar.gz" basedir="${source}/.." compression="gzip">
+ </tar>
+
+ <!-- Removing all temporary files -->
+ <delete dir="${dist}/..">
+ </delete>
+ <delete dir="${source}/..">
+ </delete>
+
+
+ </target>
+
+</project>
22 docs/01-tubaina-overview.afc
@@ -0,0 +1,22 @@
+[chapter Tubaina Overview]
+
+[quote "Constraints are good"--37signals.com]
+
+Tubaina was built to generate textbooks at Caelum ( http://www.caelum.com.br ).
+
+It basically takes text written in **afc syntax** (take a look at the syntax chapter) and outputs LaTeX and/or
+XHTML.
+
+As you will notice, Tubaina is not as powerfull as LaTeX or many other text generators but that's a good
+point. When you have thousand options to choose from, you will probably spend too much time choosing which
+color your text should be or any other format you believe is important (and will put aside ::content
+generation::). That's not quite good and will not improve productivity.
+
+Tubaina let all these decisions to be made inside the templates it use. This way, if you want to change how
+all your text looks, you just change which template you use to generate.
+
+You see? Constraints **are** good!
+
+We hope Tubaina can help you when creating content or formatting old one.
+
+Tubaina Development Team
36 docs/02-how-and-why-we-did-it.afc
@@ -0,0 +1,36 @@
+[chapter How and why we did it]
+
+[quote "Keep it simple"-- ]
+
+The whole idea for the project came from a simple problem: How to have control over editions of textbooks.
+At Caelum we used to have huge OpenOffice files and versioning system, like cvs or svn. The big problem
+is that **odt** is a binary format, so any simultaneous editing would create a conflict (a really hard one
+to solve because you don't know where the file was changed).
+
+[title Why not simply use LaTeX?]
+
+Even though LaTeX is incredible powerfull, we also wanted to have Html output. Even using some third party
+LaTeX to Html conversor the result wouldn't be as we wanted. Usually these tools doesn't allow us to customize
+the output.
+Besides, LaTeX can drive you nuts with its heavy syntax and crazy style sheets.
+
+We wanted a really simple syntax and LaTeX was far more complex than necessary. It would slow down production
+and our textbooks wouldn't be really standardized. We needed contraints and LaTex would not provide it to us.
+
+These and other causes drove us into this project.
+
+[title Development process]
+
+Tubaina was developed using an agile methodology called Extreme Programming
+( http://en.wikipedia.org/wiki/Extreme_Programming ).
+We were couched by Mariana Vivian Bravo, grad student on agile methodologies at "Universidade de São Paulo".
+Since [label Extreme Programmig]XP[/label] is a incremental methodologie, we had Tubaina running and generating
+some Html after the first week. It was really interesting to have something working so soon because this was
+Caelum's Trainees first project.
+
+Java was choosen because it's portable, and is Caelum's courses focus. Also, Caelum has developed frameworks
+( like VRaptor - http://vraptor.org ) using it.
+
+Developing Tubaina was really fun. Most programmers of the team had almost no previous contact with XP, Design
+Patterns, CSS, XHTML and text parsing. So, learning was in focus every single day.
+
115 docs/06-usage-and-dependencies.afc
@@ -0,0 +1,115 @@
+[chapter Tubaina]
+
+Tubaina is a textbook generator that uses a simple syntax and outputs either html or latex documents.
+
+It has been developed in Brazil at Caelum (http://www.caelum.com.br) and it is licensed under GPL --
+therefore it is ::opensource:: and can be used as long as its rights are kept.
+
+[section Dependencies]
+
+Tubaina should work properly on any computer running Java5, but you will need a Latex compiller so
+as to deliver a *.pdf output.
+
+[list]
+* **On Linux:** use your favorite package manager and import the packages ::tetex-extra:: and
+::latex-ucs:: and theirs respective dependencies.
+
+* **On Ubuntu (Debian):** sudo apt-get install tetex-extra latex-ucs [auctex]
+
+* **On Windows:** We recommend using the TexLive project to compile latex in Windows. Run TexLive and,
+when it asks you which packages it should install, find on the list the following packages:
+
+::graphics::, ::psfrags::, ::ifthen::, ::makeidx::, ::fancyhdr::, ::pstcol::, ::colortbl::,
+::rotating::, ::multirow::
+
+* **On Mac:** to be tested! But you may follow the **On Linux** steps if you have a package manager
+installed -- we recommend Fink and DarwinPorts.
+[/list]
+
+[section Enviromental Variables And Building Tubaina By Yourself]
+
+On Unix like systems, you can use the ::tubaina:: script to launch it. But, to do so, you need to define some
+variables using %%export%%:
+
+[list]
+* JAVA_HOME: Tubaina needs to know where is located the Java Virtual Machine in order to run. This variable
+should be set to your java directory. ($JAVA_HOME/bin/java must be your JVM).
+* TUBAINA_HOME: This should point to Tubaina's base dir (the one you get right after unpacking our zip or tgz).
+[/list]
+
+To build Tubaina from our source packages, you need to have **jakarta-oro** inside your %%ant%% build path.
+Then just run %%ant build.xml%% on the root folder.
+
+[section Running Tubaina]
+
+Run Tubaina in command line using:
+
+%% > tubaina [-latex] [-html] -i inputDirectory -o outputDirectory -n bookName [--help] [-t templateDirectory]%%
+
+If you specify neither -latex nor -html, no output will be generated!
+
+Outputs for latex and html will be generated on outputDirectory/latex and outputDirectory/html,
+respectively.
+
+For further options, check the Tubaina help.
+
+[box Why can't I see the *.dvi from the Latex?]
+For allowing users to use many image formats - not only *.eps - we use a Latex package called
+::graphicx::. This package only works on *.pdf outputs and, therefore, will prevent Latex from
+compilling *.tex to *.dvi.
+
+This means you can never read your Tubaina generated latex in dvi format. Don't get too upset,
+though. Your *.pdf output will do fine!
+[/box]
+
+[section Making a new template]
+
+Making your own template on Tubaina is easy, there are just some files which presence is mandatory.
+Let's start talking about the HTML template. Make an html and a latex folders. This folder should
+contain some documents:
+
+[list]
+ * **in yourTemplate/html:**
+
+ [list]
+ * **logo.png** - the logo, if you want Tubaina to make watermarks on your textbook images.
+ This filename is mandatory, so is its location (inside html/ folder).
+ * **toc.ftl** - the Table of Contents structure
+ * **chapter.ftl** - the page of each Chapter introduction text
+ * **section.ftl** - the page of each Sections content text
+ * **index.ftl** - the index structure
+ [/list]
+
+ Those, except for the logo, are written in Freemarker syntax and can change the structure of your page -
+ not the style. You might want to take ours as base for making your own Freemarker files. Have in mind,
+ you should not change the variable names (${variable}), for they are connected to the Tubaina core.
+
+ Then, there are some other files, mainly related to the style of the Tubaina textbook. These must be
+ added to the folder %%html/includes%%, which will be automaticaly copied by Tubaina.
+
+ [list]
+ * **Java and XML stylesheets** - these are responsible for colouring Java and XML codes
+ indicated by the tags %%java%% and %%xml%% on the text.
+
+ * **style.css stylesheet** - this .css determines the look of your book.
+
+ * **Navigation and menu images** - the images your project will use for header, footer, etc
+ and NOT in textbook content should be here.
+
+ * **Scripts** - if your online textbook will use javascript or other scripts for effects,
+ this is where you should put the script. Tubaina's template use a single script for answer
+ dropdown effect.
+ [/list]
+
+ * **in yourTemplate/latex:**
+
+ [list]
+ * **book.ftl** - general book structure. This *.ftl puts all the others together.
+ [/list]
+
+ Furthermore, you should use a stylesheet. I strongly recommend you to do your own stylesheet,
+ but you can always get directions from ours (tubaina.sty) - the matter is that it gets big and
+ confuse and there is a better chance you'll understand it afterwards if it is your own work.
+
+ Tubaina does not support watermarks in latex (pdf).
+[/list]
127 docs/07-afc-syntax.afc
@@ -0,0 +1,127 @@
+[chapter *.afc format syntax]
+
+This a short introduction to the *.afc format syntax.
+
+[section Chapters, sections and other chunks]
+
+**Chapter:** This tag creates a chapter in your textbook.
+
+[code][chapter chapter name][/code]
+
+**Section:** The section tag builds a section in a chapter. It also adds a reference on the Table of
+Contents.
+
+[code][section section name][/code]
+
+**Unimportant section:** Title works quite alike sections, but it neither add a reference on the Table of
+Contents nor make a new webpage in HTML mode -- it belongs to the previous section .
+
+[code][title unimportant section][/code]
+
+**Quotations:** This tag adjust the quotation layout, ::italizing:: the quote and placing its author
+on the next line. Both quotation and author are aligned to the right.
+
+[code][quote <quotation> --<author>][/code]
+
+**Label:** Adds a footnote, on Latex, and a alt box, on HTML, on the text inside the tag. Be aware to the
+fact that no other tags are allowed on the label text.
+
+[code][label the label] what is beeing labeled [/label][/code]
+
+**Box:** The box tag places its content in a new environment slightly indented and appart from the
+rest of the text.
+
+[code][box <box title>] <content> [/box][/code]
+
+**Exercises:** The exercise tag creates an new environment in which you must place questions. Each
+question might have an answer and it can be added by using the tag answer.
+
+[code][exercise]
+ [question] The question [/question]
+[/exercise][/code]
+
+OR
+
+[code][exercise]
+ [question] The question
+ [answer] The answer [/answer]
+ [/question]
+[/exercise][/code]
+
+**Instructors' Note:** in case you need your teacher's textbook to have extra information, you might
+use the note tag. It adds Instructor Notes to the textbook when compiling with instructors option on.
+
+[code][note]Note to the instructor[/note][/code]
+
+[section Basic text definition]
+
+**Bold:** [code]**bold text**[/code]
+
+**Italic:** [code]::italic text::[/code]
+
+**Underlined:** [code]__underlined text__[/code]
+
+**Inline code:** [code] %% code text in common text paragraph %% [/code]
+
+[section Code chunk tags]
+
+**Java:** [code][java]Java code[/java][/code]
+
+**Java from file:** [code][java src]path/File.java[/java][/code]
+
+**XML:** [code][xml]XML code[/xml][/code]
+
+**.properties:** [code][code properties]Properties code[/code][/code]
+
+**Outras linguagens:** [code][code]Any other code[/code][/code]
+
+In order to emphasize code lines, use the option: %%h=line1,line2,...%% like this:
+[code][java h=1,2,3]....[/java][/code]
+
+[section Special tags]
+
+**Link:** Tubaina automatically adds links whenever you use "http://"
+
+**Anchor for indexing:** This tag creates an anchor to be added in the index.
+
+[code][index anchor name][/code]
+
+**To do:** The tag ::to do:: allows you making reminders of those edits you must do on your textbook,
+but have not enough time or material to work on. It builds a log of all the open tasks in your book.
+
+[code][todo task reminder][/code]
+
+[section Lists]
+
+**Circular bulleted list:**
+
+[code][list]
+ * item
+ * item
+[/list][/code]
+
+**Numbered list:**
+
+[code][list number]
+ * item
+[/list][/code]
+
+**Roman counter list:**
+
+[code][list roman]
+ * item
+[/list][/code]
+
+**Letter counter list:**
+
+[code][list letter]
+ * item
+[/list][/code]
+
+[section Images]
+
+**Images:** in order to add images to your textbook, you must use the tag ::img::. This tag has two
+specialties: you may choose the percentage of the width of the page your image must fill by using the
+tag **w** and you can add a comment about the image on a floating tab.
+
+[code][img path/imagem.png w=scale% "tab comment"][/code]
59 docs/08-examples.afc
@@ -0,0 +1,59 @@
+[chapter A few short examples]
+
+Here, you'll have some simple examples of *.afc text that intend to show the easy use of this syntax.
+
+[section Example 1]
+
+[code #]
+ [chapter How to send an e-mail]
+
+ In this chapter, you'll learn how to send an e-mail
+
+ [section Why would I do that?]
+
+ The ::e-mail:: is the **main** comunication mean of most companies. Anyone
+ should be able to send an ::e-mail:::
+
+ [section The steps]
+ [list number]
+ * **Browser:** Double click on your browser's icon (Firefox, Iceweasel,
+ IE, Safari,...)
+ * **Navigating:** Copy the page address in your browser's address bar.
+ [TODO missing steps]
+ * **Log in:** Copy your login and passward to their respective fields and
+ Click on %%ok%%.
+ [/list]
+
+ That is your ::inbox:: folder. The incoming e-mails will appear there.
+
+ [box Where do I learn more?]
+ You can learn some more by exploring your e-mails' page. There must be a
+ link somewhere that teaches you all funcionalities of your e-mail -
+ including where it keeps the e-mail you send or how do you delete
+ unwanted e-mail.
+ [/box]
+[/code]
+
+[section Example 2]
+
+[code]How do you write a HelloWorld...
+
+ [list]
+ * **in Java**
+
+ [java]
+ public static void main(String[] args){
+ System.out.println("Hello world!");
+ }
+ [/java]
+
+ * **in C**
+
+ [code]
+ int main(){
+ printf("Hello world!\n");
+ return 0;
+ }
+ [/code]
+ [/list]
+[/code]
144 docs/09-testing-your-layout.afcx
@@ -0,0 +1,144 @@
+[chapter *.afc output layout test]
+
+In order for you to test your stylesheets, here is a test page for the *.afc format layout.
+
+It includes all the displayed tags of the Tubaina syntax. Go on, try your own layout on it (our's works)!
+
+[section Chapters, sections and other chunks]
+
+This just allows us verify if the sections are correctly working and so are its paragraphs and stuff like
+that.
+
+It is kind of important to verify paragraph spacing.
+
+[title unimportant section]
+
+This section should appear on the same html page as the section "Chapters, sections and other chunks"
+
+[quote To understand recursion, you must first understand recursion -- Anonymous ]
+
+Not labeled text, [label A simple label! No tag is allowed here]Labeled text[/label].
+
+[box A sample box] This should be contained in a box and all the kinds of code tag in it. Let's see...
+
+**Java:**
+[java]
+public static void main (String[] args) {
+ System.out.println("Hello world!");
+}
+[/java]
+
+**XML:**
+[xml]
+<printIt when="now">
+ Hello world!
+ <skipLine />
+</printIt>
+[/xml]
+
+**Code:**
+[code]
+int main(){
+ printf("Hello world!\n");
+}
+[/code]
+
+**Code properties:**
+[code properties]
+print: "Hello world!"
+jumpLine= 1 line
+[/code]
+
+Check if there is no weird color background on the codes above. If there is, you should use the *.css tag:
+
+[code properties]background-color: inherit[/code]
+[/box]
+
+[title Code chunk outside boxes]
+
+Now we're testing the Code chunks outside the boxes - just to make sure you didn't messed it all up when
+fixing the stylesheets for boxes. Besides, we're testing the lines highlight on all the code types,
+boldening the printing lines on each format.
+
+**Java:**
+[java h=2]
+public static void main (String[] args) {
+ System.out.println("Hello world!");
+}
+[/java]
+
+**XML:**
+[xml h=2,3]
+<printIt when="now">
+ Hello world!
+ <skipLine />
+</printIt>
+[/xml]
+
+**Code:**
+[code h=2]
+int main(){
+ printf("Hello world!\n");
+}
+[/code]
+
+**Code properties:**
+[code properties h=1,2]
+print: "Hello world!"
+jumpLine= 1 line
+[/code]
+
+[title Exercises]
+
+The exercise tag enumerates the exercises. Pay attention to that.
+
+Furthermore, the answer tag should create either a dropdown tab, on HTML, or a answer booklet at the end of
+the Latex output.
+
+[exercise]
+ [question] The question
+ [answer] The answer [/answer]
+ [/question]
+
+ [question] The other question...
+ [answer] The respective (second) answer [/answer]
+ [/question]
+[/exercise]
+
+[note]Note to the instructor. Is your layout good enough for your instructor to read? ;)[/note]
+
+[title Text layout]
+**Bold** normal text ::italic:: normal text __underlined__ normal text %%code%% normal text
+
+[title Lists]
+
+**Circular bulleted list:**
+[list]
+ * item
+ * item
+[/list]
+
+**Numbered list:**
+[list number]
+ * item
+[/list]
+
+**Roman counter list:**
+[list roman]
+ * item
+[/list]
+
+**Letter counter list:**
+[list letter]
+ * item
+[/list]
+
+[title Links and Images]
+
+**Links:**
+
+http://tubaina.sourceforge.net and http://www.caelumobjects.com
+
+**Images:**
+
+[img ../src/test/basePngImage.png w=30% "The image for testing"]
BIN lib/Tidy.jar
Binary file not shown.
BIN lib/commons-cli-1.1.jar
Binary file not shown.
BIN lib/commons-io-1.3.1.jar
Binary file not shown.
BIN lib/freemarker.jar
Binary file not shown.
BIN lib/jai_codec.jar
Binary file not shown.
BIN lib/jai_core.jar
Binary file not shown.
BIN lib/jai_imageio.jar
Binary file not shown.
BIN lib/java2html.jar
Binary file not shown.
BIN lib/log4j-1.2.12.jar
Binary file not shown.
202 src/etc/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
6 src/etc/latex.sh
@@ -0,0 +1,6 @@
+#! /bin/sh
+echo Gerando latex...
+
+yes s | pdflatex $1.tex > /dev/null
+makeindex $1.idx > /dev/null
+yes s | pdflatex $1.tex > /dev/null
17 src/etc/tubaina
@@ -0,0 +1,17 @@
+#! /bin/bash
+
+
+
+if [ -z "$JAVA_HOME" ]; then
+ echo "Enviroment variable JAVA_HOME must be set in order to run tubaina";
+elif [ -z "$TUBAINA_HOME" ]; then
+ #echo "Could not find TUBAINA_HOME. Will work only if inside Tubaina bin directory";
+ WHICH=`which $0`;
+ export TUB_REL_PATH="${WHICH%/tubaina}/@TUB_HOME_MOD";
+ $JAVA_HOME/bin/java -classpath @CLASSPATH br.com.caelum.tubaina.Tubaina $@;
+
+else
+ export TUB_REL_PATH=$TUBAINA_HOME;
+ $JAVA_HOME/bin/java -classpath @CLASSPATH br.com.caelum.tubaina.Tubaina $@;
+fi;
+
23 src/java/br/com/caelum/tubaina/Book.java
@@ -0,0 +1,23 @@
+package br.com.caelum.tubaina;
+
+import java.util.List;
+
+public class Book {
+
+ private List<Chapter> chapters;
+
+ private String name;
+
+ public Book(String name, List<Chapter> chapters) {
+ this.chapters = chapters;
+ this.name = name;
+ }
+
+ public List<Chapter> getChapters() {
+ return chapters;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
47 src/java/br/com/caelum/tubaina/Chapter.java
@@ -0,0 +1,47 @@
+package br.com.caelum.tubaina;
+
+import java.util.List;
+
+import br.com.caelum.tubaina.parser.Parser;
+import br.com.caelum.tubaina.resources.Resource;
+
+public class Chapter {
+
+ private static int COUNT = 1;
+
+ private String title;
+
+ private List<Section> sections;
+
+ private List<Resource> resources;
+
+ private Chunk introduction;
+
+ public Chapter(String title, Chunk introduction, List<Section> sections, List<Resource> resources) {
+ this.title = title;
+ this.sections = sections;
+ this.resources = resources;
+ this.introduction = introduction;
+ COUNT++;
+ }
+
+ public List<Section> getSections() {
+ return sections;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public List<Resource> getResources() {
+ return resources;
+ }
+
+ public String getIntroduction(Parser p){
+ return this.introduction.getContent(p);
+ }
+
+ public static int getChaptersCount() {
+ return COUNT;
+ }
+}
7 src/java/br/com/caelum/tubaina/Chunk.java
@@ -0,0 +1,7 @@
+package br.com.caelum.tubaina;
+
+import br.com.caelum.tubaina.parser.Parser;
+
+public interface Chunk {
+ public String getContent(Parser p);
+}
5 src/java/br/com/caelum/tubaina/CompositeChunk.java
@@ -0,0 +1,5 @@
+package br.com.caelum.tubaina;
+
+public interface CompositeChunk extends Chunk {
+
+}
30 src/java/br/com/caelum/tubaina/Section.java
@@ -0,0 +1,30 @@
+package br.com.caelum.tubaina;
+
+import java.util.List;
+
+public class Section {
+
+ private static int COUNT = 1;
+
+ private List<Chunk> chunks;
+
+ private String title;
+
+ public Section(String title, List<Chunk> chunks) {
+ this.title = title;
+ this.chunks = chunks;
+ COUNT++;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public List<Chunk> getChunks() {
+ return chunks;
+ }
+
+ public static int getSectionsCount() {
+ return COUNT;
+ }
+}
219 src/java/br/com/caelum/tubaina/Tubaina.java
@@ -0,0 +1,219 @@
+package br.com.caelum.tubaina;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.SuffixFileFilter;
+import org.apache.log4j.Logger;
+
+import br.com.caelum.tubaina.builder.BookBuilder;
+import br.com.caelum.tubaina.parser.Generator;
+import br.com.caelum.tubaina.parser.Parser;
+import br.com.caelum.tubaina.parser.RegexConfigurator;
+import br.com.caelum.tubaina.parser.Tag;
+import br.com.caelum.tubaina.parser.html.HtmlGenerator;
+import br.com.caelum.tubaina.parser.html.HtmlParser;
+import br.com.caelum.tubaina.parser.latex.LatexGenerator;
+import br.com.caelum.tubaina.parser.latex.LatexParser;
+import br.com.caelum.tubaina.resources.ResourceLocator;
+
+public class Tubaina {
+
+ public static final File DEFAULT_TEMPLATE_DIR = new File("src/templates");
+ public static final Logger LOG = Logger.getLogger(Tubaina.class);
+ public static final int MAX_LINE_LENGTH = 93; //believe us... this is what fits in Latex A4 templates.
+
+ private static File inputDir = new File(".");
+ private static File outputDir = new File(".");
+ private static String bookName;
+ //TODO listar todos
+ private static boolean listTodos;
+ private static boolean strictXhtml;
+ private static File templateDir = DEFAULT_TEMPLATE_DIR;
+ private static boolean html;
+ private static boolean latex;
+ private static boolean showNotes;
+ private static boolean dontCare;
+ private static boolean noAnswer;
+
+ public static void main(String[] args) throws IOException {
+
+ CommandLineParser parser = new PosixParser();
+
+ Options options = registerOptions();
+
+ try {
+ LOG.debug("Parsing arguments " + Arrays.toString(args));
+ CommandLine cmd = parser.parse(options, args);
+ parseOptions(cmd, options);
+ } catch (ParseException e) {
+ System.err.println( "Parsing failed. Reason: " + e.getMessage() );
+ printUsage(options);
+ System.exit(-1);
+ }
+
+ generate();
+
+ }
+
+ private static void generate() throws IOException {
+
+ ResourceLocator.initialize(inputDir);
+
+ List<Reader> readers = getAfcsFrom(inputDir);
+ BookBuilder builder = new BookBuilder(bookName);
+ builder.addAll(readers);
+
+ Book b = null;
+ try {
+ b = builder.build();
+ } catch (TubainaException e) {
+ if (dontCare) {
+ LOG.warn(e);
+ } else {
+ e.printStackTrace();
+ System.exit(-1);
+ }
+ }
+
+ RegexConfigurator conf = new RegexConfigurator();
+ if (latex) {
+ List<Tag> tags = conf.read("/regex.properties", "/latex.properties");
+
+ Parser parser = new LatexParser(tags, showNotes, noAnswer);
+ Generator latexGenerator = new LatexGenerator(parser, templateDir, noAnswer);
+ File file = new File(outputDir, "latex");
+ FileUtils.forceMkdir(file);
+ try {
+ latexGenerator.generate(b, file);
+ } catch (TubainaException e) {
+ LOG.warn(e.getMessage());
+ }
+ }
+
+ if (html) {
+ HtmlParser htmlParser = new HtmlParser(conf.read("/regex.properties", "/html.properties"), noAnswer);
+ Generator generator = new HtmlGenerator(htmlParser, strictXhtml, templateDir);
+ File file = new File(outputDir, "html");
+ FileUtils.forceMkdir(file);
+ try {
+ generator.generate(b, file);
+ } catch (TubainaException e) {
+ LOG.warn(e.getMessage());
+ }
+ }
+
+ }
+
+ private static void parseOptions(CommandLine cmd, Options options) {
+ if (cmd.hasOption("h")) {
+ printUsage(options);
+ } else {
+ if (cmd.hasOption('i')) {
+ inputDir = new File(cmd.getOptionValue('i'));
+ }
+
+ if (cmd.hasOption('o')) {
+ outputDir = new File(cmd.getOptionValue('o'));
+ }
+
+ if (cmd.hasOption('t')) {
+ templateDir = new File(cmd.getOptionValue('t'));
+ }
+
+ bookName = cmd.getOptionValue('n');
+
+ listTodos = cmd.hasOption('l');
+
+ strictXhtml = cmd.hasOption('x');
+
+ showNotes = cmd.hasOption('s');
+
+ html = cmd.hasOption("html");
+ latex = cmd.hasOption("latex");
+ dontCare = cmd.hasOption("d");
+ noAnswer = cmd.hasOption("a");
+
+
+ }
+
+ }
+
+ @SuppressWarnings("static-access")
+ private static Options registerOptions() {
+ Options options = new Options();
+ options.addOption("h", "help", false, "print this message");
+
+ options.addOption("latex", false, "generates an latex output on given outputdir");
+ options.addOption("html", false, "generates an html output on given outputdir");
+
+ //inputdir
+ options.addOption(OptionBuilder.withArgName("directory")
+ .withLongOpt("input-dir")
+ .hasArg()
+ .withDescription("directory where you have your .afc files")
+ .create('i'));
+ //outputdir
+ options.addOption(OptionBuilder.withArgName("directory")
+ .withLongOpt("output-dir")
+ .hasArg()
+ .isRequired()
+ .withDescription("directory where you want the output files")
+ .create('o'));
+ //name
+ options.addOption(OptionBuilder.withArgName("bookName")
+ .withLongOpt("name")
+ .hasArg()
+ .isRequired()
+ .withDescription("name of your book")
+ .create('n'));
+ //optional
+ options.addOption("l", "list-todos", false, "lists todos from all files");
+ options.addOption("x", "strict-xhtml", false, "perform an xhtml validation");
+ options.addOption("s", "show-notes", false, "shows notes in Latex output");
+ options.addOption("d", "dontcare", false, "ignore all errors");
+ options.addOption("a", "no-answers", false, "don't make the answers booklet");
+
+ options.addOption(OptionBuilder.withArgName("directory")
+ .withLongOpt("template-dir")
+ .hasArg()
+ .withDescription("directory where you have your template files")
+ .create('t'));
+ return options;
+ }
+
+ private static void printUsage(Options options) {
+ // automatically generate the help statement
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp( "tubaina [-html|-latex] -i <inputdir> -o <outputdir> -n <bookname>", options );
+ }
+
+ static List<Reader> getAfcsFrom(File file) throws UnsupportedEncodingException, FileNotFoundException {
+ List<Reader> readers = new ArrayList<Reader>();
+ List<String> files = new ArrayList<String>();
+ Collections.addAll(files, file.list(new SuffixFileFilter(".afc")));
+ Collections.sort(files);
+ for (String s : files) {
+ readers.add(new InputStreamReader(new FileInputStream(new File(file, s)), "UTF-8"));
+ }
+ return readers;
+ }
+
+}
23 src/java/br/com/caelum/tubaina/TubainaException.java
@@ -0,0 +1,23 @@
+package br.com.caelum.tubaina;
+
+public class TubainaException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ public TubainaException() {
+ super();
+ }
+
+ public TubainaException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public TubainaException(String message) {
+ super(message);
+ }
+
+ public TubainaException(Throwable cause) {
+ super(cause);
+ }
+
+}
80 src/java/br/com/caelum/tubaina/builder/BookBuilder.java
@@ -0,0 +1,80 @@
+package br.com.caelum.tubaina.builder;
+
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.log4j.Logger;
+
+import br.com.caelum.tubaina.Book;
+import br.com.caelum.tubaina.Chapter;
+
+public class BookBuilder {
+
+ private final Logger LOG = Logger.getLogger(BookBuilder.class);
+ private final String name;
+
+ private final List<Reader> readers = new ArrayList<Reader>();
+
+ public BookBuilder(String name) {
+ this.name = name;
+ }
+
+ public void add(Reader fileReader) {
+ this.readers.add(fileReader);
+ }
+
+ public void addAll(List<Reader> readers) {
+ this.readers.addAll(readers);
+ }
+
+ public Book build() {
+ List<Chapter> chapters = new ArrayList<Chapter>();
+ for (Reader reader : readers) {
+ LOG.info("Parsing chapter " + Chapter.getChaptersCount());
+ Scanner scanner = new Scanner(reader);
+ scanner.useDelimiter("$$");
+ if (scanner.hasNext())
+ chapters.addAll(parse(scanner.next()));
+ }
+ return new Book(name, chapters);
+ }
+
+ private List<Chapter> parse(String text) {
+ Pattern pattern = Pattern.compile("(?i)(?s)(?m)^\\[chapter(.*?)\\](.*?)(\n\\[chapter|\\z)");
+ Matcher matcher = pattern.matcher(text);
+
+ List<Chapter> chapters = new ArrayList<Chapter>();
+
+ Integer offset = 0;
+
+ while (matcher.find(offset)) {
+
+
+ String title = matcher.group(1).trim();
+ String content = matcher.group(2);
+ offset = matcher.end(2);
+
+
+ Pattern introductionPattern = Pattern.compile("(?i)(?s)(.*?)(?:\\[section|\\z)");
+ Matcher introductionMatcher = introductionPattern.matcher(content);
+
+ String introduction = "";
+ if (introductionMatcher.find())
+ introduction = introductionMatcher.group(1);
+
+ content = content.substring(introduction.length());
+
+ Chapter chapter = new ChapterBuilder(title, introduction, content).build();
+ chapters.add(chapter);
+
+ }
+
+ return chapters;
+ }
+
+
+}
58 src/java/br/com/caelum/tubaina/builder/ChapterBuilder.java
@@ -0,0 +1,58 @@
+package br.com.caelum.tubaina.builder;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import br.com.caelum.tubaina.Chapter;
+import br.com.caelum.tubaina.Section;
+import br.com.caelum.tubaina.chunk.IntroductionChunk;
+import br.com.caelum.tubaina.resources.Resource;
+
+public class ChapterBuilder {
+
+ private final String title;
+
+ private final String content;
+
+ private final Matcher matcher;
+
+ private final String introduction;
+
+ public ChapterBuilder(String title, String introduction, String content) {
+ this.title = title;
+ this.content = content;
+ this.introduction = introduction;
+ Pattern pattern = Pattern.compile("(?i)(?s)(?m)^\\[section(.*?)\\](.*?)(\n\\[section|\\z)");
+ this.matcher = pattern.matcher(content);
+ }
+
+ public Chapter build() {
+
+ List<Section> sections = new ArrayList<Section>();
+ List<Resource> resources = new ArrayList<Resource>();
+ if (content != null && content.trim().length() > 0) {
+
+ Integer offset = 0;
+
+ while (matcher.find(offset)) {
+ String sectionTitle = matcher.group(1);
+ if (sectionTitle != null) {
+ sectionTitle = sectionTitle.trim();
+ }
+ String sectionContent = matcher.group(2);
+ if (sectionTitle != null || sectionContent.trim().length() > 0) {
+ Section section = new SectionBuilder(sectionTitle, sectionContent, resources).build();
+ sections.add(section);
+ }
+ offset = matcher.end(2);
+ }
+ }
+
+ IntroductionChunk intro = new IntroductionChunk(new ChunkSplitter(resources, "all").splitChunks(introduction));
+
+ return new Chapter(title, intro, sections, resources);
+ }
+
+}
22 src/java/br/com/caelum/tubaina/builder/ChunkSplitter.java
@@ -0,0 +1,22 @@
+package br.com.caelum.tubaina.builder;
+
+import java.util.List;
+
+import br.com.caelum.tubaina.Chunk;
+import br.com.caelum.tubaina.resources.Resource;
+
+public class ChunkSplitter {
+
+ private List<Resource> resources;
+ private String replacerType;
+
+ public ChunkSplitter(List<Resource> resources, String replacerType) {
+ this.resources = resources;
+ this.replacerType = replacerType;
+ }
+
+ public List<Chunk> splitChunks(String text) {
+ ChunksMaker maker = new ChunksMakerBuilder(resources).build(replacerType);
+ return maker.make(text);
+ }
+}
37 src/java/br/com/caelum/tubaina/builder/ChunksMaker.java
@@ -0,0 +1,37 @@
+package br.com.caelum.tubaina.builder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import br.com.caelum.tubaina.Chapter;
+import br.com.caelum.tubaina.Chunk;
+import br.com.caelum.tubaina.TubainaException;
+import br.com.caelum.tubaina.builder.replacer.Replacer;
+
+public class ChunksMaker {
+
+ private final List<Replacer> replacers = new ArrayList<Replacer>();
+
+ public List<Chunk> make(String text) {
+ List<Chunk> chunks = new ArrayList<Chunk>();
+ while (text.trim().length() != 0) {
+ boolean accepted = false;
+ for (Replacer replacer : replacers) {
+ if(replacer.accepts(text)) {
+ text = replacer.execute(text, chunks);
+ accepted = true;
+ break;
+ }
+ }
+ if (!accepted)
+ throw new TubainaException("There is a syntax error on chapter "+ Chapter.getChaptersCount() +
+ ": Probably, there is some text inside an exercise tag, but outside a question tag");
+ }
+ return chunks;
+ }
+
+ public void register(Replacer replacer) {
+ this.replacers.add(replacer);
+ }
+
+}
161 src/java/br/com/caelum/tubaina/builder/ChunksMakerBuilder.java
@@ -0,0 +1,161 @@
+package br.com.caelum.tubaina.builder;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import br.com.caelum.tubaina.builder.replacer.AnswerReplacer;
+import br.com.caelum.tubaina.builder.replacer.BoxReplacer;
+import br.com.caelum.tubaina.builder.replacer.CodeReplacer;
+import br.com.caelum.tubaina.builder.replacer.ExerciseReplacer;
+import br.com.caelum.tubaina.builder.replacer.ImageReplacer;
+import br.com.caelum.tubaina.builder.replacer.IndexReplacer;
+import br.com.caelum.tubaina.builder.replacer.ItemReplacer;
+import br.com.caelum.tubaina.builder.replacer.JavaReplacer;
+import br.com.caelum.tubaina.builder.replacer.ListReplacer;
+import br.com.caelum.tubaina.builder.replacer.NoteReplacer;
+import br.com.caelum.tubaina.builder.replacer.ParagraphReplacer;
+import br.com.caelum.tubaina.builder.replacer.QuestionReplacer;
+import br.com.caelum.tubaina.builder.replacer.Replacer;
+import br.com.caelum.tubaina.builder.replacer.TodoReplacer;
+import br.com.caelum.tubaina.builder.replacer.XmlReplacer;
+import br.com.caelum.tubaina.resources.Resource;
+
+public class ChunksMakerBuilder {
+
+ private Map<String, List<Replacer>> replacerMap = new HashMap<String, List<Replacer>>();
+
+ private String paragraphTerminator = "java|box|code|img|list|xml|exercise|note|answer|item|question|todo|index";
+
+ private static final List<String> CLOSABLE_TAGS;
+ static {
+ CLOSABLE_TAGS = new ArrayList<String>();
+ Collections.addAll(CLOSABLE_TAGS, "java", "box", "code", "list", "xml", "exercise", "note", "answer",
+ "question", "label", "mail");
+ }
+
+ public static boolean isClosableTag(String tag) {
+ return CLOSABLE_TAGS.contains(tag.toLowerCase());
+ }
+ public ChunksMakerBuilder(List<Resource> resources) {
+ List<Replacer> replacers;
+
+ // Answer tag
+ replacers = new ArrayList<Replacer>();
+ replacers.add(new BoxReplacer(resources));
+ replacers.add(new CodeReplacer());
+ replacers.add(new ImageReplacer(resources));
+ replacers.add(new JavaReplacer());
+ replacers.add(new ListReplacer(resources));
+ replacers.add(new NoteReplacer(resources));
+ replacers.add(new XmlReplacer());
+ replacers.add(new IndexReplacer(resources));
+ replacers.add(new TodoReplacer());
+ replacers.add(new ParagraphReplacer(paragraphTerminator));
+ replacerMap.put("answer", replacers);
+
+ // Box tag
+ replacers = new ArrayList<Replacer>();
+ replacers.add(new CodeReplacer());
+ replacers.add(new ImageReplacer(resources));
+ replacers.add(new JavaReplacer());
+ replacers.add(new ListReplacer(resources));
+ replacers.add(new XmlReplacer());
+ replacers.add(new NoteReplacer(resources));
+ replacers.add(new IndexReplacer(resources));
+ replacers.add(new TodoReplacer());
+ replacers.add(new ParagraphReplacer(paragraphTerminator));
+ replacerMap.put("box", replacers);
+
+ // Exercise tag
+ replacers = new ArrayList<Replacer>();
+ replacers.add(new QuestionReplacer(resources));
+ replacers.add(new NoteReplacer(resources));
+ replacers.add(new TodoReplacer());
+ replacerMap.put("exercise", replacers);
+
+ // Item tag
+ replacers = new ArrayList<Replacer>();
+ replacers.add(new BoxReplacer(resources));
+ replacers.add(new CodeReplacer());
+ replacers.add(new ExerciseReplacer(resources));
+ replacers.add(new ListReplacer(resources));
+ replacers.add(new ImageReplacer(resources));
+ replacers.add(new JavaReplacer());
+ replacers.add(new NoteReplacer(resources));
+ replacers.add(new XmlReplacer());
+ replacers.add(new IndexReplacer(resources));
+ replacers.add(new TodoReplacer());
+ replacers.add(new ParagraphReplacer(paragraphTerminator));
+ replacerMap.put("item", replacers);
+
+ // List tag
+ replacers = new ArrayList<Replacer>();
+ replacers.add(new ItemReplacer(resources));
+ replacers.add(new NoteReplacer(resources));
+ replacers.add(new TodoReplacer());
+ replacerMap.put("list", replacers);
+
+ // Note tag
+ replacers = new ArrayList<Replacer>();
+ replacers.add(new CodeReplacer());
+ replacers.add(new ImageReplacer(resources));
+ replacers.add(new JavaReplacer());
+ replacers.add(new ListReplacer(resources));
+ replacers.add(new XmlReplacer());
+ replacers.add(new IndexReplacer(resources));
+ replacers.add(new TodoReplacer());
+ replacers.add(new ParagraphReplacer(paragraphTerminator));
+ replacerMap.put("note", replacers);
+
+ // Question tag
+ replacers = new ArrayList<Replacer>();
+ replacers.add(new AnswerReplacer(resources));
+ replacers.add(new BoxReplacer(resources));
+ replacers.add(new CodeReplacer());
+ replacers.add(new ImageReplacer(resources));
+ replacers.add(new JavaReplacer());
+ replacers.add(new ListReplacer(resources));
+ replacers.add(new NoteReplacer(resources));
+ replacers.add(new XmlReplacer());
+ replacers.add(new IndexReplacer(resources));
+ replacers.add(new NoteReplacer(resources));
+ replacers.add(new TodoReplacer());
+ replacers.add(new ParagraphReplacer(paragraphTerminator));
+ replacerMap.put("question", replacers);
+
+ // All tags not restricted to others, like ItemTag
+ replacers = new ArrayList<Replacer>();
+ replacers.add(new AnswerReplacer(resources));
+ replacers.add(new BoxReplacer(resources));
+ replacers.add(new CodeReplacer());
+ replacers.add(new ExerciseReplacer(resources));
+ replacers.add(new ImageReplacer(resources));
+ replacers.add(new JavaReplacer());
+ replacers.add(new ListReplacer(resources));
+ replacers.add(new NoteReplacer(resources));
+ replacers.add(new QuestionReplacer(resources));
+ replacers.add(new XmlReplacer());
+ replacers.add(new IndexReplacer(resources));
+ replacers.add(new TodoReplacer());
+ replacers.add(new ParagraphReplacer(paragraphTerminator));
+ replacerMap.put("all", replacers);
+
+ }
+
+ public ChunksMaker build(String tag) {
+ ChunksMaker maker = new ChunksMaker();
+ if (replacerMap.containsKey(tag)) {
+ for (Replacer replacer : replacerMap.get(tag)) {
+ maker.register(replacer);
+ }
+ }
+ // Every tag shall have an inner ToDo tag
+// maker.register(new TodoReplacer());
+ // paragraphReplacer MUST be the last one to be parsed or it won't work
+// maker.register(new ParagraphReplacer(paragraphTerminator));
+ return maker;
+ }
+}
25 src/java/br/com/caelum/tubaina/builder/SectionBuilder.java
@@ -0,0 +1,25 @@
+package br.com.caelum.tubaina.builder;
+
+import java.util.List;
+
+import br.com.caelum.tubaina.Section;
+import br.com.caelum.tubaina.resources.Resource;
+
+public class SectionBuilder {
+
+ private final String sectionTitle;
+
+ private final String sectionContent;
+
+ private final List<Resource> resources;
+
+ public SectionBuilder(String sectionTitle, String sectionContent, List<Resource> resources) {
+ this.sectionTitle = sectionTitle;
+ this.sectionContent = sectionContent;
+ this.resources = resources;
+ }
+
+ public Section build() {
+ return new Section(sectionTitle, new ChunkSplitter(resources, "all").splitChunks(sectionContent));
+ }
+}
66 src/java/br/com/caelum/tubaina/builder/replacer/AbstractReplacer.java
@@ -0,0 +1,66 @@
+package br.com.caelum.tubaina.builder.replacer;
+
+import java.util.List;
+import java.util.Stack;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import br.com.caelum.tubaina.Chunk;
+import br.com.caelum.tubaina.TubainaException;
+import br.com.caelum.tubaina.builder.ChunksMakerBuilder;
+
+public abstract class AbstractReplacer implements Replacer {
+
+ private final Pattern openPattern;
+ private Pattern tagPattern;
+ private final String tag;
+
+ public AbstractReplacer(String tag) {
+ this.tag = tag;
+ this.openPattern = Pattern.compile("(?s)(?i)\\A\\s*\\["+tag+"(.*?)\\]");
+ this.tagPattern = Pattern.compile("(?s)(?i)\\[(/)?(\\w+)(.*?)\\]");
+ }
+
+ public String execute(String text, List<Chunk> chunks) {
+ Matcher matcher = openPattern.matcher(text);
+ matcher.find();
+ String options = matcher.group(1);
+
+ int contentStart = matcher.end();
+
+ Matcher tagMatcher = tagPattern.matcher(text.substring(contentStart));
+
+ Stack<String> stack = new Stack<String>();
+ stack.push(tag);
+// int tagsInside = 1;
+ while (!stack.isEmpty() && tagMatcher.find()) {
+ String tagName = tagMatcher.group(2);
+ if (tagMatcher.group(1) == null) { //is openTag ([tag])
+ if (ChunksMakerBuilder.isClosableTag(tagName)) {
+ stack.push(tagName);
+ }
+ } else { //is closeTag ([/tag])
+ if (stack.peek().equalsIgnoreCase(tagName)) {
+ stack.pop();
+ } else {
+ throw new TubainaException("Tag " + tagName + " was closed unproperly");
+ }
+ }
+ }
+ if (!stack.isEmpty()) { //tag was not closed properly
+ throw new TubainaException("There is(are) unclosed tag(s) : " + stack.toString());
+ }
+ String content = text.substring(contentStart, contentStart + tagMatcher.start());
+
+ chunks.add(createChunk(options, content));
+ return text.substring(contentStart + tagMatcher.end());
+ }
+
+ protected abstract Chunk createChunk(String options, String content);
+
+ public boolean accepts(String text) {
+ Matcher matcher = openPattern.matcher(text);
+ return matcher.find();
+ }
+
+}
27 src/java/br/com/caelum/tubaina/builder/replacer/AnswerReplacer.java
@@ -0,0 +1,27 @@
+package br.com.caelum.tubaina.builder.replacer;
+
+import java.util.List;
+
+import br.com.caelum.tubaina.Chunk;
+import br.com.caelum.tubaina.builder.ChunkSplitter;
+import br.com.caelum.tubaina.chunk.AnswerChunk;
+import br.com.caelum.tubaina.resources.AnswerResource;
+import br.com.caelum.tubaina.resources.Resource;
+
+public class AnswerReplacer extends AbstractReplacer {
+
+ private List<Resource> resources;
+
+ public AnswerReplacer(List<Resource> resources) {
+ super("answer");
+ this.resources = resources;
+ }
+
+ @Override
+ public Chunk createChunk(String options, String content) {
+ AnswerChunk chunk = new AnswerChunk(new ChunkSplitter(resources, "answer").splitChunks(content));
+ resources.add(new AnswerResource(chunk));
+ return chunk;
+ }
+
+}
30 src/java/br/com/caelum/tubaina/builder/replacer/BoxReplacer.java
@@ -0,0 +1,30 @@
+package br.com.caelum.tubaina.builder.replacer;
+
+import java.util.List;
+
+import br.com.caelum.tubaina.Chunk;
+import br.com.caelum.tubaina.TubainaException;
+import br.com.caelum.tubaina.builder.ChunkSplitter;
+import br.com.caelum.tubaina.chunk.BoxChunk;
+import br.com.caelum.tubaina.resources.Resource;
+
+public class BoxReplacer extends AbstractReplacer {
+
+ private List<Resource> resources;
+
+ public BoxReplacer(List<Resource> resources) {
+ super("box");
+ this.resources = resources;
+ }
+
+ @Override
+ public Chunk createChunk(String options, String content) {
+ if (options == null || options.trim().length() == 0) {
+ throw new TubainaException("Boxes must have a non-empty title");
+ }
+ String title = options.trim();
+ List<Chunk> body = new ChunkSplitter(resources, "box").splitChunks(content);
+ return new BoxChunk(title, body);
+ }
+
+}
25 src/java/br/com/caelum/tubaina/builder/replacer/CodeReplacer.java
@@ -0,0 +1,25 @@
+package br.com.caelum.tubaina.builder.replacer;
+
+import br.com.caelum.tubaina.Chapter;
+import br.com.caelum.tubaina.Chunk;
+import br.com.caelum.tubaina.Tubaina;
+import br.com.caelum.tubaina.TubainaException;
+import br.com.caelum.tubaina.chunk.CodeChunk;
+import br.com.caelum.tubaina.util.Utilities;
+
+public class CodeReplacer extends AbstractReplacer {
+
+ public CodeReplacer() {
+ super("code");
+ }
+
+ @Override
+ public Chunk createChunk(String options, String content) {
+ int maxLineLenght = Utilities.maxLineLength(content) - Utilities.getMinIndent(content);
+ if(maxLineLenght >Tubaina.MAX_LINE_LENGTH)
+ throw new TubainaException ("Chapter " + Chapter.getChaptersCount() +
+ " - Code has " + maxLineLenght + " columns:\n\n" + content);
+ return new CodeChunk(content, options);
+ }
+
+}
43 src/java/br/com/caelum/tubaina/builder/replacer/ExerciseReplacer.java
@@ -0,0 +1,43 @@
+package br.com.caelum.tubaina.builder.replacer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import br.com.caelum.tubaina.Chunk;
+import br.com.caelum.tubaina.builder.ChunkSplitter;
+import br.com.caelum.tubaina.chunk.ExerciseChunk;
+import br.com.caelum.tubaina.resources.AnswerResource;
+import br.com.caelum.tubaina.resources.ExerciseResource;
+import br.com.caelum.tubaina.resources.Resource;
+
+public class ExerciseReplacer extends AbstractReplacer {
+
+ private List<Resource> resources;
+
+
+ public ExerciseReplacer(List<Resource> resources) {
+ super("exercise");
+ this.resources = resources;
+ }
+
+ @Override
+ public Chunk createChunk(String options, String content) {
+ ArrayList<Resource> subResources = new ArrayList<Resource>();
+ ChunkSplitter splitter = new ChunkSplitter(subResources, "exercise");
+ List<Chunk> chunks = splitter.splitChunks(content);
+ if (hasAnswer(subR