Search in sources :

Example 1 with BeansWrapper

use of freemarker.ext.beans.BeansWrapper in project zm-mailbox by Zimbra.

the class SoapApiChangeLog method writeChangelog.

private void writeChangelog() throws IOException, TemplateException {
    File templateDirFile = new File(templateDir, CHANGELOG_TEMPLATE_SUBDIR);
    Configuration config = new Configuration();
    config.setDirectoryForTemplateLoading(templateDirFile);
    config.setObjectWrapper(new BeansWrapper());
    fmTemplate = config.getTemplate(TEMPLATE_FILE);
    File of = new File(outputDir, OUTPUT_FILE);
    FileWriter out = new FileWriter(of);
    try {
        fmTemplate.process(changelogDataModel, out);
    } finally {
        try {
            out.close();
        } catch (Exception e) {
        // worst case scenario...clean-up quietly
        }
    }
}
Also used : Configuration(freemarker.template.Configuration) FileWriter(java.io.FileWriter) BeansWrapper(freemarker.ext.beans.BeansWrapper) File(java.io.File) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) JsonParseException(org.codehaus.jackson.JsonParseException) ParseException(org.apache.commons.cli.ParseException)

Example 2 with BeansWrapper

use of freemarker.ext.beans.BeansWrapper in project ninja by ninjaframework.

the class TemplateEngineFreemarkerI18nMethodTest method testThatConstraintViolationWorksWithDefault.

@Test
public void testThatConstraintViolationWorksWithDefault() throws Exception {
    Optional<Result> resultOptional = Optional.of(result);
    Mockito.when(messages.get(IsInteger.KEY, context, resultOptional)).thenReturn(Optional.empty());
    ConstraintViolation violation = new ConstraintViolation(IsInteger.KEY, "theField", IsInteger.MESSAGE);
    List args = new ArrayList();
    args.add(new StringModel(violation, new BeansWrapper()));
    TemplateModel returnValue = templateEngineFreemarkerI18nMethod.exec(args);
    assertThat(((SimpleScalar) returnValue).getAsString(), CoreMatchers.equalTo("theField must be an integer"));
    Mockito.verify(mockAppender, Mockito.never()).doAppend(Matchers.anyObject());
}
Also used : ConstraintViolation(ninja.validation.ConstraintViolation) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) StringModel(freemarker.ext.beans.StringModel) BeansWrapper(freemarker.ext.beans.BeansWrapper) TemplateModel(freemarker.template.TemplateModel) Result(ninja.Result) Test(org.junit.Test)

Example 3 with BeansWrapper

use of freemarker.ext.beans.BeansWrapper in project ninja by ninjaframework.

the class TemplateEngineFreemarkerI18nMethodTest method testThatConstraintViolationWorks.

@Test
public void testThatConstraintViolationWorks() throws Exception {
    Optional<Result> resultOptional = Optional.of(result);
    Mockito.when(messages.get(IsInteger.KEY, context, resultOptional)).thenReturn(Optional.of("This simulates the translated message!"));
    ConstraintViolation violation = new ConstraintViolation(IsInteger.KEY, "theField", IsInteger.MESSAGE);
    List args = new ArrayList();
    args.add(new StringModel(violation, new BeansWrapper()));
    TemplateModel returnValue = templateEngineFreemarkerI18nMethod.exec(args);
    assertThat(((SimpleScalar) returnValue).getAsString(), CoreMatchers.equalTo("This simulates the translated message!"));
    Mockito.verify(mockAppender, Mockito.never()).doAppend(Matchers.anyObject());
}
Also used : ConstraintViolation(ninja.validation.ConstraintViolation) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) StringModel(freemarker.ext.beans.StringModel) BeansWrapper(freemarker.ext.beans.BeansWrapper) TemplateModel(freemarker.template.TemplateModel) Result(ninja.Result) Test(org.junit.Test)

Example 4 with BeansWrapper

use of freemarker.ext.beans.BeansWrapper in project head by mifos.

the class DateFormatterTest method getFormatterArgs.

private List<Object> getFormatterArgs(Object date, Locale locale) throws TemplateModelException {
    BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
    List<Object> args = new ArrayList<Object>();
    args.add(wrapper.wrap(date));
    args.add(wrapper.wrap("MMMM"));
    args.add(wrapper.wrap(locale));
    return args;
}
Also used : ArrayList(java.util.ArrayList) BeansWrapper(freemarker.ext.beans.BeansWrapper)

Aggregations

BeansWrapper (freemarker.ext.beans.BeansWrapper)4 ArrayList (java.util.ArrayList)3 StringModel (freemarker.ext.beans.StringModel)2 TemplateModel (freemarker.template.TemplateModel)2 List (java.util.List)2 Result (ninja.Result)2 ConstraintViolation (ninja.validation.ConstraintViolation)2 Test (org.junit.Test)2 Configuration (freemarker.template.Configuration)1 TemplateException (freemarker.template.TemplateException)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 ParseException (org.apache.commons.cli.ParseException)1 JsonParseException (org.codehaus.jackson.JsonParseException)1 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)1