當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultMustacheFactory類代碼示例

本文整理匯總了Java中com.github.mustachejava.DefaultMustacheFactory的典型用法代碼示例。如果您正苦於以下問題:Java DefaultMustacheFactory類的具體用法?Java DefaultMustacheFactory怎麽用?Java DefaultMustacheFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DefaultMustacheFactory類屬於com.github.mustachejava包,在下文中一共展示了DefaultMustacheFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: announce

import com.github.mustachejava.DefaultMustacheFactory; //導入依賴的package包/類
private String announce(NuclearStream stream, List<String> responseList, Map<String, String> context) {
    String response = responseList.get(RandomUtils.nextInt(0, responseList.size()));
    if (context == null) {
        announcePresenter.announce(stream.getPublisher().getId(), response, true, false);
    } else {
        MustacheFactory mf = new DefaultMustacheFactory();
        Mustache mustache = mf.compile(new StringReader(response), "response");
        try {
            StringWriter writer = new StringWriter();
            mustache.execute(writer, context).flush();
            response = writer.toString();
            announcePresenter.announce(stream.getPublisher().getId(), response, true, false);
        } catch (IOException e) {
            log.warn("Could not create response", e);
        }
    }
    return response;
}
 
開發者ID:quanticc,項目名稱:ugc-bot-redux,代碼行數:19,代碼來源:NuclearService.java

示例2: 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

示例3: initialize

import com.github.mustachejava.DefaultMustacheFactory; //導入依賴的package包/類
public void initialize(String mustacheTemplate)
        throws IOException
{
    InputStream stream = this.getClass().getClassLoader().getResourceAsStream(mustacheTemplate);
    if (stream == null) {
        throw new FileNotFoundException("Resource not found: " + mustacheTemplate);
    }

    // compile template
    MustacheFactory mf = new DefaultMustacheFactory();
    Reader reader = new InputStreamReader(stream, "utf-8");
    mustache = mf.compile(reader, "template");

    // output path
    if (!outputPath.exists()) {
        outputPath.mkdirs();
    }
}
 
開發者ID:UKPLab,項目名稱:argument-reasoning-comprehension-task,代碼行數:19,代碼來源:AbstractHITCreator.java

示例4: main

