package ie.ucd.clops.documentation;

import java.io.Writer;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

/**
 * <BON>
 * class_chart DOCUMENT_GENERATION 
 *   explanation "Generation of documentation from the descriptions of options"
 *  end
 * </BON>
 */

public class DocumentGeneration {

	public void generate() {
		try {
			Velocity.init();

			VelocityContext context = new VelocityContext();

			context.put("option", new OptionDescription());

			Template template = Velocity.getTemplate("html.vm");

			Writer writer = new java.io.OutputStreamWriter(System.out);

			template.merge(context, writer);

			writer.flush();
			writer.close();

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}

@@ -30,16 +30,73 @@
 ation;%0A%0A
+import java.io.OutputStream;%0Aimport java.io.PrintStream;%0A
 import j
@@ -285,18 +285,16 @@
 TION %0A *
-  
  explana
@@ -298,16 +298,22 @@
 anation 
+%0A *   
 %22Generat
@@ -370,16 +370,56 @@
 ons%22%0A * 
+command%0A *   %22Generate Documentation%22%0A *
  end%0A * 
@@ -477,22 +477,106 @@
 lic 
-void generate(
+static final String HTML_TEMPLATE_NAME = %22html.vm%22;%0A%0A%09public void generate(OutputStream targetFile
 ) %7B%0A
@@ -637,20 +637,14 @@
 t = 
-new Velocity
+create
 Cont
@@ -655,60 +655,8 @@
 );%0A%0A
-%09%09%09context.put(%22option%22, new OptionDescription());%0A%0A
 %09%09%09T
@@ -695,25 +695,53 @@
 emplate(
-%22html.vm%22
+DocumentGeneration.HTML_TEMPLATE_NAME
 );%0A%0A%09%09%09W
@@ -790,18 +790,18 @@
 ter(
-System.out
+targetFile
 );%0A%0A
@@ -912,68 +912,294 @@
 %09// 
+@
 TODO 
-Auto-generated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A
+log this%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%0A%09%7D%0A%0A%09/**%0A%09 * Define the context for document generation%0A%09 * %0A%09 * @return%0A%09 */%0A%09protected VelocityContext createContext() %7B%0A%09%09VelocityContext context = new VelocityContext();%0A%0A%09%09context.put(%22option%22, new OptionDescription());%0A%09%09return context;
 %0A%09%7D%0A

Refactor a new method for context definition i.e. mapping between templates and data structures