Pages

Saturday, 16 March 2019

Creating you own TriFunction Interface in Java 8

Create your own TriFunctional Interface.


This Idea generally came when I was working with travel Domain Company, I used to have a lot of webservces to be merged into one which was nothing but output of the product.

So I have to comeup with API and Java 8 was into boom. and somehow I decided to extend a BiFunction and make my own TriFunction Interface.

@FunctionalInterface
public interface  TriFunction<W1,W2,WR> {
     /*
      * An Api method which will be used fro merginng two webservices and create new one
     */
    WR join(W1 w1, W2 w2);
}

Above example is just a short starter one which can be used in various APIS.

Wednesday, 18 June 2014

Some features of Java 8.

Some Java 8 features.

Although the java has launched its new version Java 8 with various new features, some of them are as. Because of this release there will be a drastic change in the way of coding using Lambda expressions, Streams, default interfaces, etc.

  • Streams.
  • Functional Interfaces.
  • Lambda.
  • Java Time API.
  • Accumulators.

Streams


Streams are not the streams you are thinking about (InputStream, OutputStream) this stream is all about collections, well this stream is not for replacing the List, ArrayList or any collection. There are generally two types of stream in the collections.
  1. Sequential Stream.
  2. Parallel Stream.
Sequential Stream: - When the stream is traversed sequentially it traverses one by one.

Example:-

List<Address> addresses = list.getStream.collect(Collectors.toList());



Parallel Stream: - When the stream is traversed parallely it breaks into many parts and then gets traversed and each of which is processed individually on a different thread. The results are consolidated output is formed.

Example:-

List<Address> addresses = list.getStream.parallel().collect(Collectors.toList());

Functional Interfaces

The interface which has default method, which can give a default behaviour, which can give a default functionality, this type of interfaces are the functional interface.

Functional interface cannot have more than one abstract method but it can have more than one default methods. Default methods are introduced in Java 8, to add new methods to interface without disturbing the implemented classes.

Example:-

interface FunctionalInterface{
  void show();
  default void display(){
     System.out.println("Default method in functional interface can have body..!");
  }

}

Lambda

Lambda expression is nothing but a method without any declaration, access modifiers, return value and name. It’s a kind of expression which is unspecified function. By the use of this we can directly write the logic without extracting as a method that saves our effort.

Lambda expression looks like:-

(Argument) -> {Body}
(Type argument1, Type argument2...) -> {Body}

Examples:-

(Integer x, Integer y) -> {return x * Y;}

(String s) -> {System.out.println(s);}


Java Time API


Well Java date and Time API is very old and it is continuously getting developed. Finally replacing the confusing, slow, and difficult Date and Calendar APIs. Although all the java Time classes are immutable and thread safe. They are based on the ISO 8601 calendar system, the de facto world calendar following the proleptic Gregorian rules

This time with use of Java Time API packages it will be quite easy. Though it contains some sub-packages java.time.format that provides classes to print and parse dates and times and java.time.zone provides support for time-zones and their rules.
The new Time API prefers enums over integer constants for months and days of the week. One of the useful class is DateTimeFormatter for converting datetime objects to strings

Accumulators

An accumulator is a variable that the program uses to calculate a sum or product of a series of values. Accumulator variable is used to maintain a single count, sum... which is updated by many threads. Therefore some new classes were generated for it.

·         DoubleAccumulator
·         DoubleAdder
·         LongAccumulator
·         LongAdder

Generally these classes are used when the variable is to accessed by many threads.
Both the DoubleAdder and LongAdder classes can be seen as specific subsets of the DoubleAccumulator and LongAccumulator functionality.

The call new DoubleAdder() is equivalent to
new DoubleAccumulator((x, y) -> x + y, 0.0).
The call new LongAdder() is equivalent to
new LongAccumulator((x, y) -> x + y, 0L).

Example:-

DoubleAccumulator da = new DoubleAccumulator((x,y) -> x + y, 0.0);
List<Double> doubles = Arrays.asList(1.0, 2.0, 3.0, 4.0, 10.0);
doubles.forEach(da::accumulate);

