本文整理汇总了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");
}
示例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);
}
}
}
示例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();
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}