當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。