use of freemarker.template.Template in project jforum2 by rafaelsteil.
the class ExceptionWriter method handleExceptionData.
public void handleExceptionData(Throwable t, Writer w, RequestContext request) {
StringWriter strWriter = new StringWriter();
PrintWriter writer = new PrintWriter(strWriter);
t.printStackTrace(writer);
String currentUrl = this.extractCurrentUrl(request);
writer.write(currentUrl);
writer.close();
try {
logger.error(strWriter);
String message = "";
Throwable cause = t.getCause();
while (cause != null) {
message = cause.toString();
cause = cause.getCause();
}
if (message == null || message.equals("")) {
message = t.getMessage();
}
if (message == null || message.equals("")) {
message = t.toString();
}
boolean canViewStackTrace = !SystemGlobals.getBoolValue(ConfigKeys.STACKTRACE_MODERATORS_ONLY) || (SessionFacade.isLogged() && SessionFacade.getUserSession().isModerator());
String filter = "[<>]";
String stackTrace = canViewStackTrace ? strWriter.toString() : "Only moderators can view stack trace.";
stackTrace = stackTrace.replaceAll(filter, "");
message = message.replaceAll(filter, "");
SimpleHash templateContext = JForumExecutionContext.getTemplateContext();
templateContext.put("stackTrace", stackTrace);
templateContext.put("message", message);
Template template = JForumExecutionContext.templateConfig().getTemplate("exception.html");
template.process(templateContext, w);
} catch (Exception e) {
strWriter = new StringWriter();
writer = new PrintWriter(strWriter);
e.printStackTrace(writer);
writer.close();
logger.error(strWriter);
}
}
use of freemarker.template.Template in project spring-framework by spring-projects.
the class FreeMarkerMacroTests method testExposeSpringMacroHelpers.
@Test
public void testExposeSpringMacroHelpers() throws Exception {
FreeMarkerView fv = new FreeMarkerView() {
@Override
@SuppressWarnings("rawtypes")
protected void processTemplate(Template template, SimpleHash fmModel, HttpServletResponse response) throws TemplateException {
Map model = fmModel.toMap();
assertTrue(model.get(FreeMarkerView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE) instanceof RequestContext);
RequestContext rc = (RequestContext) model.get(FreeMarkerView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE);
BindStatus status = rc.getBindStatus("tb.name");
assertEquals("name", status.getExpression());
assertEquals("juergen", status.getValue());
}
};
fv.setUrl(TEMPLATE_FILE);
fv.setApplicationContext(wac);
fv.setExposeSpringMacroHelpers(true);
Map<String, Object> model = new HashMap<>();
model.put("tb", new TestBean("juergen", 99));
fv.render(model, request, response);
}
use of freemarker.template.Template in project camel by apache.
the class SpringBootStarterMojo method getTemplate.
private Template getTemplate(String name) throws IOException {
Configuration cfg = new Configuration(Configuration.getVersion());
cfg.setTemplateLoader(new URLTemplateLoader() {
@Override
protected URL getURL(String name) {
return SpringBootStarterMojo.class.getResource("/" + name);
}
});
cfg.setDefaultEncoding("UTF-8");
Template template = cfg.getTemplate(name);
return template;
}
use of freemarker.template.Template in project camel by apache.
the class SpringBootStarterMojo method createBasePomFromScratch.
private Document createBasePomFromScratch() throws Exception {
getLog().info("Creating a new pom.xml for the starter from scratch");
Template pomTemplate = getTemplate("spring-boot-starter-template-pom.template");
Map<String, String> props = new HashMap<>();
props.put("version", project.getVersion());
props.put("componentId", getComponentId());
props.put("componentName", project.getName());
props.put("componentDescription", project.getDescription());
StringWriter sw = new StringWriter();
pomTemplate.process(props, sw);
String xml = sw.toString();
ByteArrayInputStream bin = new ByteArrayInputStream(xml.getBytes("UTF-8"));
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document pom = builder.parse(bin);
return pom;
}
use of freemarker.template.Template in project camel by apache.
the class SpringBootStarterMojo method writeSpringProvides.
private void writeSpringProvides() throws IOException, TemplateException {
Template fileTemplate = getTemplate("spring-boot-starter-template-spring.provides");
Map<String, String> props = new HashMap<>();
props.put("artifactId", project.getArtifactId());
File outDir = new File(starterDir(), "src/main/resources/META-INF");
outDir.mkdirs();
File outFile = new File(outDir, "spring.provides");
StringWriter sw = new StringWriter();
fileTemplate.process(props, sw);
sw.close();
writeIfChanged(sw.toString(), outFile);
}
Aggregations