Ejemplo n.º 1
0
  /**
   * Invoked on startup. Looks for a single FreeMarkerConfig bean to find the relevant Configuration
   * for this factory.
   *
   * <p>Checks that the template for the default Locale can be found: FreeMarker will check
   * non-Locale-specific templates if a locale-specific one is not found.
   *
   * @see freemarker.cache.TemplateCache#getTemplate
   */
  protected void initApplicationContext() throws BeansException {
    super.initApplicationContext();

    if (getConfiguration() == null) {
      FreeMarkerConfig config = autodetectConfiguration();
      setConfiguration(config.getConfiguration());
    }
    checkTemplate();
  }
 public WidgetView resolve(Object viewName, Locale locale) throws Exception {
   if (viewName instanceof String) {
     String viewPath = getViewPath((String) viewName);
     Template template = freeMarkerConfig.getConfiguration().getTemplate(viewPath, locale);
     //
     return new DefaultWidgetView(template);
   }
   //
   throw new NullPointerException("WidgetView not found!");
 }
Ejemplo n.º 3
0
  public String resolvedAsHtml(Map<String, Object> parameterMap) {
    if (parameterMap == null || parameterMap.get("templateContent") == null) {
      return null;
    }
    try {

      String templateContent = parameterMap.get("templateContent").toString();

      StringWriter writer = new StringWriter();
      new freemarker.template.Template(
              "", new StringReader(templateContent), freemarkerConfig.getConfiguration())
          .process(parameterMap, writer);
      return writer.toString();
    } catch (Exception e) {
      return null;
    }
  }
  @Bean
  public freemarker.template.Configuration freeMarkerConfiguration(FreeMarkerConfig configurer) {
    if (logger.isDebugEnabled()) logger.debug("");

    return configurer.getConfiguration();
  }