System.out.println("Result: " + da.doubleValue());

Result:-
Result: 24

LongAdder la = new LongAdder();
List<long> longs = Arrays.asList(10, 20, 30, 40, 100);
longs.forEach(la::accumulate);

System.out.println("Result: " + la.longValue());

Result:-

Result: 200

Thursday, 10 April 2014

Logging in a clustered environment using Log4j

Logging using Socket Appender.

The logs should be stored in a centralized machine or sever when the application is stored in a clustered environment. Let’s get a scenario where every information level of logs goes in a clustered machine and error level log go in a server or centralized machine. So every cluster will have an information level log and if an error occurs it will show in a centralized machine.


There are four classes (Class1, Class2, Class3, Class4) these classes behave as a clustered application and ClassMain which contain the main method behave as a manager of this cluster. This cluster means class 1 2 3 4 will store the info level logs through RolingFileAppender, show the message in the console using ConsoleAppender and send the error level logs to a centralized machine using SocketAppender.

log4j.xml is the file which is defined in the application; every cluster will have the same property file and log4j-server.xml will be deployed in a centralized machine.

The command for starting socket server:-

java -classpath {Jar Path}\jars\log4j-1.2.17.jar org.apache.log4j.net.SimpleSocketServer
4712 {property file path}\log4j-server.properties 

