<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Technotrance, Illusions and Perspectives &#187; freemarker</title>
	<atom:link href="http://myblog.shriharisc.com/tag/freemarker/feed/" rel="self" type="application/rss+xml" />
	<link>http://myblog.shriharisc.com</link>
	<description>A dose of everyday bruises with Java/JEE</description>
	<lastBuildDate>Mon, 02 Aug 2010 17:45:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using FreemarkerServlet in Google Guice to inject Configuration</title>
		<link>http://myblog.shriharisc.com/2009/09/05/using-freemarkerservlet-in-google-guice-to-inject-configuration/</link>
		<comments>http://myblog.shriharisc.com/2009/09/05/using-freemarkerservlet-in-google-guice-to-inject-configuration/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 19:01:01 +0000</pubDate>
		<dc:creator>Shrihari</dc:creator>
				<category><![CDATA[jee-light]]></category>
		<category><![CDATA[freemarker]]></category>
		<category><![CDATA[google-guice]]></category>

		<guid isPermaLink="false">http://schakrap.wordpress.com/?p=95</guid>
		<description><![CDATA[Freemarker is a fantastic template parsing framework , and has its own avantages over Apache Velocity.  Google Guice is a straightforward injection framework which injects abstraction-driven ,instance-driven, or annotation driven module classes using bindings.  In order 2 get the best of both these frameworks, the following snippet would aid in doing so.
1) Modify the WEB-INF/web.xml [...]]]></description>
			<content:encoded><![CDATA[<p>Freemarker is a fantastic template parsing framework , and has its own avantages over Apache Velocity.  Google Guice is a straightforward injection framework which injects abstraction-driven ,instance-driven, or annotation driven module classes using bindings.  In order 2 get the best of both these frameworks, the following snippet would aid in doing so.</p>
<p>1) Modify the WEB-INF/web.xml to define FreemarkerServlet</p>
<pre class="brush: xml">
&lt;servlet&gt;
 &lt;servlet-name&gt;freemarker&lt;/servlet-name&gt;
 &lt;servlet-class&gt;com.ts.guicefmkr.web.TemplateServlet&lt;/servlet-class&gt;
 &lt;init-param&gt;
 &lt;param-name&gt;TemplatePath&lt;/param-name&gt;
 &lt;param-value&gt;/WEB-INF/ftl&lt;/param-value&gt;
 &lt;/init-param&gt;
 &lt;init-param&gt;
 &lt;param-name&gt;NoCache&lt;/param-name&gt;
 &lt;param-value&gt;true&lt;/param-value&gt;
 &lt;/init-param&gt;
 &lt;init-param&gt;
 &lt;param-name&gt;ContentType&lt;/param-name&gt;
 &lt;param-value&gt;text/html&lt;/param-value&gt;
 &lt;/init-param&gt;
 &lt;init-param&gt;
 &lt;param-name&gt;template_update_delay&lt;/param-name&gt;
 &lt;param-value&gt;0&lt;/param-value&gt;
 &lt;/init-param&gt;
 &lt;init-param&gt;
 &lt;param-name&gt;default_encoding&lt;/param-name&gt;
 &lt;param-value&gt;ISO-8859-1&lt;/param-value&gt;
 &lt;/init-param&gt;
 &lt;init-param&gt;
 &lt;param-name&gt;number_format&lt;/param-name&gt;
 &lt;param-value&gt;0.##########&lt;/param-value&gt;
 &lt;/init-param&gt;
 &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
 &lt;/servlet&gt;
</pre>
<p>2) Extend the FreemarkerServlet and implement to Guice&#8217;s Module to bind the created  Configuration object</p>
<pre class="brush: java">
import com.google.inject.Binder;
import com.google.inject.Injector;
import com.google.inject.Module;
import javax.servlet.ServletException;

import freemarker.ext.servlet.FreemarkerServlet;
import freemarker.template.Configuration;
public class TemplateServlet extends FreemarkerServlet implements Module
{   private Configuration templateConfig;
    public Configuration getTemplateConfig()
    {      return templateConfig;
    }

     public void setTemplateConfig(Configuration templateConfig) {
        this.templateConfig = templateConfig;
     }

    public void init() throws ServletException
     {   super.init();
         templateConfig = getConfiguration();
        Injector injector = com.google.inject.Guice.createInjector(this);
       }

      public void configure(Binder binder)
     {   binder.bind(Configuration.class).toInstance(templateConfig);
     }
}
</pre>
<p>Thus you could use Configuration object anywhere in your application using @Inject from Guice.</p>
]]></content:encoded>
			<wfw:commentRss>http://myblog.shriharisc.com/2009/09/05/using-freemarkerservlet-in-google-guice-to-inject-configuration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
