use of freemarker.template.Template in project head by mifos.
the class TallyXMLGenerator method getTallyXML.
public static String getTallyXML(List<AccountingDto> accountingData, String fileName) {
Template temp = getTemplate("master.template");
String masterData = "";
try {
List<TallyMessage> tallyMessages = TALLY_MESSAGE_GENERATOR.generateTallyMessages(accountingData);
masterData = getMasterData(tallyMessages, fileName);
} catch (Exception e) {
masterData = "Contact admin: There was an error encountered :";
masterData += e.getMessage();
return masterData;
}
/* Create a data-model */
Map<String, Object> root = new HashMap<String, Object>();
Map<String, Object> tallyMessage = new HashMap<String, Object>();
root.put("tallyMessage", tallyMessage);
tallyMessage.put("headOfficeName", "HEAD OFFICE");
tallyMessage.put("data", masterData);
StringWriter bow = new StringWriter();
process(temp, root, bow);
return bow.toString();
}
use of freemarker.template.Template in project head by mifos.
the class TallyXMLGenerator method getTallyMessageData.
private static String getTallyMessageData(TallyMessage tallyMessage, String fileName) {
Template temp = getTemplate("tally_mesage.template");
/* Create a data-model */
Map<String, Object> root = new HashMap<String, Object>();
Map<String, Object> voucher = new HashMap<String, Object>();
root.put("voucher", voucher);
voucher.put("type", tallyMessage.getVoucherType().getValue());
voucher.put("date", TallyMessageGenerator.DATE_FORMAT.format(tallyMessage.getVoucherDate()));
voucher.put("fileName", fileName);
voucher.put("data", getVoucherData(tallyMessage));
StringWriter bow = new StringWriter();
process(temp, root, bow);
return bow.toString() + "\n";
}
use of freemarker.template.Template in project spark by perwendel.
the class FreeMarkerTemplateEngine method render.
@Override
public String render(ModelAndView modelAndView) {
try {
StringWriter stringWriter = new StringWriter();
Template template = configuration.getTemplate(modelAndView.getViewName());
template.process(modelAndView.getModel(), stringWriter);
return stringWriter.toString();
} catch (IOException e) {
throw new IllegalArgumentException(e);
} catch (TemplateException e) {
throw new IllegalArgumentException(e);
}
}
use of freemarker.template.Template in project jforum2 by rafaelsteil.
the class InstallServlet method service.
/**
* @see javax.servlet.http.HttpServlet#service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
*/
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
try {
String encoding = SystemGlobals.getValue(ConfigKeys.ENCODING);
req.setCharacterEncoding(encoding);
// Request
RequestContext request = new WebRequestContext(req);
ResponseContext response = new WebResponseContext(res);
request.setCharacterEncoding(encoding);
JForumExecutionContext ex = JForumExecutionContext.get();
ForumContext forumContext = new JForumContext(request.getContextPath(), SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION), request, response, false);
ex.setForumContext(forumContext);
// Assigns the information to user's thread
JForumExecutionContext.set(ex);
// Context
SimpleHash context = JForumExecutionContext.getTemplateContext();
context.put("contextPath", req.getContextPath());
context.put("serverName", req.getServerName());
context.put("templateName", "default");
context.put("serverPort", Integer.toString(req.getServerPort()));
context.put("I18n", I18n.getInstance());
context.put("encoding", encoding);
context.put("extension", SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION));
context.put("JForumContext", forumContext);
context.put("version", SystemGlobals.getValue(ConfigKeys.VERSION));
if (SystemGlobals.getBoolValue(ConfigKeys.INSTALLED)) {
JForumExecutionContext.setRedirect(request.getContextPath() + "/forums/list" + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION));
} else {
// Module and Action
String moduleClass = ModulesRepository.getModuleClass(request.getModule());
context.put("moduleName", request.getModule());
context.put("action", request.getAction());
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(response.getOutputStream(), encoding));
try {
if (moduleClass != null) {
// Here we go, baby
Command c = (Command) Class.forName(moduleClass).newInstance();
Template template = c.process(request, response, context);
if (JForumExecutionContext.getRedirectTo() == null) {
response.setContentType("text/html; charset=" + encoding);
template.process(context, out);
out.flush();
}
}
} catch (Exception e) {
response.setContentType("text/html; charset=" + encoding);
if (out != null) {
new ExceptionWriter().handleExceptionData(e, out, request);
} else {
new ExceptionWriter().handleExceptionData(e, new BufferedWriter(new OutputStreamWriter(response.getOutputStream())), request);
}
}
}
String redirectTo = JForumExecutionContext.getRedirectTo();
if (redirectTo != null) {
response.sendRedirect(response.encodeRedirectURL(redirectTo));
}
} finally {
JForumExecutionContext.finish();
}
}
use of freemarker.template.Template in project jforum2 by rafaelsteil.
the class JForum method processCommand.
private Writer processCommand(Writer out, RequestContext request, ResponseContext response, String encoding, SimpleHash context, String moduleClass) throws Exception {
// Here we go, baby
Command c = this.retrieveCommand(moduleClass);
Template template = c.process(request, response, context);
if (JForumExecutionContext.getRedirectTo() == null) {
String contentType = JForumExecutionContext.getContentType();
if (contentType == null) {
contentType = "text/html; charset=" + encoding;
}
response.setContentType(contentType);
// manipulation
if (!JForumExecutionContext.isCustomContent()) {
out = new BufferedWriter(new OutputStreamWriter(response.getOutputStream(), encoding));
template.process(JForumExecutionContext.getTemplateContext(), out);
out.flush();
}
}
return out;
}
Aggregations