本文整理匯總了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);
}