当前位置: 首页>>代码示例>>Java>>正文


Java DefaultMustacheFactory.compile方法代码示例

本文整理汇总了Java中com.github.mustachejava.DefaultMustacheFactory.compile方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultMustacheFactory.compile方法的具体用法?Java DefaultMustacheFactory.compile怎么用?Java DefaultMustacheFactory.compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.github.mustachejava.DefaultMustacheFactory的用法示例。


在下文中一共展示了DefaultMustacheFactory.compile方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compile

import com.github.mustachejava.DefaultMustacheFactory; //导入方法依赖的package包/类
/**
 * Compile a template string to (in this case) a Mustache object than can
 * later be re-used for execution to fill in missing parameter values.
 *
 * @param template
 *            a string representing the template to compile.
 * @return a compiled template object for later execution.
 * */
@Override
public Object compile(String template, Map<String, String> params) {
    String contentType = params.get(CONTENT_TYPE_PARAM);
    if (contentType == null) {
        contentType = JSON_CONTENT_TYPE;
    }

    final DefaultMustacheFactory mustacheFactory;
    switch (contentType){
        case PLAIN_TEXT_CONTENT_TYPE:
            mustacheFactory = new NoneEscapingMustacheFactory();
            break;
        case JSON_CONTENT_TYPE:
        default:
            // assume that the default is json encoding:
            mustacheFactory = new JsonEscapingMustacheFactory();
            break;
    }
    mustacheFactory.setObjectHandler(new CustomReflectionObjectHandler());
    Reader reader = new FastStringReader(template);
    return mustacheFactory.compile(reader, "query-template");
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:31,代码来源:MustacheScriptEngineService.java

示例2: createMustache

import com.github.mustachejava.DefaultMustacheFactory; //导入方法依赖的package包/类
/**
 * Read and compile a Mustache template
 *
 * @param resourceReader Reader used to get template
 * @param resourceUri    Template Id
 * @return Template
 */
private Mustache createMustache(Reader resourceReader, String resourceUri) throws IOException {
    ClassLoader oldcl = Thread.currentThread().getContextClassLoader();
    try {
        ClassLoader apcl = getCamelContext().getApplicationContextClassLoader();
        if (apcl != null) {
            Thread.currentThread().setContextClassLoader(apcl);
        }
        Mustache newMustache;
        if (startDelimiter != null && endDelimiter != null && mustacheFactory instanceof DefaultMustacheFactory) {
            DefaultMustacheFactory defaultMustacheFactory = (DefaultMustacheFactory) mustacheFactory;
            newMustache = defaultMustacheFactory.compile(resourceReader, resourceUri, startDelimiter, endDelimiter);
        } else {
            newMustache = mustacheFactory.compile(resourceReader, resourceUri);
        }
        return newMustache;
    } finally {
        resourceReader.close();
        if (oldcl != null) {
            Thread.currentThread().setContextClassLoader(oldcl);
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:30,代码来源:MustacheEndpoint.java

示例3: generateCreateTable

import com.github.mustachejava.DefaultMustacheFactory; //导入方法依赖的package包/类
public String generateCreateTable(String schemaName, ScrapeTemplate template) throws IOException {
        final CreateTableData createTableData = new CreateTableData();
        template.getCollections().forEach(collDef -> {
            final PropertyDef idProp = collDef.getProperties().stream()
                    .filter(it -> it.getId().equals(collDef.getIdProperty())).findAny().get();
//            final PropertyDef nameProp = collDef.getProperties().stream()
//                    .filter(it -> it.getId().equals(collDef.getNameProperty())).findAny().get();
            final Table table = new Table(schemaName, collDef.getId(), kindToSqlType(idProp.getKind(), idProp.getCardinality()));
            for (final PropertyDef propDef : collDef.getProperties()) {
                if (collDef.getIdProperty().equals(propDef.getId())) {
                    continue;
                }
                if (collDef.getNameProperty().equals(propDef.getId())) {
                    continue;
                }
                table.columns.add(new Column(propDef.getId(), kindToSqlType(propDef.getKind(), Cardinality.SINGLE)));
            }
            createTableData.tables.add(table);
        });

        final DefaultMustacheFactory mustacheFactory = new DefaultMustacheFactory("org/soluvas/scrape/core/sql");
        // TODO: TableDdlGenerator should generate CREATE INDEXes #5
        final Mustache mustache = mustacheFactory.compile("create_table.sql.mustache");
        try (StringWriter sw = new StringWriter()) {
            mustache.execute(sw, createTableData);
            return sw.toString();
        }
    }
 
开发者ID:soluvas,项目名称:soluvas-scrape,代码行数:29,代码来源:TableDdlGenerator.java

示例4: loadTemplate

import com.github.mustachejava.DefaultMustacheFactory; //导入方法依赖的package包/类
private static Mustache loadTemplate(final String name) {
    try {
        final DefaultMustacheFactory factory = new DefaultMustacheFactory();
        return factory.compile(new InputStreamReader(Analyzer.class.getResource(name)
                .openStream(), Charsets.UTF_8), name);
    } catch (final IOException ex) {
        throw new Error(ex);
    }
}
 
开发者ID:dkmfbk,项目名称:pikes,代码行数:10,代码来源:Analyzer.java

示例5: createTemplate

import com.github.mustachejava.DefaultMustacheFactory; //导入方法依赖的package包/类
private static Mustache createTemplate(File template, Charset charset) throws MojoFailureException {
    DefaultMustacheFactory mf = new DefaultMustacheFactory();
    Mustache mustache;
    try (Reader reader = new InputStreamReader(new FileInputStream(template), charset)) {
        mustache = mf.compile(reader, "template");
    } catch (IOException e) {
        throw new MojoFailureException(e, "Cannot open template", "Cannot open template");
    }
    return mustache;
}
 
开发者ID:wouterd,项目名称:mustache-maven-plugin,代码行数:11,代码来源:MustacheMojo.java

示例6: ChangeLogWriter

import com.github.mustachejava.DefaultMustacheFactory; //导入方法依赖的package包/类
public ChangeLogWriter(String template, Log log) {
    this.log = log;

    final DefaultMustacheFactory mustacheFactory = new DefaultMustacheFactory();
    mustache = mustacheFactory.compile(template);
}
 
开发者ID:jakubplichta,项目名称:git-changelog-maven-plugin,代码行数:7,代码来源:ChangeLogWriter.java

示例7: HtmlPage

import com.github.mustachejava.DefaultMustacheFactory; //导入方法依赖的package包/类
public HtmlPage(String name, String templateRes) throws IOException {
  mFactory = new DefaultMustacheFactory();
  String template = IOUtil.loadResAsString(templateRes) ;
  mustacheTmpl = mFactory.compile(new StringReader(template), name);
}
 
开发者ID:DemandCube,项目名称:NeverwinterDP-Commons,代码行数:6,代码来源:HtmlPage.java

示例8: getView

import com.github.mustachejava.DefaultMustacheFactory; //导入方法依赖的package包/类
@Override
public View getView(String viewName, ResourceLoader resourceLoader) throws Exception {
	String filename = filename(viewName);

	if (resourceLoader.load(filename) == null) return null;

	DefaultMustacheFactory mf = getViewFactory(resourceLoader);

	Mustache mustache = mf.compile(filename);

	return view(mustache);
}
 
开发者ID:rapidoid,项目名称:rapidoid,代码行数:13,代码来源:MustacheJavaViewResolver.java


注:本文中的com.github.mustachejava.DefaultMustacheFactory.compile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。