Search in sources :

Example 11 with TemplateException

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);
    }
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) Template(freemarker.template.Template)

Example 12 with TemplateException

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);
    }
}
Also used : StringWriter(java.io.StringWriter) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) Template(freemarker.template.Template)

Example 13 with TemplateException

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();
    }
}
Also used : Configuration(freemarker.template.Configuration) HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Template(freemarker.template.Template) BufferedWriter(java.io.BufferedWriter) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 14 with TemplateException

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();
    }
}
Also used : StringWriter(java.io.StringWriter) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) Template(freemarker.template.Template)

Example 15 with TemplateException

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);
    }
}
Also used : ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException)

Aggregations

TemplateException (freemarker.template.TemplateException)43 IOException (java.io.IOException)38 Template (freemarker.template.Template)21 HashMap (java.util.HashMap)19 Writer (java.io.Writer)15 StringWriter (java.io.StringWriter)13 Configuration (freemarker.template.Configuration)8 Map (java.util.Map)8 WriterRepresentation (org.restlet.representation.WriterRepresentation)6 File (java.io.File)5 OutputStreamWriter (java.io.OutputStreamWriter)4 MediaType (org.restlet.data.MediaType)4 Representation (org.restlet.representation.Representation)4 DefaultObjectWrapper (freemarker.template.DefaultObjectWrapper)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileWriter (java.io.FileWriter)3 StringRepresentation (org.restlet.representation.StringRepresentation)3 ParseException (freemarker.core.ParseException)2 SimpleHash (freemarker.template.SimpleHash)2 BufferedWriter (java.io.BufferedWriter)2