Java Code Examples for freemarker.template.Configuration#setLogTemplateExceptions()

The following examples show how to use freemarker.template.Configuration#setLogTemplateExceptions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FreemarkerEngine.java    From helidon-build-tools with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new instance of {@link FreemarkerEngine}.
 * @param backend the backend name
 * @param directives custom directives to register
 * @param model some model attributes to set for each rendering invocation
 */
public FreemarkerEngine(String backend,
                        Map<String, String> directives,
                        Map<String, String> model) {
    checkNonNullNonEmpty(backend, BACKEND_PROP);
    this.backend = backend;
    this.directives = directives == null ? Collections.emptyMap() : directives;
    this.model = model == null ? Collections.emptyMap() : model;
    freemarker = new Configuration(FREEMARKER_VERSION);
    freemarker.setTemplateLoader(new TemplateLoader());
    freemarker.setDefaultEncoding(DEFAULT_ENCODING);
    freemarker.setObjectWrapper(OBJECT_WRAPPER);
    freemarker.setTemplateExceptionHandler(
            TemplateExceptionHandler.RETHROW_HANDLER);
    freemarker.setLogTemplateExceptions(false);
}
 
Example 2
Source File: CCDAExporter.java    From synthea with Apache License 2.0 6 votes vote down vote up
private static Configuration templateConfiguration() {
  Configuration configuration = new Configuration(Configuration.VERSION_2_3_26);
  configuration.setDefaultEncoding("UTF-8");
  configuration.setLogTemplateExceptions(false);
  try {
    configuration.setSetting("object_wrapper",
        "DefaultObjectWrapper(2.3.26, forceLegacyNonListCollections=false, "
            + "iterableSupport=true, exposeFields=true)");
  } catch (TemplateException e) {
    e.printStackTrace();
  }
  configuration.setAPIBuiltinEnabled(true);
  configuration.setClassLoaderForTemplateLoading(ClassLoader.getSystemClassLoader(),
      "templates/ccda");
  return configuration;
}
 
Example 3
Source File: ClinicalNoteExporter.java    From synthea with Apache License 2.0 6 votes vote down vote up
private static Configuration templateConfiguration() {
  Configuration configuration = new Configuration(Configuration.VERSION_2_3_26);
  configuration.setDefaultEncoding("UTF-8");
  configuration.setLogTemplateExceptions(false);
  try {
    configuration.setSetting("object_wrapper",
        "DefaultObjectWrapper(2.3.26, forceLegacyNonListCollections=false, "
            + "iterableSupport=true, exposeFields=true)");
  } catch (TemplateException e) {
    e.printStackTrace();
  }
  configuration.setAPIBuiltinEnabled(true);
  configuration.setClassLoaderForTemplateLoading(ClassLoader.getSystemClassLoader(),
      "templates/notes");
  return configuration;
}
 
Example 4
Source File: FreemarkerRenderer.java    From act with GNU General Public License v3.0 6 votes vote down vote up
private void init(String dbHost, Integer dbPort, String dbName, String dnaCollection, String pathwayCollection) throws IOException {
  cfg = new Configuration(Configuration.VERSION_2_3_23);

  cfg.setClassLoaderForTemplateLoading(
      this.getClass().getClassLoader(), "/act/installer/reachablesexplorer/templates");
  cfg.setDefaultEncoding("UTF-8");

  cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  cfg.setLogTemplateExceptions(true);

  reachableTemplate = cfg.getTemplate(reachableTemplateName);
  pathwayTemplate = cfg.getTemplate(pathwayTemplateName);

  // TODO: move this elsewhere.
  MongoClient client = new MongoClient(new ServerAddress(dbHost, dbPort));
  DB db = client.getDB(dbName);

  dnaDesignCollection = JacksonDBCollection.wrap(db.getCollection(dnaCollection), DNADesign.class, String.class);
  Cascade.setCollectionName(pathwayCollection);
}
 
