本文整理匯總了Java中freemarker.template.TemplateExceptionHandler類的典型用法代碼示例。如果您正苦於以下問題:Java TemplateExceptionHandler類的具體用法?Java TemplateExceptionHandler怎麽用?Java TemplateExceptionHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TemplateExceptionHandler類屬於freemarker.template包,在下文中一共展示了TemplateExceptionHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: render
import freemarker.template.TemplateExceptionHandler; //導入依賴的package包/類
public void render(String modelType) throws IOException {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setClassLoaderForTemplateLoading(SimpleModel.class.getClassLoader(), "/");
if (!outDir.getParentFile().exists())
outDir.getParentFile().mkdirs();
String modelTypeName = modelType.substring(0, 1).toUpperCase() + modelType.substring(1);
Map<String, Object> params = new HashMap<String, Object>();
params.put("packageName", packageName);
params.put("models", models);
writeFile(packageName, modelTypeName, getTemplate(cfg, modelType), params);
for (SimpleModel model : models) {
if (model.isRender()) {
params = new HashMap<>();
params.put("model", model);
writeFile(model.getPackageName(), model.getName(), getModelTemplate(cfg), params);
}
}
}
示例2: prepareConfiguration
import freemarker.template.TemplateExceptionHandler; //導入依賴的package包/類
private static Configuration prepareConfiguration() {
Configuration result = new Configuration(Configuration.VERSION_2_3_26);
result.setNumberFormat("computer");
result.setDefaultEncoding(StandardCharsets.UTF_8.name());
result.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
result.setLogTemplateExceptions(false);
return result;
}
示例3: init
import freemarker.template.TemplateExceptionHandler; //導入依賴的package包/類
@Override
public void init(ServletConfig servletConfig) throws ServletException {
this.servletConfig = servletConfig;
//templateCfg.setClassForTemplateLoading(getClass(), "/");
Resource baseResource;
try {
baseResource = Resource.newResource(servletConfig.getInitParameter("resourceBase"));
} catch (MalformedURLException e) {
throw new ServletException(e);
}
templateCfg.setTemplateLoader(new ResourceTemplateLoader(baseResource));
templateCfg.setDefaultEncoding("UTF-8");
// Sets how errors will appear.
// During web page *development* TemplateExceptionHandler.HTML_DEBUG_HANDLER
// is better.
// cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
templateCfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
}
示例4: init
import freemarker.template.TemplateExceptionHandler; //導入依賴的package包/類
public void init() throws IOException {
ClassTemplateLoader ctl = new ClassTemplateLoader(Application.class, "/freemarker");
MultiTemplateLoader mtl = new MultiTemplateLoader(new TemplateLoader[] {ctl});
Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);
cfg.setTemplateLoader(mtl);
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setLogTemplateExceptions(false);
Pair<String, Template> clusterResourceQuota = new ImmutablePair<String, Template>("ClusterResourceQuota-ForUser", cfg.getTemplate("ClusterResourceQuota-ForUser.ftlh"));
Pair<String, Template> bestEffortResourceLimits = new ImmutablePair<String, Template>("LimitRange-BestEffortResourceLimits", cfg.getTemplate("LimitRange-BestEffortResourceLimits.ftlh"));
Pair<String, Template> burstableResourceLimits = new ImmutablePair<String, Template>("LimitRange-BurstableResourceLimits", cfg.getTemplate("LimitRange-BurstableResourceLimits.ftlh"));
Pair<String, Template> maxImageCounts = new ImmutablePair<String, Template>("LimitRange-MaxImageCounts", cfg.getTemplate("LimitRange-MaxImageCounts.ftlh"));
Pair<String, Template> bestEffort = new ImmutablePair<String, Template>("ResourceQuota-BestEffort", cfg.getTemplate("ResourceQuota-BestEffort.ftlh"));
Pair<String, Template> notTerminatingAndNotBestEffort = new ImmutablePair<String, Template>("ResourceQuota-NotTerminating-And-NotBestEffort",
cfg.getTemplate("ResourceQuota-NotTerminating-And-NotBestEffort.ftlh"));
Pair<String, Template> terminating = new ImmutablePair<String, Template>("ResourceQuota-Terminating", cfg.getTemplate("ResourceQuota-Terminating.ftlh"));
templates = Arrays.asList(clusterResourceQuota, bestEffortResourceLimits, burstableResourceLimits, maxImageCounts, bestEffort, notTerminatingAndNotBestEffort, terminating);
}
示例5: initializeConfiguration
import freemarker.template.TemplateExceptionHandler; //導入依賴的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;
}
示例6: initializeConfiguration
import freemarker.template.TemplateExceptionHandler; //導入依賴的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;
}
示例7: getConfigurationByClass
import freemarker.template.TemplateExceptionHandler; //導入依賴的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;
}
示例8: getConfigurationByClassLoader
import freemarker.template.TemplateExceptionHandler; //導入依賴的package包/類
public static Configuration getConfigurationByClassLoader(ClassLoader classLoader, String prefix)
{
try
{
Configuration configuration = new Configuration(Configuration.VERSION_2_3_25);
configuration.setClassLoaderForTemplateLoading(classLoader, 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;
}
示例9: getConfigurationByDirectory
import freemarker.template.TemplateExceptionHandler; //導入依賴的package包/類
/**
* 根據模板的路徑,獲取一個配置文件
* @author [email protected]
* @param templateLoadingPath
* @return
*/
public static Configuration getConfigurationByDirectory(File templateLoadingPath)
{
try
{
Configuration configuration = new Configuration(Configuration.VERSION_2_3_25);
//以下這兩種設置方式是等價的
// configuration.setDirectoryForTemplateLoading(templateLoadingPath);
configuration.setTemplateLoader(new FileTemplateLoader(templateLoadingPath));
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;
}
示例10: JoomlaHugoConverter
import freemarker.template.TemplateExceptionHandler; //導入依賴的package包/類
public JoomlaHugoConverter(NastyContentChecker nastyContentChecker,
JdbcTemplate template, String pathToOutput, String dbExtension,
boolean buildTags) throws IOException {
this.dbExtension = dbExtension;
this.nastyContentChecker = nastyContentChecker;
this.template = template;
this.pathToOutput = pathToOutput;
this.buildTags = buildTags;
Configuration cfg = new Configuration(Configuration.getVersion());
cfg.setClassLoaderForTemplateLoading(ClassLoader.getSystemClassLoader(), "/");
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setLogTemplateExceptions(false);
categoryTemplate = cfg.getTemplate("categoryPage.toml.ftl");
contentTemplate = cfg.getTemplate("defaultPage.toml.ftl");
buildTags();
}
示例11: init
import freemarker.template.TemplateExceptionHandler; //導入依賴的package包/類
private void init() {
if (inited) {
return;
}
lock.lock();
try {
if (!inited) {
cfg = new Configuration(Configuration.VERSION_2_3_25);
cfg.setDefaultEncoding(encode);
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setClassLoaderForTemplateLoading(ClassLoader.getSystemClassLoader(), tmplPath);
}
} finally {
lock.unlock();
}
}
示例12: TemplateService
import freemarker.template.TemplateExceptionHandler; //導入依賴的package包/類
public TemplateService() {
String templatePath = new File("").getAbsolutePath();
System.out.println("Using template path '" + templatePath + "'.");
try {
config = new Configuration(Configuration.VERSION_2_3_25);
config.setDirectoryForTemplateLoading(new File(templatePath));
config.setDefaultEncoding("UTF-8");
config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
config.setLogTemplateExceptions(false);
} catch (IOException e) {
throw new FileLibraryException(e);
}
}
示例13: SchemaMaker
import freemarker.template.TemplateExceptionHandler; //導入依賴的package包/類
/**
* @param onTable
*/
public SchemaMaker(String tenant, String module, TenantOperation mode, String previousVersion, String rmbVersion){
if(SchemaMaker.cfg == null){
//do this ONLY ONCE
SchemaMaker.cfg = new Configuration(new Version(2, 3, 26));
// Where do we load the templates from:
cfg.setClassForTemplateLoading(SchemaMaker.class, "/templates/db_scripts");
cfg.setDefaultEncoding("UTF-8");
cfg.setLocale(Locale.US);
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
}
this.tenant = tenant;
this.module = module;
this.mode = mode;
this.previousVersion = previousVersion;
this.rmbVersion = rmbVersion;
}
示例14: __doViewInit
import freemarker.template.TemplateExceptionHandler; //導入依賴的package包/類
@Override
protected void __doViewInit(IWebMvc owner) {
super.__doViewInit(owner);
// 初始化Freemarker模板引擎配置
if (__freemarkerConfig == null) {
__freemarkerConfig = new Configuration(Configuration.VERSION_2_3_22);
__freemarkerConfig.setDefaultEncoding(owner.getModuleCfg().getDefaultCharsetEncoding());
__freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
//
List<TemplateLoader> _tmpLoaders = new ArrayList<TemplateLoader>();
try {
if (__baseViewPath.startsWith("/WEB-INF")) {
_tmpLoaders.add(new FileTemplateLoader(new File(RuntimeUtils.getRootPath(), StringUtils.substringAfter(__baseViewPath, "/WEB-INF/"))));
} else {
_tmpLoaders.add(new FileTemplateLoader(new File(__baseViewPath)));
}
//
__freemarkerConfig.setTemplateLoader(new MultiTemplateLoader(_tmpLoaders.toArray(new TemplateLoader[_tmpLoaders.size()])));
} catch (IOException e) {
throw new Error(RuntimeUtils.unwrapThrow(e));
}
}
}
示例15: createConfiguration
import freemarker.template.TemplateExceptionHandler; //導入依賴的package包/類
Configuration createConfiguration() throws IOException {
// Create your Configuration instance, and specify if up to what FreeMarker
// version (here 2.3.22) do you want to apply the fixes that are not 100%
// backward-compatible. See the Configuration JavaDoc for details.
Configuration cfg = new Configuration(Configuration.VERSION_2_3_21);
// Specify the source where the template files come from. Here I set a
// plain directory for it, but non-file-system sources are possible too:
cfg.setDirectoryForTemplateLoading(new File("/"));
// Set the preferred charset template files are stored in. UTF-8 is
// a good choice in most applications:
cfg.setDefaultEncoding("UTF-8");
// Sets how errors will appear.
// During web page *development* TemplateExceptionHandler.HTML_DEBUG_HANDLER is better.
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setTemplateLoader(new ClassTemplateLoader());
return cfg;
}