本文整理匯總了Java中freemarker.template.Configuration.setLocale方法的典型用法代碼示例。如果您正苦於以下問題:Java Configuration.setLocale方法的具體用法?Java Configuration.setLocale怎麽用?Java Configuration.setLocale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類freemarker.template.Configuration
的用法示例。
在下文中一共展示了Configuration.setLocale方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initializeConfiguration
import freemarker.template.Configuration; //導入方法依賴的package包/類
/**
* Configures freemarker for usage.
* @return
* @throws URISyntaxException
* @throws TemplateNotFoundException
* @throws MalformedTemplateNameException
* @throws ParseException
* @throws IOException
* @throws TemplateException
*/
private Configuration initializeConfiguration() throws URISyntaxException, TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException{
Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
cfg.setClassForTemplateLoading(DwFeatureModelSVGGenerator.class, "templates");
cfg.setDefaultEncoding("UTF-8");
cfg.setLocale(Locale.US);
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
Bundle bundle = Platform.getBundle("de.darwinspl.feature.graphical.editor");
URL fileURL = bundle.getEntry("templates/");
File file = new File(FileLocator.resolve(fileURL).toURI());
cfg.setDirectoryForTemplateLoading(file);
Map<String, TemplateNumberFormatFactory> customNumberFormats = new HashMap<String, TemplateNumberFormatFactory>();
customNumberFormats.put("hex", DwHexTemplateNumberFormatFactory.INSTANCE);
cfg.setCustomNumberFormats(customNumberFormats);
return cfg;
}
示例2: initializeConfiguration
import freemarker.template.Configuration; //導入方法依賴的package包/類
private Configuration initializeConfiguration() throws URISyntaxException, TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException{
Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
cfg.setClassForTemplateLoading(DwFeatureModelOverviewGenerator.class, "templates");
cfg.setDefaultEncoding("UTF-8");
cfg.setLocale(Locale.US);
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
Map<String, TemplateDateFormatFactory> customDateFormats = new HashMap<String, TemplateDateFormatFactory>();
customDateFormats.put("simple", DwSimpleTemplateDateFormatFactory.INSTANCE);
cfg.setCustomDateFormats(customDateFormats);
cfg.setDateTimeFormat("@simle");
Bundle bundle = Platform.getBundle("eu.hyvar.feature.graphical.editor");
URL fileURL = bundle.getEntry("templates/");
File file = new File(FileLocator.resolve(fileURL).toURI());
cfg.setDirectoryForTemplateLoading(file);
return cfg;
}
示例3: configuration
import freemarker.template.Configuration; //導入方法依賴的package包/類
@Singleton
@Provides
public static Configuration configuration(LinkHelper linkHelper, MultiTemplateLoader templateLoader) {
try {
freemarker.log.Logger.selectLoggerLibrary(Logger.LIBRARY_SLF4J);
Configuration cfg = new freemarker.template.Configuration(Configuration.VERSION_2_3_25);
cfg.setTagSyntax(freemarker.template.Configuration.SQUARE_BRACKET_TAG_SYNTAX);
cfg.setLazyAutoImports(true);
cfg.setLocale(Locale.GERMANY); // todo make configurable
cfg.addAutoImport("saito", "saito.ftl");
cfg.setSharedVariable("saitoLinkHelper", linkHelper);
cfg.setDefaultEncoding("UTF-8");
cfg.setLogTemplateExceptions(false);
cfg.setTemplateLoader(templateLoader);
return cfg;
} catch (TemplateModelException | ClassNotFoundException e) {
log.error("Error creating config", e);
throw new IllegalStateException(e);
}
}
示例4: message
import freemarker.template.Configuration; //導入方法依賴的package包/類
private String message() throws IOException, TemplateException {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
cfg.setClassForTemplateLoading(EventEmail.class, "");
cfg.setLocale(Localization.getJavaLocale());
cfg.setOutputEncoding("utf-8");
Template template = cfg.getTemplate("confirmation.ftl");
Map<String, Object> input = new HashMap<String, Object>();
input.put("msg", MESSAGES);
input.put("const", CONSTANTS);
input.put("subject", subject());
input.put("event", event());
input.put("operation", request().getOperation() == null ? "NONE" : request().getOperation().name());
if (response().hasCreatedMeetings())
input.put("created", EventInterface.getMultiMeetings(response().getCreatedMeetings(), true, false));
if (response().hasDeletedMeetings())
input.put("deleted", EventInterface.getMultiMeetings(response().getDeletedMeetings(), true, false));
if (response().hasCancelledMeetings())
input.put("cancelled", EventInterface.getMultiMeetings(response().getCancelledMeetings(), true, false));
if (response().hasUpdatedMeetings())
input.put("updated", EventInterface.getMultiMeetings(response().getUpdatedMeetings(), true, false));
if (request().hasMessage())
input.put("message", request().getMessage());
if (request().getEvent().getId() != null) {
if (event().hasMeetings()) {
input.put("meetings", EventInterface.getMultiMeetings(event().getMeetings(), true, false));
} else
input.put("meetings", new TreeSet<MultiMeetingInterface>());
}
input.put("version", MESSAGES.pageVersion(Constants.getVersion(), Constants.getReleaseDate()));
input.put("ts", new Date());
input.put("link", ApplicationProperty.UniTimeUrl.value());
input.put("sessionId", iRequest.getSessionId());
StringWriter s = new StringWriter();
template.process(input, new PrintWriter(s));
s.flush(); s.close();
return s.toString();
}
示例5: FreeMarkerService
import freemarker.template.Configuration; //導入方法依賴的package包/類
private FreeMarkerService(Builder bulder) {
maxOutputLength = bulder.getMaxOutputLength();
maxThreads = bulder.getMaxThreads();
maxQueueLength = bulder.getMaxQueueLength();
maxTemplateExecutionTime = bulder.getMaxTemplateExecutionTime();
int actualMaxQueueLength = maxQueueLength != null
? maxQueueLength
: Math.max(
MIN_DEFAULT_MAX_QUEUE_LENGTH,
(int) (MAX_DEFAULT_MAX_QUEUE_LENGTH_MILLISECONDS / maxTemplateExecutionTime));
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
maxThreads, maxThreads,
THREAD_KEEP_ALIVE_TIME, TimeUnit.MILLISECONDS,
new BlockingArrayQueue<Runnable>(actualMaxQueueLength));
threadPoolExecutor.allowCoreThreadTimeOut(true);
templateExecutor = threadPoolExecutor;
freeMarkerConfig = new Configuration(Configuration.getVersion());
freeMarkerConfig.setNewBuiltinClassResolver(TemplateClassResolver.ALLOWS_NOTHING_RESOLVER);
freeMarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
freeMarkerConfig.setLogTemplateExceptions(false);
freeMarkerConfig.setAttemptExceptionReporter(new AttemptExceptionReporter() {
@Override
public void report(TemplateException te, Environment env) {
// Suppress it
}
});
freeMarkerConfig.setLocale(AllowedSettingValuesMaps.DEFAULT_LOCALE);
freeMarkerConfig.setTimeZone(AllowedSettingValuesMaps.DEFAULT_TIME_ZONE);
freeMarkerConfig.setOutputFormat(AllowedSettingValuesMaps.DEFAULT_OUTPUT_FORMAT);
freeMarkerConfig.setOutputEncoding("UTF-8");
}
示例6: render
import freemarker.template.Configuration; //導入方法依賴的package包/類
public static String render(String templateContent, Map<String, Object> params)
throws IOException, TemplateException {
StringWriter sw = new StringWriter();
App app = App.get();
ApplicationContext appCtx = app.context();
RequestContext reqCtx = appCtx.getRequestContext();
// TODO: replace quick hack with configured value!
Configuration conf = new Configuration();
conf.setDefaultEncoding("UTF-8");
if (reqCtx != null && reqCtx.getLocale() != null)
conf.setLocale(reqCtx.getLocale());
conf.setSharedVariable("set", new SetDirective());
conf.setSharedVariable("url", app.inject(URLDirective.class));
conf.setSharedVariable("attribute", new AttributeDirective());
conf.setSharedVariable("attribute_exists", new AttributeExistsDirective());
conf.setSharedVariable("attribute_equals", new AttributeEqualsDirective());
conf.setSharedVariable("attribute_has_value", new AttributeHasValueDirective());
conf.setSharedVariable("message", new MessageDirective());
conf.setSharedVariable("print", new PrintDirective());
conf.setSharedVariable("json", new JsonDirective());
conf.setSharedVariable("skin", new SkinDirective());
conf.setSharedVariable("truncate", new TruncateDirective());
Template t = new Template("name", new StringReader(templateContent), conf);
t.process(params, sw);
return sw.toString();
}