當前位置: 首頁>>代碼示例>>Java>>正文


Java Configuration.setClassForTemplateLoading方法代碼示例

本文整理匯總了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);
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:22,代碼來源:ThriftFileBuilder.java

示例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;
}
 
開發者ID:DarwinSPL,項目名稱:DarwinSPL,代碼行數:22,代碼來源:DwFeatureModelOverviewGenerator.java

示例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");
}
 
開發者ID:xsingHu,項目名稱:xs-android-architecture,代碼行數:20,代碼來源:DaoGenerator.java

示例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;
}
 
開發者ID:DarwinSPL,項目名稱:DarwinSPL,代碼行數:32,代碼來源:DwFeatureModelSVGGenerator.java

示例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;
}
 
開發者ID:lnwazg,項目名稱:kit,代碼行數:28,代碼來源:FreeMkKit.java

示例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();
	}
}
 
開發者ID:esig,項目名稱:dss-demonstrations,代碼行數:10,代碼來源:NexuDeployScriptController.java

示例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);
}
 
開發者ID:tsiq,項目名稱:magic-beanstalk,代碼行數:17,代碼來源:FileGenerator.java

示例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;
}
 
開發者ID:dmn-tck,項目名稱:tck,代碼行數:8,代碼來源:Reporter.java

示例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;
}
 
開發者ID:WinRoad-NET,項目名稱:wrdocletbase,代碼行數:13,代碼來源:FreemarkerWriter.java

示例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();
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:40,代碼來源:EventEmail.java

示例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;
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:10,代碼來源:Freemarker.java

示例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);
}
 
開發者ID:petabyte-research,項目名稱:redflags,代碼行數:9,代碼來源:NoticesSvc.java

示例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;
}
 
開發者ID:witchpou,項目名稱:lj-projectbuilder,代碼行數:14,代碼來源:GeneratorService.java

示例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);
	}
}
 
開發者ID:deptofdefense,項目名稱:anet,代碼行數:41,代碼來源:ReportResource.java

示例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);
}
 
開發者ID:deptofdefense,項目名稱:anet,代碼行數:35,代碼來源:AnetEmailWorker.java


注:本文中的freemarker.template.Configuration.setClassForTemplateLoading方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。