import com.github.mustachejava.DefaultMustacheFactory; //導入依賴的package包/類
public static void main(String[] args) {
    System.out.println("Starting executor");

    if (new File("config").mkdir()) {
        System.out.println("Created config directory");
    }

    MustacheFactory mustacheFactory = new DefaultMustacheFactory();
    final Mustache filebeatMustache = mustacheFactory.compile("filebeat.yaml.mustache");
    final Mustache metricbeatMustache = mustacheFactory.compile("metricbeat.yaml.mustache");
    try {
        MesosExecutorDriver driver = new MesosExecutorDriver(new HumioExecutor(filebeatMustache, metricbeatMustache));
        final Protos.Status status = driver.run();

        System.out.println("status = " + status);
        if (status.equals(Protos.Status.DRIVER_STOPPED)) {
            System.exit(0);
        } else {
            System.err.println("Error: " + status);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:humio,項目名稱:dcos2humio,代碼行數:25,代碼來源:ExecutorApplication.java

示例5: handleRequest

import com.github.mustachejava.DefaultMustacheFactory; //導入依賴的package包/類
public String handleRequest(String name, Context context) {
    String responseLanguage = Optional.ofNullable(System.getenv("language")).orElse(DEFAULT_LANGUAGE);

    Mustache mustache = new DefaultMustacheFactory().compile("hellopage.mustache");

    String envVersion = Optional.ofNullable(context.getFunctionVersion()).orElse("no-alias");
    String functionName = Optional.ofNullable(context.getFunctionName()).orElse("default-name");
    String arnName = Optional.ofNullable(context.getInvokedFunctionArn()).orElse("default-arn");

    String response = "Hello " + name + " from version: " + envVersion + " of " + functionName + " with arn: " + arnName;

    HelloResponse responseData = new HelloResponse(responseLanguage, response);
    StringWriter stringWriter = new StringWriter();

    try {
        mustache.execute(stringWriter, responseData).flush();
    } catch (IOException e) {
        stringWriter.append("Failed to execute mustache template and flush output");
    }

    return stringWriter.toString();
}
 
開發者ID:willh,項目名稱:lambda-helloworld-config,代碼行數:23,代碼來源:HelloWorldMicroservice.java

示例6: init

import com.github.mustachejava.DefaultMustacheFactory; //導入依賴的package包/類
private void init()
{
  String templatePath = _config.get("view.mustache.templates",
                                    "classpath:/templates");

  MustacheResolver resolver;

  if (templatePath.startsWith("classpath:")) {
    String root = templatePath.substring("classpath:".length());

    resolver = new ClasspathResolver(root);

    //ClassLoader loader = Thread.currentThread().getContextClassLoader();
    //resolver = new MustacheResolverImpl(loader, root);
  }
  else {
    resolver = new DefaultResolver(templatePath);
  }

  MustacheFactory factory = new DefaultMustacheFactory(resolver);

  _factory = factory;
}
 
開發者ID:baratine,項目名稱:baratine,代碼行數:24,代碼來源:ViewMustache.java

示例7: getTemplate

import com.github.mustachejava.DefaultMustacheFactory; //導入依賴的package包/類
public static String getTemplate(PXContext pxContext, PXConfiguration pxConfig, String template) throws PXException {
    try {
        // In case of challenge
        if (pxContext.getBlockAction().equals("challenge") && pxContext.getBlockActionData() != null) {
            return pxContext.getBlockActionData();
        }

        Map<String, String> props = getProps(pxContext, pxConfig);
        MustacheFactory mf = new DefaultMustacheFactory();
        Mustache m = mf.compile((getTemplate(template)), (getTemplate(template)).toString());
        StringWriter sw = new StringWriter();
        m.execute(sw, props).close();
        return sw.toString();
    } catch (IOException e) {
        throw new PXException(e);
    }

}
 
開發者ID:PerimeterX,項目名稱:perimeterx-java-sdk,代碼行數:19,代碼來源:TemplateFactory.java

示例8: 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

示例9: buildPluginOutput

import com.github.mustachejava.DefaultMustacheFactory; //導入依賴的package包/類
private static void buildPluginOutput(File input) throws IOException {
    String name = parseName(input.getName());

    Dep dep = parseDep(input);
    String url = dep.toUrl(MAVEN2);
    if (testURL(url)) {
        System.out.println("URL is good: " + url);
    } else {
        throw new IOException("Invalid URL: " + url + " for dep " + dep);
    }

    HashMap<String, Object> scopes = new HashMap<String, Object>();
    scopes.put("name", name);
    scopes.put("url", url);
    scopes.put("version", (dep.version!=null)?dep.version:dep.rev);
    scopes.put("date", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
    scopes.put("md5", getUrlAsString(url + ".md5"));

    Writer writer = new OutputStreamWriter(new FileOutputStream(new File(dirOut, name+".xml")));
    MustacheFactory mf = new DefaultMustacheFactory();
    Mustache mustache = mf.compile(new StringReader(template), "template");
    mustache.execute(writer, scopes);
    writer.flush();
    writer.close();
}
 
開發者ID:OpenSageTV,項目名稱:sagetv-plugin-repo,代碼行數:26,代碼來源:BuildLibraries.java

示例10: displaySummary

import com.github.mustachejava.DefaultMustacheFactory; //導入依賴的package包/類
@Override
public void displaySummary(long numFiles, long numSkipped, long numErrors, long numWarnings) throws IOException {
    Map<String, Object> output = new HashMap<>();
    output.put(Messages.SUMMARY_KEY,
        Formatter.formatSummary(numFiles, numSkipped, numErrors, numWarnings).replace(NEWLINE_PATTERN, ""));
    // Sort files by descending order of the number of violations
    FILES.sort((o1, o2) ->
        ((List) o2.get(Messages.VIOLATIONS_KEY)).size() - ((List) o1.get(Messages.VIOLATIONS_KEY)).size());
    output.put(Messages.FILES_KEY, FILES);
    output.put(Messages.VERSION_LONG_OPT, new ConfigProperties().getVersion());

    InputStreamReader inputStreamReader = new InputStreamReader(
        HTMLFormatter.class.getResourceAsStream(TEMPLATE_PATH),
        Charset.defaultCharset());
    Mustache mustache = new DefaultMustacheFactory().compile(inputStreamReader, TEMPLATE_PATH);
    mustache.execute(new OutputStreamWriter(System.out, Charset.defaultCharset()), output).flush();
    inputStreamReader.close();
}
 
開發者ID:sleekbyte,項目名稱:tailor,代碼行數:19,代碼來源:HTMLFormatter.java

示例11: writeFile

import com.github.mustachejava.DefaultMustacheFactory; //導入依賴的package包/類
private void writeFile(String headTemplateFile) {
	try {

		Reader reader = new FileReader(new File(headTemplateFile));

		log.debug(headTemplateFile);
		File outputFile = new File(headTemplateFile.split("template")[0] + "html");

		Writer writer = new FileWriter(outputFile);

		MustacheFactory mf = new DefaultMustacheFactory();
		Mustache mustache = mf.compile(reader, "example");
		mustache.execute(writer, templates);
		writer.flush();

		log.debug(Tools.readFile(outputFile.getAbsolutePath()));

	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
開發者ID:dessalines,項目名稱:referendum,代碼行數:22,代碼來源:WriteHTMLFiles.java

示例12: doExport

import com.github.mustachejava.DefaultMustacheFactory; //導入依賴的package包/類
private void doExport(MustachePojoWrapper mustachePojoWrapper) {
    MustacheFactory mf = new DefaultMustacheFactory();

    // enrich repo information
    mustachePojoWrapper.repoOwner = repoOwner;
    mustachePojoWrapper.repoName = repoName;

    try {


        for (String curTemplate : templates) {
            //TODO remove this hack!
            String reportFileName = curTemplate.replaceAll("/templates", "");

            System.out.println(">>>>>> write template " + curTemplate + " >> to >> " + reportFileName);

            Mustache curMustache = mf.compile(curTemplate);

            curMustache.execute(new PrintWriter(new File(reportFileName)), mustachePojoWrapper).flush();
            //curMustache.execute(new PrintWriter(System.out), new NonseneWrapper(issueEvents)).flush();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

}
 
開發者ID:stola3,項目名稱:github-issue-events-report,代碼行數:27,代碼來源:GitHubEventsReport.java

示例13: setup

import com.github.mustachejava.DefaultMustacheFactory; //導入依賴的package包/類
@Setup
public void setup() {
    MustacheFactory mustacheFactory = new DefaultMustacheFactory() {

        @Override
        public void encode(String value, Writer writer) {
            // Disable HTML escaping
            try {
                writer.write(value);
            } catch (IOException e) {
                throw new MustacheException(e);
            }
        }
    };
    template = mustacheFactory.compile("templates/stocks.mustache.html");
}
 
開發者ID:mbosecke,項目名稱:template-benchmark,代碼行數:17,代碼來源:Mustache.java

示例14: getTemplate

import com.github.mustachejava.DefaultMustacheFactory; //導入依賴的package包/類
@Override
public Template getTemplate(String templateName) {
    try {
        MustacheFactory mf = new DefaultMustacheFactory();
        final Mustache mustache = mf.compile(new StringReader(Templates.loadTemplate(templateName, resourceManager)), templateName);

        return new Template() {
            @Override
            public String apply(Object data) {
                final StringWriter stringWriter = new StringWriter();
                mustache.execute(stringWriter, data);
                return stringWriter.getBuffer().toString();
            }
        };
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:undertow-io,項目名稱:undertow.js,代碼行數:19,代碼來源:MustacheTemplateProvider.java

示例15: render

import com.github.mustachejava.DefaultMustacheFactory; //導入依賴的package包/類
/**
 * Get the changelog.
 *
 * @throws GitChangelogRepositoryException
 */
public void render(final Writer writer) throws GitChangelogRepositoryException {
  final MustacheFactory mf = new DefaultMustacheFactory();
  final String templateContent = checkNotNull(getTemplateContent(), "No template!");
  final StringReader reader = new StringReader(templateContent);
  final Mustache mustache = mf.compile(reader, this.settings.getTemplatePath());
  try {
    final boolean useIntegrationIfConfigured = shouldUseIntegrationIfConfigured(templateContent);
    final Changelog changelog = this.getChangelog(useIntegrationIfConfigured);
    mustache
        .execute(
            writer, //
            new Object[] {changelog, this.settings.getExtendedVariables()} //
            )
        .flush();
  } catch (final IOException e) {
    // Should be impossible!
    throw new GitChangelogRepositoryException("", e);
  }
}
 
開發者ID:tomasbjerre,項目名稱:git-changelog-lib,代碼行數:25,代碼來源:GitChangelogApi.java


注:本文中的com.github.mustachejava.DefaultMustacheFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。