本文整理匯總了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);
}