Example 5
Source File: FreemarkerTemplateEngineFactory.java    From gocd with Apache License 2.0 6 votes vote down vote up
@Override
public void afterPropertiesSet() {
    Configuration configuration = new Configuration(Configuration.VERSION_2_3_28);
    configuration.setDefaultEncoding("utf-8");
    configuration.setLogTemplateExceptions(true);
    configuration.setNumberFormat("computer");
    configuration.setOutputFormat(XHTMLOutputFormat.INSTANCE);
    configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    configuration.setTemplateLoader(new SpringTemplateLoader(this.resourceLoader, this.resourceLoaderPath));

    if (this.shouldCheckForTemplateModifications) {
        configuration.setTemplateUpdateDelayMilliseconds(1000);
    } else {
        configuration.setTemplateUpdateDelayMilliseconds(Long.MAX_VALUE);
    }

    this.configuration = configuration;
}
 
Example 6
Source File: FreemarkerTransformer.java    From tutorials with MIT License 5 votes vote down vote up
public String html() throws IOException, TemplateException {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_29);
    cfg.setDirectoryForTemplateLoading(new File(templateDirectory));
    cfg.setDefaultEncoding(StandardCharsets.UTF_8.toString());
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setLogTemplateExceptions(false);
    cfg.setWrapUncheckedExceptions(true);
    cfg.setFallbackOnNullLoopVariable(false);
    Template temp = cfg.getTemplate(templateFile);
    try (Writer output = new StringWriter()) {
        temp.process(staxTransformer.getMap(), output);
        return output.toString();
    }
}
 
Example 7
Source File: DetectBootFactory.java    From synopsys-detect with Apache License 2.0 5 votes vote down vote up
public Configuration createConfiguration() {
    final Configuration configuration = new Configuration(Configuration.VERSION_2_3_26);
    configuration.setClassForTemplateLoading(Application.class, "/");
    configuration.setDefaultEncoding("UTF-8");
    configuration.setLogTemplateExceptions(true);

    return configuration;
}
 
Example 8
Source File: PreprocessorImpl.java    From maven-confluence-plugin with Apache License 2.0 5 votes vote down vote up
public PreprocessorImpl() {
    cfg = new Configuration(VERSION);
    cfg.setDefaultEncoding(StandardCharsets.UTF_8.name());
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setLogTemplateExceptions(false);
    cfg.setWrapUncheckedExceptions(true);
    cfg.setFallbackOnNullLoopVariable(false);
}
 
Example 9
Source File: ViewBuilder.java    From docker-elastic-agents-plugin with Apache License 2.0 5 votes vote down vote up
private ViewBuilder() {
    configuration = new Configuration(Configuration.VERSION_2_3_23);
    configuration.setTemplateLoader(new ClassTemplateLoader(getClass(), "/"));
    configuration.setDefaultEncoding("UTF-8");
    configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    configuration.setLogTemplateExceptions(false);
    configuration.setDateTimeFormat("iso");
}
 
Example 10
Source File: PluginStatusReportViewBuilder.java    From docker-swarm-elastic-agent-plugin with Apache License 2.0 5 votes vote down vote up
private PluginStatusReportViewBuilder() {
    configuration = new Configuration(Configuration.VERSION_2_3_23);
    configuration.setTemplateLoader(new ClassTemplateLoader(getClass(), "/"));
    configuration.setDefaultEncoding("UTF-8");
    configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    configuration.setLogTemplateExceptions(false);
    configuration.setDateTimeFormat("iso");
}
 
Example 11
Source File: ObjectRenderer.java    From Repeat with Apache License 2.0 5 votes vote down vote up
public ObjectRenderer(File templateDir) {
	config = new Configuration(Configuration.VERSION_2_3_28);
	try {
		config.setDirectoryForTemplateLoading(templateDir);
	} catch (IOException e) {
		LOGGER.log(Level.SEVERE, "Error setting template directory to " + templateDir.getAbsolutePath(), e);
	}
	config.setDefaultEncoding("UTF-8");
	config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
	config.setLogTemplateExceptions(false);
	config.setWrapUncheckedExceptions(true);
}
 
Example 12
Source File: Templates.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static Configuration createConfiguration() {
  Configuration configuration = new Configuration(Configuration.VERSION_2_3_25);
  configuration.setClassForTemplateLoading(Templates.class, "/templates/appengine");
  configuration.setDefaultEncoding(StandardCharsets.UTF_8.name());
  configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  configuration.setLogTemplateExceptions(false);
  return configuration;
}
 
