public static TemplateSource create()

in freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/util/TemplateSourceFactory.java [32:49]


    public static TemplateSource create(TemplateSourceDefinition templateSourceDefinition, Charset charset) {
        Validate.notNull(templateSourceDefinition, "templateSourceDefinition must not be null");
        Validate.notNull(charset, "charset must not be null");

        final String template = templateSourceDefinition.template;
        final DataSourceLoader dataSourceLoader = DataSourceLoaderFactory.create();

        if (templateSourceDefinition.isInteractiveTemplate()) {
            return TemplateSource.fromCode(Location.INTERACTIVE, templateSourceDefinition.interactiveTemplate);
        } else if (new File(template).exists()) {
            final String templateSource = templateSourceDefinition.template;
            try (DataSource dataSource = dataSourceLoader.load(templateSource)) {
                return TemplateSource.fromCode(dataSource.getName(), dataSource.getText(charset.name()));
            }
        } else {
            return TemplateSource.fromPath(template, charset);
        }
    }