本文整理汇总了Java中freemarker.template.Configuration.setClassForTemplateLoading方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.setClassForTemplateLoading方法的具体用法?Java Configuration.setClassForTemplateLoading怎么用?Java Configuration.setClassForTemplateLoading使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类freemarker.template.Configuration
的用法示例。
在下文中一共展示了Configuration.setClassForTemplateLoading方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildToOutputStream
import freemarker.template.Configuration; //导入方法依赖的package包/类
public void buildToOutputStream(Class<?> commonServiceClass, OutputStream os) throws Exception {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
cfg.setClassForTemplateLoading(ThriftFileBuilder.class, "/");
Template template = cfg.getTemplate("templates/thrift/thrift.ftl");
Writer out = new OutputStreamWriter(os);
ThriftServiceBuilder serviceBuilder = new ThriftServiceBuilder(commonServiceClass);
ThriftService service = serviceBuilder.buildThriftService();
Map<String, Object> rootMap = new HashMap<String, Object>();
rootMap.put("thriftServicePackage", this.getPackageName(commonServiceClass));
List<ThriftStruct> structs = serviceBuilder.getStructs();
List<ThriftEnum> enums = serviceBuilder.getEnums();
CommonUtils.removeRepeat(structs);
rootMap.put("structList", structs);
rootMap.put("enumList", enums);
CommonUtils.removeRepeat(enums);
rootMap.put("serviceList", Arrays.asList(service));
template.process(rootMap, out);
}
示例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: DaoGenerator
import freemarker.template.Configuration; //导入方法依赖的package包/类
public DaoGenerator() throws IOException {
System.out.println("greenDAO Generator");
System.out.println("Copyright 2011-2016 Markus Junginger, greenrobot.de. Licensed under GPL V3.");
System.out.println("This program comes with ABSOLUTELY NO WARRANTY");
patternKeepIncludes = compilePattern("INCLUDES");
patternKeepFields = compilePattern("FIELDS");
patternKeepMethods = compilePattern("METHODS");
Configuration config = new Configuration(Configuration.VERSION_2_3_23);
config.setClassForTemplateLoading(this.getClass(), "/");
templateDao = config.getTemplate("dao.ftl");
templateDaoMaster = config.getTemplate("dao-master.ftl");
templateDaoSession = config.getTemplate("dao-session.ftl");
templateEntity = config.getTemplate("entity.ftl");
templateDaoUnitTest = config.getTemplate("dao-unit-test.ftl");
templateContentProvider = config.getTemplate("content-provider.ftl");
}
示例4: 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;
}
示例5: getConfigurationByClass
import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
* 根据根路径的类,获取配置文件
* @author nan.li
* @param paramClass
* @param prefix
* @return
*/
public static Configuration getConfigurationByClass(Class<?> paramClass, String prefix)
{
try
{
Configuration configuration = new Configuration(Configuration.VERSION_2_3_25);
configuration.setClassForTemplateLoading(paramClass, prefix);
//等价于下面这种方法
// configuration.setTemplateLoader( new ClassTemplateLoader(paramClass,prefix));
configuration.setObjectWrapper(new DefaultObjectWrapper(Configuration.VERSION_2_3_25));
configuration.setDefaultEncoding(CharEncoding.UTF_8);
configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
configuration.setObjectWrapper(new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25).build());
return configuration;
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
示例6: NexuDeployScriptController
import freemarker.template.Configuration; //导入方法依赖的package包/类
public NexuDeployScriptController() {
try {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
cfg.setClassForTemplateLoading(getClass(), "/");
this.template = cfg.getTemplate("nexu_deploy.ftl.js", "UTF-8");
} catch (IOException e) {
throw new RuntimeException();
}
}
示例7: generateDefaultDockerrunFile
import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
*Generate a dockerrun.aws.json file with the default template
* @param outputFilePath the output directory
* @param parameters a map to hydrate the default template with
* @throws IOException if failed to load the template file
* @throws TemplateException if template generation fails
*/
public static void generateDefaultDockerrunFile(
String outputFilePath,
Map<String, Object> parameters
) throws IOException, TemplateException {
Configuration cfg = initializeTemplateConfiguration();
cfg.setClassForTemplateLoading(FileGenerator.class, "/");
final String defaultDockerrunTemplateFile = "DockerrunTemplate.ftlh";
generateFileFromTemplate(cfg, defaultDockerrunTemplateFile, outputFilePath, parameters);
}
示例8: createFreemarkerConfiguration
import freemarker.template.Configuration; //导入方法依赖的package包/类
private static Configuration createFreemarkerConfiguration() {
Configuration cfg = new Configuration();
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler( TemplateExceptionHandler.RETHROW_HANDLER );
cfg.setClassForTemplateLoading( Reporter.class, "/" );
return cfg;
}
示例9: getTemplate
import freemarker.template.Configuration; //导入方法依赖的package包/类
protected Template getTemplate(String tmplFileName)
throws IOException {
Configuration cfg = new Configuration();
cfg.setEncoding(DEFAULT_LOCALE, DEFAULT_ENCODING);
this.logger.debug("reading ftl " + tmplFileName
+ " from class path " + freemarkerTemplateDefaultFilePath);
cfg.setClassForTemplateLoading(this.getClass(),
freemarkerTemplateDefaultFilePath);
Template tmpl = cfg.getTemplate(tmplFileName);
tmpl.setEncoding(DEFAULT_ENCODING);
return tmpl;
}
示例10: 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();
}
示例11: newFreeMarkerConfig
import freemarker.template.Configuration; //导入方法依赖的package包/类
private Configuration newFreeMarkerConfig() {
Configuration freeMarkerConfig = new Configuration(Configuration.VERSION_2_3_24);
freeMarkerConfig.setDefaultEncoding("UTF-8");
freeMarkerConfig.setClassForTemplateLoading(this.getClass(), "/");
freeMarkerConfig
.setTemplateExceptionHandler(TemplateExceptionHandler.DEBUG_HANDLER);
return freeMarkerConfig;
}
示例12: init
import freemarker.template.Configuration; //导入方法依赖的package包/类
@PostConstruct
public void init() throws IOException {
cfg = new Configuration(Configuration.VERSION_2_3_21);
cfg.setClassForTemplateLoading(App.class, "/queries/");
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
tpl = cfg.getTemplate(FTL);
}
示例13: getTemplate
import freemarker.template.Configuration; //导入方法依赖的package包/类
public Template getTemplate(String templatePath)
throws IOException, TemplateNotFoundException, MalformedTemplateNameException, ParseException {
@SuppressWarnings("deprecation")
Configuration cfg = new Configuration();
if (templatePath.startsWith("classpath:")) {
cfg.setClassForTemplateLoading(FindClass.class, ".." + Constants.FILE_SEP);
templatePath = templatePath.replace("classpath:", "");
} else {
cfg.setDirectoryForTemplateLoading(new File(templatePath));
}
Template template = cfg.getTemplate(templatePath);
return template;
}
示例14: showRollupEmail
import freemarker.template.Configuration; //导入方法依赖的package包/类
@GET
@Timed
@Path("/rollup")
@Produces(MediaType.TEXT_HTML)
public Response showRollupEmail(@Auth Person user, @QueryParam("startDate") Long start,
@QueryParam("endDate") Long end,
@QueryParam("orgType") OrganizationType orgType,
@QueryParam("advisorOrganizationId") Integer advisorOrgId,
@QueryParam("principalOrganizationId") Integer principalOrgId,
@QueryParam("showText") @DefaultValue("false") Boolean showReportText) {
DailyRollupEmail action = new DailyRollupEmail();
action.setStartDate(new DateTime(start));
action.setEndDate(new DateTime(end));
action.setChartOrgType(orgType);
action.setAdvisorOrganizationId(advisorOrgId);
action.setPrincipalOrganizationId(principalOrgId);
Map<String,Object> context = action.execute();
context.put("serverUrl", config.getServerUrl());
context.put(AdminSettingKeys.SECURITY_BANNER_TEXT.name(), engine.getAdminSetting(AdminSettingKeys.SECURITY_BANNER_TEXT));
context.put(AdminSettingKeys.SECURITY_BANNER_COLOR.name(), engine.getAdminSetting(AdminSettingKeys.SECURITY_BANNER_COLOR));
context.put(DailyRollupEmail.SHOW_REPORT_TEXT_FLAG, showReportText);
try {
Configuration freemarkerConfig = new Configuration(Configuration.getVersion());
freemarkerConfig.setObjectWrapper(new DefaultObjectWrapperBuilder(Configuration.getVersion()).build());
freemarkerConfig.loadBuiltInEncodingMap();
freemarkerConfig.setDefaultEncoding(StandardCharsets.UTF_8.name());
freemarkerConfig.setClassForTemplateLoading(this.getClass(), "/");
freemarkerConfig.setAPIBuiltinEnabled(true);
Template temp = freemarkerConfig.getTemplate(action.getTemplateName());
StringWriter writer = new StringWriter();
temp.process(context, writer);
return Response.ok(writer.toString(), MediaType.TEXT_HTML_TYPE).build();
} catch (Exception e) {
throw new WebApplicationException(e);
}
}
示例15: AnetEmailWorker
import freemarker.template.Configuration; //导入方法依赖的package包/类
public AnetEmailWorker(Handle dbHandle, AnetConfiguration config, ScheduledExecutorService scheduler) {
this.handle = dbHandle;
this.scheduler = scheduler;
this.mapper = new ObjectMapper();
mapper.registerModule(new JodaModule());
//mapper.enableDefaultTyping();
this.emailMapper = new AnetEmailMapper();
this.fromAddr = config.getEmailFromAddr();
this.serverUrl = config.getServerUrl();
instance = this;
SmtpConfiguration smtpConfig = config.getSmtp();
props = new Properties();
props.put("mail.smtp.starttls.enable", smtpConfig.getStartTls().toString());
props.put("mail.smtp.host", smtpConfig.getHostname());
props.put("mail.smtp.port", smtpConfig.getPort().toString());
auth = null;
if (smtpConfig.getUsername() != null && smtpConfig.getUsername().trim().length() > 0) {
props.put("mail.smtp.auth", "true");
auth = new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(smtpConfig.getUsername(), smtpConfig.getPassword());
}
};
}
freemarkerConfig = new Configuration(Configuration.getVersion());
freemarkerConfig.setObjectWrapper(new DefaultObjectWrapperBuilder(Configuration.getVersion()).build());
freemarkerConfig.loadBuiltInEncodingMap();
freemarkerConfig.setDefaultEncoding(StandardCharsets.UTF_8.name());
freemarkerConfig.setClassForTemplateLoading(this.getClass(), "/");
freemarkerConfig.setAPIBuiltinEnabled(true);
}