Search in sources :

Example 1 with TemplateNumberFormatFactory

use of freemarker.core.TemplateNumberFormatFactory in project freemarker by apache.

the class CustomFormatsExample method aliases2.

@Test
public void aliases2() throws IOException, TemplateException {
    Configuration cfg = getConfiguration();
    Map<String, TemplateNumberFormatFactory> customNumberFormats = new HashMap<String, TemplateNumberFormatFactory>();
    customNumberFormats.put("base", BaseNTemplateNumberFormatFactory.INSTANCE);
    customNumberFormats.put("oct", new AliasTemplateNumberFormatFactory("@base 8"));
    cfg.setCustomNumberFormats(customNumberFormats);
    assertOutputForNamed("CustomFormatsExample-alias2.ftlh");
}
Also used : AliasTemplateNumberFormatFactory(freemarker.core.AliasTemplateNumberFormatFactory) Configuration(freemarker.template.Configuration) HashMap(java.util.HashMap) BaseNTemplateNumberFormatFactory(freemarker.core.BaseNTemplateNumberFormatFactory) TemplateNumberFormatFactory(freemarker.core.TemplateNumberFormatFactory) AliasTemplateNumberFormatFactory(freemarker.core.AliasTemplateNumberFormatFactory) Test(org.junit.Test)

Example 2 with TemplateNumberFormatFactory

use of freemarker.core.TemplateNumberFormatFactory in project freemarker by apache.

the class CustomFormatsExample method aliases1.

@Test
public void aliases1() throws IOException, TemplateException {
    Configuration cfg = getConfiguration();
    Map<String, TemplateNumberFormatFactory> customNumberFormats = new HashMap<String, TemplateNumberFormatFactory>();
    customNumberFormats.put("price", new AliasTemplateNumberFormatFactory(",000.00"));
    customNumberFormats.put("weight", new AliasTemplateNumberFormatFactory("0.##;; roundingMode=halfUp"));
    cfg.setCustomNumberFormats(customNumberFormats);
    Map<String, TemplateDateFormatFactory> customDateFormats = new HashMap<String, TemplateDateFormatFactory>();
    customDateFormats.put("fileDate", new AliasTemplateDateFormatFactory("dd/MMM/yy hh:mm a"));
    customDateFormats.put("logEventTime", new AliasTemplateDateFormatFactory("iso ms u"));
    cfg.setCustomDateFormats(customDateFormats);
    addToDataModel("p", 10000);
    addToDataModel("w", new BigDecimal("10.305"));
    addToDataModel("fd", new Date(1450904944213L));
    addToDataModel("let", new Date(1450904944213L));
    assertOutputForNamed("CustomFormatsExample-alias1.ftlh");
}
Also used : AliasTemplateNumberFormatFactory(freemarker.core.AliasTemplateNumberFormatFactory) Configuration(freemarker.template.Configuration) HashMap(java.util.HashMap) BaseNTemplateNumberFormatFactory(freemarker.core.BaseNTemplateNumberFormatFactory) TemplateNumberFormatFactory(freemarker.core.TemplateNumberFormatFactory) AliasTemplateNumberFormatFactory(freemarker.core.AliasTemplateNumberFormatFactory) BigDecimal(java.math.BigDecimal) Date(java.util.Date) TemplateDateFormatFactory(freemarker.core.TemplateDateFormatFactory) AliasTemplateDateFormatFactory(freemarker.core.AliasTemplateDateFormatFactory) AliasTemplateDateFormatFactory(freemarker.core.AliasTemplateDateFormatFactory) Test(org.junit.Test)

Example 3 with TemplateNumberFormatFactory

use of freemarker.core.TemplateNumberFormatFactory in project freemarker by apache.

the class CustomFormatsExample method modelAware.

@Test
public void modelAware() throws IOException, TemplateException {
    Configuration cfg = getConfiguration();
    Map<String, TemplateNumberFormatFactory> customNumberFormats = new HashMap<String, TemplateNumberFormatFactory>();
    customNumberFormats.put("ua", UnitAwareTemplateNumberFormatFactory.INSTANCE);
    cfg.setCustomNumberFormats(customNumberFormats);
    cfg.setNumberFormat("@ua 0.####;; roundingMode=halfUp");
    addToDataModel("weight", new UnitAwareTemplateNumberModel(1.5, "kg"));
    assertOutputForNamed("CustomFormatsExample-modelAware.ftlh");
}
Also used : Configuration(freemarker.template.Configuration) HashMap(java.util.HashMap) BaseNTemplateNumberFormatFactory(freemarker.core.BaseNTemplateNumberFormatFactory) TemplateNumberFormatFactory(freemarker.core.TemplateNumberFormatFactory) AliasTemplateNumberFormatFactory(freemarker.core.AliasTemplateNumberFormatFactory) Test(org.junit.Test)

Aggregations

AliasTemplateNumberFormatFactory (freemarker.core.AliasTemplateNumberFormatFactory)3 BaseNTemplateNumberFormatFactory (freemarker.core.BaseNTemplateNumberFormatFactory)3 TemplateNumberFormatFactory (freemarker.core.TemplateNumberFormatFactory)3 Configuration (freemarker.template.Configuration)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 AliasTemplateDateFormatFactory (freemarker.core.AliasTemplateDateFormatFactory)1 TemplateDateFormatFactory (freemarker.core.TemplateDateFormatFactory)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1