package com.sun.log.a;
import org.apache.log4j.Logger;
import com.sun.log.main.ClassMain;
/**
* Class1 containing log method which calls log method of main class.
*
* @author Suraj Bhambhani
*
*/
public class Class1 {
static Logger logger = Logger.getLogger("Class1");
/**
* Create logs for Class1 logger
*
* @return Logger
*/
public static Logger Log() {
ClassMain.log(logger);
return logger;
}
}
view raw Class1 hosted with ❤ by GitHub
package com.sun.log.a;
import org.apache.log4j.Logger;
import com.sun.log.main.ClassMain;
/**
* Class2 containing log method which calls log method of main class.
*
* @author Suraj Bhambhani
*
*/
public class Class2 {
static Logger logger = Logger.getLogger("Class2");
/**
* Create logs for Class1 logger
*
* @return Logger
*/
public static Logger Log() {
ClassMain.log(logger);
return logger;
}
}
view raw Class2 hosted with ❤ by GitHub
package com.sun.log.b;
import org.apache.log4j.Logger;
import com.sun.log.main.ClassMain;
/**
* Class3 containing log method which calls log method of main class.
*
* @author Suraj Bhambhani
*
*/
public class Class3 {
static Logger logger = Logger.getLogger("Class3");
/**
* Create logs for Class3 logger
*
* @return Logger
*/
public static Logger Log() {
ClassMain.log(logger);
return logger;
}
}
view raw Class3 hosted with ❤ by GitHub
package com.sun.log.b;
import org.apache.log4j.Logger;
import com.sun.log.main.ClassMain;
/**
* Class4 containing log method which calls log method of main class.
*
* @author Suraj Bhambhani
*
*/
public class Class4 {
static Logger logger = Logger.getLogger("Class4");
/**
* Create logs for Class4 logger
*
* @return Logger
*/
public static Logger Log() {
ClassMain.log(logger);
return logger;
}
}
view raw Class4 hosted with ❤ by GitHub
package com.sun.log.main;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.log4j.Logger;
import com.sun.log.a.Class1;
import com.sun.log.a.Class2;
import com.sun.log.b.Class3;
import com.sun.log.b.Class4;
/**
* ClassMain containing main method which calls all classes logs.
*
* @author Suraj Bhambhani
*
*/
public class ClassMain {
static SimpleDateFormat sd = new SimpleDateFormat("HH:mm:ss.SSS");
static Logger logger = Logger.getLogger(ClassMain.class);
/**
* Iterating to get all logs from the classes
*
* @param args
*/
public static void main(String[] args) {
for (int i = 0; i < 20; i++) {
Class1.Log();
Class2.Log();
Class3.Log();
Class4.Log();
}
}
/**
* Generic log method which log.
*
* @param logger
*/
public static void log(Logger logger) {
logger.error(logger.getName() + " Type Error "
+ sd.format(new Date()).toString());
logger.info(logger.getName() + " Type Info "
+ sd.format(new Date()).toString());
logger.trace(logger.getName() + " Type Trace "
+ sd.format(new Date()).toString());
logger.warn(logger.getName() + " Type Warn "
+ sd.format(new Date()).toString());
}
}
view raw ClassMain hosted with ❤ by GitHub
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true"
xmlns:log4j='http://jakarta.apache.org/log4j/'>
<!--Socket appender for sending the logs to remote machine -->
<appender name="socketAppender" class="org.apache.log4j.net.SocketAppender">
<param name="Port" value="4712" />
<param name="RemoteHost" value="localhost" />
<param name="ReconnectionDelay" value="60000" />
</appender>
<!-- Console appender to print the logs in remote machine console -->
<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p [%d] [%t] %c %m%n" />
</layout>
</appender>
<!-- Generate a file using rolling file appender of a particular logger -->
<appender name="fileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="Threshold" value="ALL" />
<param name="append" value="true" />
<param name="file" value="/Log/Local.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p [%d] [%t] %c %m%n" />
</layout>
</appender>
<!-- Sending the logs to the server machine by using socket appender -->
<logger name="Class1" additivity="false">
<level value="ERROR" />
<appender-ref ref="socketAppender" />
</logger>
<logger name="Class2" additivity="false">
<level value="ERROR" />
<appender-ref ref="socketAppender" />
</logger>
<!-- Root for defining the root work which is to be happened like console
appender will work for everything -->
<root>
<appender-ref ref="consoleAppender" />
<appender-ref ref="fileAppender" />
</root>
</log4j:configuration>
view raw log4j hosted with ❤ by GitHub
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true"
xmlns:log4j='http://jakarta.apache.org/log4j/'>
<!-- Console appender to print the logs in remote machine console -->
<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p [%d] [%t] %c %m%n" />
</layout>
</appender>
<!-- Generate a file using rolling file appender of a particular logger -->
<appender name="fileAppender1" class="org.apache.log4j.RollingFileAppender">
<param name="Threshold" value="ALL" />
<param name="file" value="/Log/Desk1.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p [%d] [%t] %c %m%n" />
</layout>
</appender>
<appender name="fileAppender2" class="org.apache.log4j.RollingFileAppender">
<param name="Threshold" value="ALL" />
<param name="file" value="/Log/Desk2.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p [%d] [%t] %c %m%n" />
</layout>
</appender>
<!-- Catch the logs sent by a socket appender and perform the operation
by calling the appropriate appender -->
<logger name="Class1" additivity="false">
<appender-ref ref="fileAppender1" />
</logger>
<logger name="Class2" additivity="false">
<appender-ref ref="fileAppender2" />
</logger>
<!-- Root for defining the root work which is to be happened like console
appender will work for everything -->
<root>
<appender-ref ref="consoleAppender" />
</root>
</log4j:configuration>
view raw log4j-server hosted with ❤ by GitHub
References

Saturday, 1 March 2014

Steps for installation of Windows 2008 R2 Server

Installation of Windows 2008 R2 Server

  • Insert the appropriate Windows Server 2008 installation media into your DVD drive and reboot the computer and complete installation process.

  • When prompted for an installation language and other regional options, make your selection and press Next.

  • Next. press Install Now to begin the installation process.

  • Enter your Product ID in the next window, click Next.

  • Select the Full version of the right Windows version you're prompted, and click Next.

  • Read and accept the license terms by clicking to select the checkbox and pressing Next.

  • In the "Which type of installation do you want? " window, click the only available option –Custom (Advanced).

  • In the "Where do you want to install Windows?", if you're installing the server on a regular IDE hard disk, click to select the first disk, usually Disk 0, and click Next.

  • The installation process will reboot your computer, so make sure you remove it before going to lunch.
  • Once the install is finished, we’re prompted to change our password before logging in.

  • Windows requires that you have a strong password, seven characters long with atleast three of the four following: uppercase letter, lowercase letter, numeral, or symbol. You’ll want to make sure you write it down somewhere for now, because if you forget it later, the entire install will have to be re-done.

  • Finished! That’s all there is to doing a base install of Windows Server 2008 R2.

