本文整理汇总了Java中freemarker.template.TemplateMethodModelEx类的典型用法代码示例。如果您正苦于以下问题:Java TemplateMethodModelEx类的具体用法?Java TemplateMethodModelEx怎么用?Java TemplateMethodModelEx使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TemplateMethodModelEx类属于freemarker.template包,在下文中一共展示了TemplateMethodModelEx类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerResourceBundleResolver
import freemarker.template.TemplateMethodModelEx; //导入依赖的package包/类
private static void registerResourceBundleResolver(Map<String, Object> model, Locale locale, StampoGlobalConfiguration configuration) {
model.put("message", new ResourceBundleModel(ResourceBundle.getBundle("messages", locale, configuration.getResourceBundleControl()), new BeansWrapperBuilder(Configuration.VERSION_2_3_22).build()));
TemplateMethodModelEx messageWithBundle = (arguments) -> {
if (arguments.size() < 2) {
throw new IllegalArgumentException(
"messageWithBundle must have at least 2 parameters, passed only " + arguments.size());
}
String bundleName = arguments.get(0).toString();
String code = arguments.get(1).toString();
List<Object> parameters = new ArrayList<>();
for (int i = 2; i < arguments.size(); i++) {
parameters.add(arguments.get(i));
}
return MessageFormat.format(
ResourceBundle.getBundle(bundleName, locale, configuration.getResourceBundleControl()).getString(code),
parameters.toArray());
};
model.put("messageWithBundle", messageWithBundle);
TemplateMethodModelEx defaultOrLocale = (arguments) -> {
String loc = arguments.get(0).toString();
return configuration.getDefaultLocale().map(l -> l.toLanguageTag().equals(loc) ? "" : loc)
.orElse(loc);
};
model.put("defaultOrLocale", defaultOrLocale);
TemplateMethodModelEx switchToLocale = (arguments) -> {
String localeToSwitch = arguments.get(0).toString();
Path fileResourceOutputPath = (Path) model.get("fileResourceOutputPath");
return PathUtils.switchToLocale(Locale.forLanguageTag(localeToSwitch), locale, fileResourceOutputPath, configuration);
};
model.put("switchToLocale", switchToLocale);
}