Example 13
Source File: BootFactory.java    From hub-detect with Apache License 2.0 5 votes vote down vote up
public Configuration createConfiguration() {
    final Configuration configuration = new Configuration(Configuration.VERSION_2_3_26);
    configuration.setClassForTemplateLoading(Application.class, "/");
    configuration.setDefaultEncoding("UTF-8");
    configuration.setLogTemplateExceptions(true);

    return configuration;
}
 
Example 14
Source File: FreemarkerServiceImpl.java    From jframe with Apache License 2.0 5 votes vote down vote up
private Configuration createConfiguration(String id) throws IOException {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
    File dir = new File(_conf.getConf(id, FtlPropsConf.P_ftl_dir));
    dir.mkdirs();
    cfg.setDirectoryForTemplateLoading(dir);
    cfg.setDefaultEncoding(_conf.getConf(id, FtlPropsConf.P_ftl_encoding, "UTF-8"));
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setLogTemplateExceptions(false);
    return cfg;
}
 
Example 15
Source File: FreemarkerTemplatingService.java    From blackduck-alert with Apache License 2.0 5 votes vote down vote up
private Configuration createDefaultConfiguration() {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);

    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
    cfg.setLogTemplateExceptions(false);

    return cfg;
}
 
Example 16
Source File: PluginStatusReportViewBuilder.java    From kubernetes-elastic-agents with Apache License 2.0 5 votes vote down vote up
private PluginStatusReportViewBuilder() {
    configuration = new Configuration(Configuration.VERSION_2_3_23);
    configuration.setTemplateLoader(new ClassTemplateLoader(getClass(), "/"));
    configuration.setDefaultEncoding("UTF-8");
    configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    configuration.setLogTemplateExceptions(false);
    configuration.setDateTimeFormat("iso");
}
 
Example 17
Source File: AbstractRunningGenerator.java    From skywalking with Apache License 2.0 5 votes vote down vote up
protected AbstractRunningGenerator() {
    cfg = new Configuration(Configuration.VERSION_2_3_28);
    try {
        cfg.setClassLoaderForTemplateLoading(this.getClass().getClassLoader(), "/");
        cfg.setDefaultEncoding("UTF-8");
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
        cfg.setLogTemplateExceptions(false);
        cfg.setWrapUncheckedExceptions(true);
    } catch (Exception e) {
        // never to do this
    }
}
 
Example 18
Source File: ConfigurationExporterTest.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
static String renderDocumentation(ConfigurationRegistry configurationRegistry) throws IOException, TemplateException {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_27);
    cfg.setClassLoaderForTemplateLoading(ConfigurationExporterTest.class.getClassLoader(), "/");
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setLogTemplateExceptions(false);

    Template temp = cfg.getTemplate("configuration.asciidoc.ftl");
    StringWriter tempRenderedFile = new StringWriter();
    tempRenderedFile.write("////\n" +
        "This file is auto generated\n" +
        "\n" +
        "Please only make changes in configuration.asciidoc.ftl\n" +
        "////\n");
    final List<ConfigurationOption<?>> nonInternalOptions = configurationRegistry.getConfigurationOptionsByCategory()
        .values()
        .stream()
        .flatMap(List::stream)
        .filter(option -> !option.getTags().contains("internal"))
        .collect(Collectors.toList());
    final Map<String, List<ConfigurationOption<?>>> optionsByCategory = nonInternalOptions.stream()
        .collect(Collectors.groupingBy(ConfigurationOption::getConfigurationCategory, TreeMap::new, Collectors.toList()));
    temp.process(Map.of(
        "config", optionsByCategory,
        "keys", nonInternalOptions.stream().map(ConfigurationOption::getKey).sorted().collect(Collectors.toList())
    ), tempRenderedFile);

    // re-process the rendered template to resolve the ${allInstrumentationGroupNames} placeholder
    StringWriter out = new StringWriter();
    new Template("", tempRenderedFile.toString(), cfg)
        .process(Map.of("allInstrumentationGroupNames", getAllInstrumentationGroupNames()), out);

    return out.toString();
}
 
