package com.javahonk.controller;

import java.io.File;
import java.io.StringWriter;
import java.util.Properties;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
public class SpringMVCController {
	
	@RequestMapping(value = "/firstPage")	
	public @ResponseBody String firstPage() {
		
		Properties prop = new Properties();
		String absolutePath=new File(Thread.currentThread().getContextClassLoader().getResource("").getFile()).getParentFile().getParentFile().getPath();
		prop.put("file.resource.loader.path", absolutePath+"/WEB-INF/classes");
		VelocityEngine ve = new VelocityEngine();
		ve.init(prop);
		Template t = ve.getTemplate("/templates/Sample.vm");
		VelocityContext vc = new VelocityContext();	
		vc.put("firstName", "Java Honk!!!");
		StringWriter sw = new StringWriter();
		t.merge(vc, sw);		
		return sw.toString();		
		
	}

}