Friday, 4 October 2013

Example of mail merge generating multiple files.

Example of mail merge (Dependency Example) generating different files using RTFTemplate library.


  • Add required JARS in class path.
  •  Required JARS:  
       
     rtftemplate-1.0.1-b14.jar  
     commons-collections-3.2.1.jar  
     spring-beans-3.2.2.RELEASE.jar  
     spring-context-3.2.2.RELEASE.jar  
     spring-context-support-3.2.2.RELEASE.jar  
     spring-core-3.2.2.RELEASE.jar  
     spring-expression-3.2.2.RELEASE.jar  
     spring-jdbc-3.2.2.RELEASE.jar  
     spring-orm-3.2.2.RELEASE.jar  
     spring-tx-3.2.2.RELEASE.jar  
     xml-apis-1.0.b2.jar  
     commons-logging-1.1.1.jar  
     freemarker.jar  
     commons-digester-2.1.jar  
     org.apache.commons.beanutils.jar  
     velocity-1.7.jar  
     commons-lang.jar  
    
package com.rtf.impl;
public class Dependency {
private String artifactID;
private String type;
private String version;
private String url;
public Dependency(String artifactID, String type, String version, String url) {
this.artifactID = artifactID;
this.type = type;
this.version = version;
this.url = url;
}
public String getArtifactID() {
return artifactID;
}
public void setArtifactID(String artifactID) {
this.artifactID = artifactID;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
}
view raw Dependency hosted with ❤ by GitHub
package com.rtf.impl;
import java.util.ArrayList;
import java.util.Collection;
public class Developer {
private String name;
private String email;
private Collection<Role> roles;
private Manager manager;
public Developer(String name, String email) {
this.name = name;
this.email = email;
roles = new ArrayList<Role>();
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Collection<Role> getRoles() {
return roles;
}
public void setRoles(Collection<Role> roles) {
this.roles = roles;
}
public void addRole(Role role) {
roles.add(role);
}
public void addRole(String roleName) {
addRole(new Role(roleName));
}
public Manager getManager() {
return manager;
}
public void setManager(Manager manager) {
this.manager = manager;
}
}
view raw Developer hosted with ❤ by GitHub
package com.rtf.impl;
public class DeveloperGroup {
private Developer developer1;
private Developer developer2;
private Developer developer3;
public DeveloperGroup(Developer developer1, Developer developer2,
Developer developer3) {
this.developer1 = developer1;
this.developer2 = developer2;
this.developer3 = developer3;
}
public Developer getDeveloper1() {
return developer1;
}
public void setDeveloper1(Developer developer1) {
this.developer1 = developer1;
}
public Developer getDeveloper2() {
return developer2;
}
public void setDeveloper2(Developer developer2) {
this.developer2 = developer2;
}
public Developer getDeveloper3() {
return developer3;
}
public void setDeveloper3(Developer developer3) {
this.developer3 = developer3;
}
}
view raw DeveloperGroup hosted with ❤ by GitHub
package com.rtf.impl;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.rtf.RTFTemplate;
import net.sourceforge.rtf.helper.RTFTemplateBuilder;
/**
* This class is to generate a multiple file with there different addresses
* using RTF Template.
*
* @author Suraj Bhambhani
*
*/
public class GenerateMultipleRTFFiles {
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
// Source of file to be generated.
String rtfSource = "src/RTF_Websites.rtf";
// 1. Get default RTFtemplateBuilder
RTFTemplateBuilder builder = RTFTemplateBuilder.newRTFTemplateBuilder();
// 2. Get RTFtemplate with default Implementation of template engine
RTFTemplate rtfTemplate = builder.newRTFTemplate();
// 3. Set the RTF model source
rtfTemplate.setTemplate(new File(rtfSource));
// List of Projects
List<Project> projects = new ArrayList<Project>();
// Project with one website, website2 exists.
Project project1 = new Project("Be Open Source", "Suraj Bhambhani",
"OutOfMemory", "", "www.scart.com");
// Project with two website.
Project project2 = new Project("Be Open Source", "Suraj Bhambhani",
"OutOfMemory", "www.liveinSF.com", "www.liveinNJ.com");
// Project with one website, website1 exists.
Project project3 = new Project("Be Open Source", "Suraj Bhambhani",
"OutOfMemory", "www.workwithme.com", "");
// Project with one website, website1 exists.
Project project4 = new Project("Be Open Source", "Suraj Bhambhani",
"OutOfMemory", "www.workinSF.com", "www.workinNJ.com");
projects.add(project1);
projects.add(project2);
projects.add(project3);
projects.add(project4);
rtfTemplate.put("header_developer_name", "Name");
rtfTemplate.put("header_developer_email", "Email");
rtfTemplate.put("header_developer_roles", "Roles");
// Dependencies
List<Dependency> dependencies = new ArrayList<Dependency>();
Dependency dependency = new Dependency("commons-collection", "jar",
"1.0", "http://jakarta.apache.org/commons/collection/");
dependencies.add(dependency);
rtfTemplate.put("dependencies", dependencies);
// List of developers.
List<Developer> developers = new ArrayList<Developer>();
Developer developer;
developer = new Developer("Will Glass-Husain", "wglass@apache.org");
developer.addRole("Java Developer");
developer.addRole("Manager");
rtfTemplate.put("developers", developers);
developers.add(developer);
developer = new Developer("Ma-Husain", "wglass@apache.org");
developer.addRole("Java Developer");
developer.addRole("Manager");
developers.add(developer);
// Iterating over projects and generating files accordingly.
for (Project projectIterate : projects) {
// When both wesite exists.
if (!projectIterate.getWebsite1().equals("")
&& !projectIterate.getWebsite2().equals("")) {
withTwoWebsites(rtfTemplate, projectIterate);
withTwoWebsites(rtfTemplate, projectIterate);
}
// When Website2 exists and website1 not.
if (projectIterate.getWebsite1().equals("")
&& !projectIterate.getWebsite2().equals("")) {
withWebsite2(rtfTemplate, projectIterate);
}
// When Website1 exists and website2 not.
if (!projectIterate.getWebsite1().equals("")
&& projectIterate.getWebsite2().equals("")) {
withWebsite1(rtfTemplate, projectIterate);
}
System.out.println(projectIterate.getWebsite1());
System.out.println(projectIterate.getWebsite2());
}
}
private static void withWebsite1(RTFTemplate rtfTemplate,
Project projectIterate) throws Exception {
String name;
name = projectIterate.getWebsite1();
generateFile(rtfTemplate, projectIterate, name);
}
private static void withWebsite2(RTFTemplate rtfTemplate,
Project projectIterate) throws Exception {
String name;
projectIterate.setWebsite1(projectIterate.getWebsite2());
name = projectIterate.getWebsite2();
generateFile(rtfTemplate, projectIterate, name);
}
private static void generateFile(RTFTemplate rtfTemplate,
Project projectIterate, String name) throws Exception {
// 4. Put the context.
rtfTemplate.put("project", projectIterate);
String rtfTarget = "Project_" + name + ".rtf";
// 5. Merge the RTF source model and the context
rtfTemplate.merge(rtfTarget);
}
private static void withTwoWebsites(RTFTemplate rtfTemplate,
Project projectIterate) throws Exception {
String name;
boolean websiteCheck = true;
int websitBreak = 0;
// When two website exist.
while (true) {
name = projectIterate.getWebsite1();
if (websiteCheck == false) {
projectIterate.setWebsite1(projectIterate.getWebsite2());
name = projectIterate.getWebsite2();
}
generateFile(rtfTemplate, projectIterate, name);
websitBreak++;
websiteCheck = false;
if (websitBreak == 2)
break;
}
}
}
package com.rtf.impl;
import java.util.ArrayList;
import java.util.List;
public class Manager {
private List<Project> projects;
public Manager(String name) {
this.name = name;
this.projects = new ArrayList<Project>();
}
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void addProject(Project project) {
projects.add(project);
}
public List<Project> getProjects() {
return projects;
}
}
view raw Manager hosted with ❤ by GitHub
package com.rtf.impl;
import java.io.InputStream;
import java.util.List;
public class Project {
private String name;
private InputStream logo = null;
private String clientName;
private String error;
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
private String website1;
private String website2;
public String getWebsite2() {
return website2;
}
public void setWebsite2(String website1) {
this.website2 = website1;
}
public String getWebsite1() {
return website1;
}
public void setWebsite1(String website) {
this.website1 = website;
}
public String getClientName() {
return clientName;
}
public void setClientName(String clientName) {
this.clientName = clientName;
}
public Project(String name, String clientName, String error,
String website, String website1) {
this.name = name;
this.clientName = clientName;
this.error = error;
this.website1 = website;
this.website2 = website1;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setLogo(InputStream logo) {
this.logo = logo;
}
public InputStream getLogo() {
return logo;
}
private List<Project> group;
public List<Project> getGroup() {
return group;
}
public void addProject(Project project) {
group.add(project);
}
}
view raw Project hosted with ❤ by GitHub
package com.rtf.impl;
public class Role {
private String name;
public Role(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
view raw Role hosted with ❤ by GitHub
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- **********************************************************************
********************* RTFTEMPLTE IMPLEMENTATION *********************
********************************************************************** -->
<!-- Defautlt RTFTemplate implementation with freemarker template engine -->
<bean id="ftlRTFTemplate"
class="net.sourceforge.rtf.RTFTemplate"
singleton="false" >
<property name="parser" ref="defaultRTFParser" />
<property name="transformer" ref="ftlTransformer" />
<property name="templateEngine" ref="ftl" />
</bean>
<!-- Defautlt RTFTemplate implementation with velocity template engine -->
<bean id="vmRTFTemplate"
class="net.sourceforge.rtf.RTFTemplate"
singleton="false" >
<property name="parser" ref="defaultRTFParser" />
<property name="transformer" ref="vmTransformer" />
<property name="templateEngine" ref="vm" />
</bean>
<!-- **********************************************************************
********************* RTFDOCUMENT PARSER *********************
********************************************************************** -->
<!-- Defautlt RTFDocument Parser -->
<bean id="defaultRTFParser"
class="net.sourceforge.rtf.handler.RTFDocumentHandler"
singleton="true" >
</bean>
<!-- **********************************************************************
********************* FREEMARKER TEMPLATE ENGINE *********************
********************************************************************** -->
<!-- Freemarker template engine -->
<bean id="ftl"
class="net.sourceforge.rtf.template.freemarker.FreemarkerTemplateEngineImpl"
singleton="false" >
<property name="freemarkerConfiguration" ref="ftlConfiguration" />
</bean>
<!-- Freemarker Configuration -->
<bean id="ftlConfiguration"
class="freemarker.template.Configuration"
singleton="true" >
</bean>
<!-- Freemarker RTF Document Transformer -->
<bean id="ftlTransformer"
class="net.sourceforge.rtf.template.freemarker.RTFFreemarkerTransformerImpl"
singleton="true" >
</bean>
<!-- **********************************************************************
********************* VELOCITY TEMPLATE ENGINE *********************
********************************************************************** -->
<bean id="vm"
class="net.sourceforge.rtf.template.velocity.VelocityTemplateEngineImpl"
singleton="false" >
<property name="velocityEngine" ref="vmEngine" />
</bean>
<!-- VelocityEngine Configuration -->
<bean id="vmEngine"
class="org.apache.velocity.app.VelocityEngine"
singleton="true" >
</bean>
<!-- Velocity RTF Document Transformer -->
<bean id="vmTransformer"
class="net.sourceforge.rtf.template.velocity.RTFVelocityTransformerImpl"
singleton="true" >
</bean>
</beans>


References:-
http://sourceforge.net/projects/rtftemplate/

http://rtftemplate.sourceforge.net/