use of freemarker.template.TemplateException in project ORCID-Source by ORCID.
the class SwaggerUIBuilder method buildSwaggerHTML.
/**
* Build the swagger UI HTML page
*
* @param baseUri
* the URL of the main website. e.g. http://orcid.org
* @param apiUri
* the URL of the API e.g. http://pub.orcid.org
* @param showOAuth
* if true, input boxes allowing user to enter client id and
* secret will be shown
* @return a 200 response containing the HTML as text.
*/
public Response buildSwaggerHTML(String baseUri, String apiUri, boolean showOAuth) {
final Map<String, Object> map = new HashMap<String, Object>();
map.put("swaggerJsonUrl", apiUri + OrcidApiConstants.SWAGGER_PATH + OrcidApiConstants.SWAGGER_FILE);
map.put("swaggerBaseUrl", baseUri + SWAGGER_STATIC_HTML_PATH);
map.put("showOAuth", showOAuth);
map.put("baseUri", baseUri);
map.put("apiUri", apiUri);
try {
Template template = freeMarkerConfiguration.getTemplate(SWAGGER_UI_FTL);
StringWriter result = new StringWriter();
template.process(map, result);
return Response.ok(result.toString()).build();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (TemplateException e) {
throw new RuntimeException(e);
}
}
use of freemarker.template.TemplateException in project ORCID-Source by ORCID.
the class TemplateManagerImpl method processTemplate.
@Override
public String processTemplate(String templateName, Map<String, Object> params, Locale locale) {
try {
Template template = freeMarkerConfiguration.getTemplate(templateName, locale);
StringWriter result = new StringWriter();
template.process(params, result);
return result.toString();
} catch (IOException e) {
throw new IllegalArgumentException(e);
} catch (TemplateException e) {
throw new IllegalArgumentException(e);
}
}
use of freemarker.template.TemplateException in project SpringStepByStep by JavaProgrammerLB.
the class FreemarkerTest method main.
public static void main(String[] args) {
Configuration config = new Configuration();
try {
String path = new File("").getAbsolutePath();
config.setDirectoryForTemplateLoading(new File(path));
Template template = config.getTemplate("src/test.ftl", "UTF-8");
// 创建数据模型
Map root = new HashMap();
List<User> users = new ArrayList<User>();
User u1 = new User();
u1.setId("123");
u1.setName("王五");
users.add(u1);
User u2 = new User();
u2.setId("423");
u2.setName("李四");
users.add(u2);
User u3 = new User();
u3.setId("333");
u3.setName("张三");
users.add(u3);
root.put("userList", users);
Map product = new HashMap();
root.put("lastProduct", product);
product.put("url", "www.baidu.com");
product.put("name", "green hose");
File file = new File(path + "\\src\\test.html");
if (!file.exists()) {
//System.out.println("file exist");
file.createNewFile();
}
Writer out = new BufferedWriter(new FileWriter(file));
template.process(root, out);
out.flush();
} catch (IOException e) {
e.printStackTrace();
} catch (TemplateException e) {
e.printStackTrace();
}
}
use of freemarker.template.TemplateException in project SpringStepByStep by JavaProgrammerLB.
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();
} catch (TemplateException e) {
throw new IllegalArgumentException();
}
}
use of freemarker.template.TemplateException in project asterixdb by apache.
the class GenerateFileMojo method execute.
@java.lang.Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {
init();
readExtraMaps();
addDependenciesToLicenseMap();
resolveLicenseContent();
resolveNoticeFiles();
resolveLicenseFiles();
rebuildLicenseContentProjectMap();
combineCommonGavs();
SourcePointerResolver.execute(this);
persistLicenseMap();
buildNoticeProjectMap();
generateFiles();
} catch (IOException | TemplateException | ProjectBuildingException e) {
throw new MojoExecutionException("Unexpected exception: " + e, e);
}
}
Aggregations