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


Java Template.execute方法代码示例

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


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

示例1: renderInternal

import com.samskivert.mustache.Template; //导入方法依赖的package包/类
@Override
protected Mono<Void> renderInternal(Map<String, Object> model, MediaType contentType,
                                    ServerWebExchange exchange) {
    Resource resource = resolveResource();
    if (resource == null) {
        return Mono.error(new IllegalStateException(
                "Could not find Mustache template with URL [" + getUrl() + "]"));
    }
    DataBuffer dataBuffer = exchange.getResponse().bufferFactory().allocateBuffer();
    try (Reader reader = getReader(resource)) {
        Template template = this.compiler.compile(reader);
        Charset charset = getCharset(contentType).orElse(getDefaultCharset());
        try (Writer writer = new OutputStreamWriter(dataBuffer.asOutputStream(),
                charset)) {
            template.execute(model, writer);
            writer.flush();
        }
    }
    catch (Exception ex) {
        DataBufferUtils.release(dataBuffer);
        return Mono.error(ex);
    }
    return exchange.getResponse().writeWith(Flux.just(dataBuffer));
}
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:25,代码来源:MustacheView.java

示例2: testMustasche

import com.samskivert.mustache.Template; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testMustasche() throws IOException {
	Yaml yaml = new Yaml();
	Map model = (Map) yaml.load(valuesResource.getInputStream());
	String templateAsString = StreamUtils.copyToString(nestedMapResource.getInputStream(),
			Charset.defaultCharset());
	Template mustacheTemplate = Mustache.compiler().compile(templateAsString);
	String resolvedYml = mustacheTemplate.execute(model);
	Map map = (Map) yaml.load(resolvedYml);

	logger.info("Resolved yml = " + resolvedYml);
	assertThat(map).containsKeys("apiVersion", "deployment");
	Map deploymentMap = (Map) map.get("deployment");
	assertThat(deploymentMap).contains(entry("name", "time"))
			.contains(entry("count", 10));
	Map applicationProperties = (Map) deploymentMap.get("applicationProperties");
	assertThat(applicationProperties).contains(entry("log.level", "DEBUG"), entry("server.port", 8089));
	Map deploymentProperties = (Map) deploymentMap.get("deploymentProperties");
	assertThat(deploymentProperties).contains(entry("app.time.producer.partitionKeyExpression", "payload"),
			entry("app.log.spring.cloud.stream.bindings.input.consumer.maxAttempts", 5));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:23,代码来源:PackageTemplateTests.java

示例3: getAnalyticsCodeForAuthUser

import com.samskivert.mustache.Template; //导入方法依赖的package包/类
@RequestMapping(value = "/analytics_auth.js", method = RequestMethod.GET, produces = "application/javascript")
public @ResponseBody
ResponseEntity<String> getAnalyticsCodeForAuthUser(@AuthenticationPrincipal Client client) {

    Map<String, Object> model = new HashMap<>();
    model.put("trackingId", trackingId);
    if(client != null) {
        model.put("clientId", client.getClientId());
        model.put("unitId", client.getUnitId());
    }

    Template template = templateLoader.loadTemplate("analytics.mustache");
    String requestBody = template.execute(model);

    return new ResponseEntity<>(requestBody,  new HttpHeaders(), HttpStatus.OK);
}
 
开发者ID:AusDTO,项目名称:citizenship-appointment-server,代码行数:17,代码来源:AnalyticsController.java

示例4: getCalendarIcsFile

import com.samskivert.mustache.Template; //导入方法依赖的package包/类
@RequestMapping(value = "/calendar.ics", method = RequestMethod.GET, produces = "text/calendar")
public @ResponseBody
ResponseEntity<String> getCalendarIcsFile(@AuthenticationPrincipal Client client) {
    final AppointmentDetails appointmentDetails = appointmentDetailsService.getExpectedAppointmentForClientForNextYear(client);

    Map<String, Object> model = new HashMap<>();
    model.put("id", UUID.randomUUID().toString());
    model.put("timeZone", appointmentDetails.getUnitTimeZoneIANA());

    DateTimeFormatter calendarDateNoZoneFormat = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss");
    model.put("startTime", appointmentDetails.getAppointmentDate().format(calendarDateNoZoneFormat));
    model.put("endTime", appointmentDetails.getAppointmentDate().plusHours(2L).format(calendarDateNoZoneFormat));
    model.put("location", appointmentDetails.getUnitAddress());

    Template template = templateLoader.loadTemplate("calendar_ics.mustache");
    String requestBody = template.execute(model);

    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.add("content-disposition", "attachment; filename=appointment.ics");
    responseHeaders.add("Content-Type","text/calendar");

    return new ResponseEntity<>(requestBody, responseHeaders,  HttpStatus.OK);
}
 
开发者ID:AusDTO,项目名称:citizenship-appointment-server,代码行数:24,代码来源:AddToCalendarController.java

示例5: sendRequestInternal

import com.samskivert.mustache.Template; //导入方法依赖的package包/类
private ResponseWrapper sendRequestInternal(Template template, Map<String, String> messageParams, String serviceAddress, String messageId) {
    ApiSession apiSession = apiSessionService.createSession();

    try {
        messageParams.put("apiSessionId", apiSession.getApiSessionId());
        messageParams.put("currentUserId", apiSession.getUserId());
        messageParams.put("serviceAddress", serviceAddress);
        messageParams.put("messageUUID", messageId);
        String requestBody = template.execute(messageParams);
        return httpClient.post(serviceAddress, requestBody, messageId);
    } finally {
        if (apiSession != null) {
            apiSessionService.closeSession(apiSession.getApiSessionId());
        }
    }
}
 
开发者ID:AusDTO,项目名称:citizenship-appointment-server,代码行数:17,代码来源:ApiCallsSenderService.java

示例6: logout

import com.samskivert.mustache.Template; //导入方法依赖的package包/类
public void logout(String apiSessionId) {
    Resource resource = resourceLoader.getResource("classpath:request_templates/" + SIGN_OUT_TEMPLATE_PATH);
    InputStream inputStream = null;
    try {
        inputStream = resource.getInputStream();
    } catch (IOException e) {
        throw new RuntimeException("Problem reading request template: " + SIGN_OUT_TEMPLATE_PATH, e);
    }
    InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
    Template tmpl = Mustache.compiler().compile(inputStreamReader);

    Map<String, String> messageParams = new HashMap<>();
    messageParams.put("apiSessionId", apiSessionId);
    String messageId = UUID.randomUUID().toString();
    messageParams.put("messageUUID", messageId);
    messageParams.put("serviceAddress", serviceAddressUser);
    String messageBody = tmpl.execute(messageParams);

    httpClient.post(serviceAddressUser, messageBody, messageId);
}
 
开发者ID:AusDTO,项目名称:citizenship-appointment-server,代码行数:21,代码来源:ApiLogoutService.java

示例7: gatherReferencedFields

import com.samskivert.mustache.Template; //导入方法依赖的package包/类
/**
 * Gather fields that are referenced in the mustache template.
 *
 * @return the collection
 */
private Collection<String> gatherReferencedFields() {
	Collection<String> fields = new ArrayList<>();
	Collector collector = new DefaultCollector() {

		@Override
		public VariableFetcher createFetcher(Object ctx, String name) {
			fields.add(name);
			return super.createFetcher(ctx, name);
		}
	};

	Compiler compiler = Mustache.compiler().defaultValue("").withCollector(collector);
	Template mockTemplate = compiler.compile(mustacheTemplate);
	mockTemplate.execute(new HashMap<>());
	return fields;
}
 
开发者ID:dstl,项目名称:baleen,代码行数:22,代码来源:TemplateFieldJoiningAnnotator.java

示例8: writeRecords

import com.samskivert.mustache.Template; //导入方法依赖的package包/类
@Override
protected void writeRecords(String documentSourceName, JCas jCas, Map<String, Collection<ExtractedRecord>> records,
		Map<String, Object> fieldMap) {
	for (Collection<ExtractedRecord> extractedRecords : records.values()) {
		for (ExtractedRecord extractedRecord : extractedRecords) {
			String name = extractedRecord.getName();
			Template template = templates.get(StringUtils.lowerCase(name));
			if (template == null) {
				getMonitor().info("No template found for record {}", name);
				continue;
			}
			try (Writer writer = createOutputWriter(documentSourceName, name)) {
				template.execute(fieldMap, writer);
			} catch (IOException e) {
				getMonitor().warn("Failed to write record " + name + " for document " + documentSourceName, e);
			}
		}
	}
}
 
开发者ID:dstl,项目名称:baleen,代码行数:20,代码来源:PerRecordMustacheHtmlTemplateRecordConsumer.java

示例9: getEmailText

import com.samskivert.mustache.Template; //导入方法依赖的package包/类
private String getEmailText(Locale locale, String loginName, String link)
		throws IOException {
	String resource = "pwreset_email.mustache";
	if (locale != null && locale.getLanguage().toLowerCase().equals("de")) {
		resource = "pwreset_email_de.mustache";
	}
	ClassPathResource cp = new ClassPathResource(resource);
	try (InputStream is = cp.getInputStream()) {
		Template template = this.mustacheCompiler.compile(new InputStreamReader(is));

		Map<String, Object> data = new HashMap<>();
		data.put("loginName", loginName);
		data.put("link", link);

		return template.execute(data);
	}
}
 
开发者ID:ralscha,项目名称:eds-starter6-jpa,代码行数:18,代码来源:MailService.java

示例10: render

import com.samskivert.mustache.Template; //导入方法依赖的package包/类
private void render(String templatePath, File workingDirectory, Object toRender) throws IOException {
    FileWriter writer = null;

    try {
        File template = new File(workingDirectory.getPath(), templatePath);
        if (template.getParentFile() != null) {
            template.getParentFile().mkdirs();
        }

        writer = new FileWriter(template);

        Template mustacheTemplate = engine.compile(buildTemplateReader(templatePath));

        mustacheTemplate.execute(toRender, writer);
    } finally {
        IOUtils.closeQuietly(writer);
    }
}
 
开发者ID:Orange-OpenSource,项目名称:ocara,代码行数:19,代码来源:AuditDocxExporter.java

示例11: process

import com.samskivert.mustache.Template; //导入方法依赖的package包/类
public String process(String name, Map<String, ?> model) {
	try {
		Template template = getTemplate(name);
		return template.execute(model);
	}
	catch (Exception e) {
		log.error("Cannot render: " + name, e);
		throw new IllegalStateException("Cannot render template", e);
	}
}
 
开发者ID:rvillars,项目名称:edoras-one-initializr,代码行数:11,代码来源:TemplateRenderer.java

示例12: format

import com.samskivert.mustache.Template; //导入方法依赖的package包/类
public String format(final Document html, final ParserContext parserContext) {
	final ParserType parserType = ParserType.detect(html).orElseThrow(
			() -> new RuntimeException("Unsupported Wowhead article type"));
	final Object data = parserType.parse(html, parserContext);
	final Map<String, Object> context = new HashMap<>();
	
	context.put(parserType.getTemplateObjectPrefix(), data);
	
	Template template = TEMPLATES.computeIfAbsent(parserType, this::createTemplate);
	return template.execute(context);
}
 
开发者ID:Maia-Everett,项目名称:questfiller,代码行数:12,代码来源:ArticleFormatter.java

示例13: prepareMatchingRuleConfiguration

import com.samskivert.mustache.Template; //导入方法依赖的package包/类
/**
 * Prepare a matching rule configuration file in the specified job folder
 * based on whether the run is Deduplication or Linkage.
 * 
 * @param isDeduplication
 *          true when deduplicating records in a single data set.
 * 
 * @param jobDir
 * @return
 * @throws IOException
 */
File prepareMatchingRuleConfiguration(boolean isDeduplication, File jobDir)
    throws IOException {
  final String templateFileStr = isDeduplication ? getDeduplicationTemplate()
      : getLinkageTemplate();
  if (templateFileStr == null) {
    throw new IllegalStateException("No Template File set for "
        + (isDeduplication ? "deduplication" : "linkage") + " mode");
  }

  final Template matchConfigTemplate = loadTemplate(templateFileStr);
  if (matchConfigTemplate == null) {
    final String msg = "Unable to load matching rule configuration template: "
        + templateFileStr;
    LOG.error(msg);
    throw new IllegalStateException(msg);
  }

  final File configFile = new File(jobDir, "config.xml");

  // Generate the configuration file that specifies matching rules and
  // data sources
  final Map<String, String> templateParams = new HashMap<String, String>();
  templateParams.put("jobDir", jobDir.getAbsolutePath());
  final Writer configWriter = new FileWriter(configFile);
  try {
    // Apply parameters to template and write result to file
    matchConfigTemplate.execute(templateParams, configWriter);
    configWriter.flush();
  } finally {
    try {
      configWriter.close();
    } catch (IOException e) {
      // ignore
    }
  }
  return configFile;
}
 
开发者ID:mitre,项目名称:ptmatchadapter,代码行数:49,代码来源:RecordMatchRequestProcessor.java

示例14: toString

import com.samskivert.mustache.Template; //导入方法依赖的package包/类
@Override
public String toString() {
    StringWriter writer = new StringWriter();

    InputStream templateStream = getClass().getResourceAsStream(getTemplateName());
    Mustache.Compiler compiler = Mustache.compiler()
            .strictSections(false)
            .nullValue("");
    Template template = compiler.compile(new InputStreamReader(templateStream));
    template.execute(this, writer);

    return writer.toString();
}
 
开发者ID:nrudenko,项目名称:dora,代码行数:14,代码来源:BaseTemplateContext.java

示例15: doGet

import com.samskivert.mustache.Template; //导入方法依赖的package包/类
@Override
public HttpResponse doGet(HttpRequest request) {
    String html = HtmlReader.readAll(context, "download.html");

    Template template = Mustache.compiler().compile(html);

    Map<String, List<FileItem>> map = new HashMap<>();
    map.put("files", PreferenceUtil.getFileItemsToSend(context));

    html = template.execute(map);

    Log.i(TAG, html);
    return HttpResponse.newResponse(html);
}
 
开发者ID:YieldNull,项目名称:Biu,代码行数:15,代码来源:DownloadServlet.java


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