Example 19
Source File: TimeStepRunnerCodeGenerator.java    From hazelcast-simulator with Apache License 2.0 4 votes vote down vote up
private JavaFileObject createJavaFileObject(
        String className,
        String executionGroup,
        Class<? extends Metronome> metronomeClass,
        TimeStepModel timeStepModel,
        Class<? extends Probe> probeClass,
        long logFrequency,
        long logRateMs,
        boolean hasIterationCap) {
    try {
        Configuration cfg = new Configuration(Configuration.VERSION_2_3_24);
        cfg.setClassForTemplateLoading(this.getClass(), "/");
        cfg.setDefaultEncoding("UTF-8");
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
        cfg.setLogTemplateExceptions(false);

        Map<String, Object> root = new HashMap<>();
        root.put("testInstanceClass", getClassName(timeStepModel.getTestClass()));
        root.put("metronomeClass", getMetronomeClass(metronomeClass));
        root.put("timeStepMethods", timeStepModel.getActiveTimeStepMethods(executionGroup));
        root.put("probeClass", getClassName(probeClass));
        root.put("isStartNanos", new IsStartNanos(timeStepModel));
        root.put("isAssignableFrom", new IsAssignableFromMethod());
        root.put("isAsyncResult", new IsAsyncResult());
        root.put("Probe", Probe.class);
        root.put("threadStateClass", getClassName(timeStepModel.getThreadStateClass(executionGroup)));
        root.put("hasProbe", new HasProbeMethod());
        root.put("className", className);
        if (logFrequency > 0) {
            root.put("logFrequency", "" + logFrequency);
        }

        if (logRateMs > 0) {
            root.put("logRateMs", "" + logRateMs);
        }

        if (hasIterationCap) {
            root.put("hasIterationCap", "true");
        }

        Template temp = cfg.getTemplate("TimeStepRunner.ftl");
        StringWriter out = new StringWriter();
        temp.process(root, out);

        String javaCode = out.toString();
        File javaFile = new File(targetDirectory, className + ".java");

        writeText(javaCode, javaFile);

        return new JavaSourceFromString(className, javaCode);
    } catch (Exception e) {
        throw new IllegalTestException(className + " ran into a code generation problem: " + e.getMessage(), e);
    }
}
 
Example 20
Source File: GeneratePDFWorkitemHandler.java    From jbpm-work-items with Apache License 2.0 4 votes vote down vote up
public void executeWorkItem(WorkItem workItem,
                            WorkItemManager workItemManager) {

    try {

        RequiredParameterValidator.validate(this.getClass(),
                                            workItem);

        Map<String, Object> results = new HashMap<>();
        String templateXHTML = (String) workItem.getParameter("TemplateXHTML");
        String pdfName = (String) workItem.getParameter("PDFName");

        if (pdfName == null || pdfName.isEmpty()) {
            pdfName = "generatedpdf";
        }

        Configuration cfg = new Configuration(freemarker.template.Configuration.VERSION_2_3_26);
        cfg.setDefaultEncoding("UTF-8");
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
        cfg.setLogTemplateExceptions(false);

        StringTemplateLoader stringLoader = new StringTemplateLoader();
        stringLoader.putTemplate("pdfTemplate",
                                 templateXHTML);
        cfg.setTemplateLoader(stringLoader);

        StringWriter stringWriter = new StringWriter();

        Template pdfTemplate = cfg.getTemplate("pdfTemplate");
        pdfTemplate.process(workItem.getParameters(),
                            stringWriter);
        resultXHTML = stringWriter.toString();

        ITextRenderer renderer = new ITextRenderer();
        renderer.setDocumentFromString(resultXHTML);
        renderer.layout();

        Document document = new DocumentImpl();
        document.setName(pdfName + ".pdf");
        document.setLastModified(new Date());

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        renderer.createPDF(baos);
        document.setContent(baos.toByteArray());

        results.put(RESULTS_VALUE,
                    document);

        workItemManager.completeWorkItem(workItem.getId(),
                                         results);
    } catch (Exception e) {
        logger.error(e.getMessage());
        handleException(e);
    }
}