freemarker.core.Environment.toFullTemplateName()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中freemarker.core.Environment.toFullTemplateName()方法的一些代码示例,展示了Environment.toFullTemplateName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Environment.toFullTemplateName()方法的具体详情如下:
包路径:freemarker.core.Environment
类名称:Environment
方法名:toFullTemplateName

Environment.toFullTemplateName介绍

[英]Resolves a reference to a template (like the one used in #include or #import), assuming a base name. This gives a root based, even if non-normalized and possibly non-absolute (but then relative to the root) template name, that could be used for Configuration#getTemplate(String). This is mostly used when a template refers to another template.

If you need to guarantee that the result is also an absolute path, then apply #rootBasedToAbsoluteTemplateName(String) on it.
[中]使用基名称解析对模板的引用(如#include或#import中使用的模板)。这提供了一个基于根的模板名称,即使是非规范化的、可能是非绝对的(但相对于根)模板名称,也可以用于配置#getTemplate(字符串)。这主要用于模板引用另一个模板时。
如果需要保证结果也是绝对路径,则对其应用#rootBasedToAbsoluteTemplateName(字符串)。

代码示例

代码示例来源:origin: org.freemarker/freemarker

  1. /**
  2. * @deprecated Use {@link Environment#toFullTemplateName(String, String)} instead, as that can throw
  3. * {@link MalformedTemplateNameException}, and is on a more logical place anyway.
  4. *
  5. * @throws IllegalArgumentException
  6. * If the {@code baseName} or {@code targetName} is malformed according the {@link TemplateNameFormat}
  7. * in use.
  8. */
  9. @Deprecated
  10. public static String getFullTemplatePath(Environment env, String baseName, String targetName) {
  11. try {
  12. return env.toFullTemplateName(baseName, targetName);
  13. } catch (MalformedTemplateNameException e) {
  14. throw new IllegalArgumentException(e.getMessage());
  15. }
  16. }

代码示例来源:origin: org.freemarker/freemarker

  1. static Template getTemplate(String systemId) throws IOException {
  2. Environment env = Environment.getCurrentEnvironment();
  3. String encoding = env.getTemplate().getEncoding();
  4. if (encoding == null) {
  5. encoding = env.getConfiguration().getEncoding(env.getLocale());
  6. }
  7. String templatePath = env.getTemplate().getName();
  8. int lastSlash = templatePath.lastIndexOf('/');
  9. templatePath = lastSlash == -1 ? "" : templatePath.substring(0, lastSlash + 1);
  10. systemId = env.toFullTemplateName(templatePath, systemId);
  11. Template raw = env.getConfiguration().getTemplate(systemId, env.getLocale(), encoding, false);
  12. return raw;
  13. }

代码示例来源:origin: org.freemarker/freemarker

  1. /**
  2. * @param basePath Maybe {@code null}
  3. */
  4. private String resolvePath(String basePath) throws TemplateModelException {
  5. try {
  6. return env.rootBasedToAbsoluteTemplateName(env.toFullTemplateName(basePath, pathToResolve));
  7. } catch (MalformedTemplateNameException e) {
  8. throw new _TemplateModelException(e,
  9. "Can't resolve ", new _DelayedJQuote(pathToResolve),
  10. "to absolute template name using base ", new _DelayedJQuote(basePath),
  11. "; see cause exception");
  12. }
  13. }

代码示例来源:origin: org.freemarker/freemarker

  1. @Override
  2. TemplateElement[] accept(Environment env) throws TemplateException, IOException {
  3. final String importedTemplateName = importedTemplateNameExp.evalAndCoerceToPlainText(env);
  4. final String fullImportedTemplateName;
  5. try {
  6. fullImportedTemplateName = env.toFullTemplateName(getTemplate().getName(), importedTemplateName);
  7. } catch (MalformedTemplateNameException e) {
  8. throw new _MiscTemplateException(e, env,
  9. "Malformed template name ", new _DelayedJQuote(e.getTemplateName()), ":\n",
  10. e.getMalformednessDescription());
  11. }
  12. try {
  13. env.importLib(fullImportedTemplateName, targetNsVarName);
  14. } catch (IOException e) {
  15. throw new _MiscTemplateException(e, env,
  16. "Template importing failed (for parameter value ",
  17. new _DelayedJQuote(importedTemplateName),
  18. "):\n", new _DelayedGetMessage(e));
  19. }
  20. return null;
  21. }

代码示例来源:origin: org.freemarker/freemarker

  1. final String fullIncludedTemplateName;
  2. try {
  3. fullIncludedTemplateName = env.toFullTemplateName(getTemplate().getName(), includedTemplateName);
  4. } catch (MalformedTemplateNameException e) {
  5. throw new _MiscTemplateException(e, env,

代码示例来源:origin: org.freemarker/freemarker

  1. absTemplateName = env.toFullTemplateName(env.getCurrentTemplate().getName(), templateName);
  2. } catch (MalformedTemplateNameException e) {
  3. throw new _TemplateModelException(

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.freemarker

  1. /**
  2. * @deprecated Use {@link Environment#toFullTemplateName(String, String)} instead, as that can throw
  3. * {@link MalformedTemplateNameException}, and is on a more logical place anyway.
  4. *
  5. * @throws IllegalArgumentException
  6. * If the {@code baseName} or {@code targetName} is malformed according the {@link TemplateNameFormat}
  7. * in use.
  8. */
  9. @Deprecated
  10. public static String getFullTemplatePath(Environment env, String baseName, String targetName) {
  11. try {
  12. return env.toFullTemplateName(baseName, targetName);
  13. } catch (MalformedTemplateNameException e) {
  14. throw new IllegalArgumentException(e.getMessage());
  15. }
  16. }

代码示例来源:origin: org.freemarker/freemarker-gae

  1. /**
  2. * @deprecated Use {@link Environment#toFullTemplateName(String, String)} instead, as that can throw
  3. * {@link MalformedTemplateNameException}, and is on a more logical place anyway.
  4. *
  5. * @throws IllegalArgumentException
  6. * If the {@code baseName} or {@code targetName} is malformed according the {@link TemplateNameFormat}
  7. * in use.
  8. */
  9. @Deprecated
  10. public static String getFullTemplatePath(Environment env, String baseName, String targetName) {
  11. try {
  12. return env.toFullTemplateName(baseName, targetName);
  13. } catch (MalformedTemplateNameException e) {
  14. throw new IllegalArgumentException(e.getMessage());
  15. }
  16. }

代码示例来源:origin: org.freemarker/freemarker-gae

  1. static Template getTemplate(String systemId) throws IOException {
  2. Environment env = Environment.getCurrentEnvironment();
  3. String encoding = env.getTemplate().getEncoding();
  4. if (encoding == null) {
  5. encoding = env.getConfiguration().getEncoding(env.getLocale());
  6. }
  7. String templatePath = env.getTemplate().getName();
  8. int lastSlash = templatePath.lastIndexOf('/');
  9. templatePath = lastSlash == -1 ? "" : templatePath.substring(0, lastSlash + 1);
  10. systemId = env.toFullTemplateName(templatePath, systemId);
  11. Template raw = env.getConfiguration().getTemplate(systemId, env.getLocale(), encoding, false);
  12. return raw;
  13. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.freemarker

  1. static Template getTemplate(String systemId) throws IOException {
  2. Environment env = Environment.getCurrentEnvironment();
  3. String encoding = env.getTemplate().getEncoding();
  4. if (encoding == null) {
  5. encoding = env.getConfiguration().getEncoding(env.getLocale());
  6. }
  7. String templatePath = env.getTemplate().getName();
  8. int lastSlash = templatePath.lastIndexOf('/');
  9. templatePath = lastSlash == -1 ? "" : templatePath.substring(0, lastSlash + 1);
  10. systemId = env.toFullTemplateName(templatePath, systemId);
  11. Template raw = env.getConfiguration().getTemplate(systemId, env.getLocale(), encoding, false);
  12. return raw;
  13. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.freemarker

  1. /**
  2. * @param basePath Maybe {@code null}
  3. */
  4. private String resolvePath(String basePath) throws TemplateModelException {
  5. try {
  6. return env.rootBasedToAbsoluteTemplateName(env.toFullTemplateName(basePath, pathToResolve));
  7. } catch (MalformedTemplateNameException e) {
  8. throw new _TemplateModelException(e,
  9. "Can't resolve ", new _DelayedJQuote(pathToResolve),
  10. "to absolute template name using base ", new _DelayedJQuote(basePath),
  11. "; see cause exception");
  12. }
  13. }

代码示例来源:origin: org.freemarker/freemarker-gae

  1. /**
  2. * @param basePath Maybe {@code null}
  3. */
  4. private String resolvePath(String basePath) throws TemplateModelException {
  5. try {
  6. return env.rootBasedToAbsoluteTemplateName(env.toFullTemplateName(basePath, pathToResolve));
  7. } catch (MalformedTemplateNameException e) {
  8. throw new _TemplateModelException(e,
  9. "Can't resolve ", new _DelayedJQuote(pathToResolve),
  10. "to absolute template name using base ", new _DelayedJQuote(basePath),
  11. "; see cause exception");
  12. }
  13. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.freemarker

  1. @Override
  2. TemplateElement[] accept(Environment env) throws TemplateException, IOException {
  3. final String importedTemplateName = importedTemplateNameExp.evalAndCoerceToPlainText(env);
  4. final String fullImportedTemplateName;
  5. try {
  6. fullImportedTemplateName = env.toFullTemplateName(getTemplate().getName(), importedTemplateName);
  7. } catch (MalformedTemplateNameException e) {
  8. throw new _MiscTemplateException(e, env,
  9. "Malformed template name ", new _DelayedJQuote(e.getTemplateName()), ":\n",
  10. e.getMalformednessDescription());
  11. }
  12. try {
  13. env.importLib(fullImportedTemplateName, targetNsVarName);
  14. } catch (IOException e) {
  15. throw new _MiscTemplateException(e, env,
  16. "Template importing failed (for parameter value ",
  17. new _DelayedJQuote(importedTemplateName),
  18. "):\n", new _DelayedGetMessage(e));
  19. }
  20. return null;
  21. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.freemarker

  1. absTemplateName = env.toFullTemplateName(env.getCurrentTemplate().getName(), templateName);
  2. } catch (MalformedTemplateNameException e) {
  3. throw new _TemplateModelException(

代码示例来源:origin: org.freemarker/freemarker-gae

  1. final String fullIncludedTemplateName;
  2. try {
  3. fullIncludedTemplateName = env.toFullTemplateName(getTemplate().getName(), includedTemplateName);
  4. } catch (MalformedTemplateNameException e) {
  5. throw new _MiscTemplateException(e, env,

代码示例来源:origin: org.freemarker/freemarker-gae

  1. @Override
  2. TemplateElement[] accept(Environment env) throws TemplateException, IOException {
  3. final String importedTemplateName = importedTemplateNameExp.evalAndCoerceToPlainText(env);
  4. final String fullImportedTemplateName;
  5. try {
  6. fullImportedTemplateName = env.toFullTemplateName(getTemplate().getName(), importedTemplateName);
  7. } catch (MalformedTemplateNameException e) {
  8. throw new _MiscTemplateException(e, env,
  9. "Malformed template name ", new _DelayedJQuote(e.getTemplateName()), ":\n",
  10. e.getMalformednessDescription());
  11. }
  12. try {
  13. env.importLib(fullImportedTemplateName, targetNsVarName);
  14. } catch (IOException e) {
  15. throw new _MiscTemplateException(e, env,
  16. "Template importing failed (for parameter value ",
  17. new _DelayedJQuote(importedTemplateName),
  18. "):\n", new _DelayedGetMessage(e));
  19. }
  20. return null;
  21. }

代码示例来源:origin: org.freemarker/freemarker-gae

  1. absTemplateName = env.toFullTemplateName(env.getCurrentTemplate().getName(), templateName);
  2. } catch (MalformedTemplateNameException e) {
  3. throw new _TemplateModelException(

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.freemarker

  1. final String fullIncludedTemplateName;
  2. try {
  3. fullIncludedTemplateName = env.toFullTemplateName(getTemplate().getName(), includedTemplateName);
  4. } catch (MalformedTemplateNameException e) {
  5. throw new _MiscTemplateException(e, env,

相关文章

Environment类方法