本文整理汇总了Java中com.samskivert.mustache.Template类的典型用法代码示例。如果您正苦于以下问题:Java Template类的具体用法?Java Template怎么用?Java Template使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Template类属于com.samskivert.mustache包,在下文中一共展示了Template类的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));
}
示例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));
}
示例3: execute
import com.samskivert.mustache.Template; //导入依赖的package包/类
@Override
public void execute(Template.Fragment frag, Writer out) throws IOException {
String body = frag.execute();
int split = body.indexOf('|');
String expr;
String format;
if (split == -1) {
expr = body.trim();
format = DEFAULT_FORMAT;
} else {
expr = body.substring(0, split).trim();
format = body.substring(split + 1).trim();
}
if(expr.length() == 0) {
log.debug("date_format_lambda param date is empty!");
return;
}
out.write(new SimpleDateFormat(format).format(new Date(Long.parseLong(expr))));
}
示例4: rendererOf
import com.samskivert.mustache.Template; //导入依赖的package包/类
private Renderer rendererOf(Template template, String templateName) {
return renderable -> {
formatter.set(renderable.context().site().config().formatters().formatters());
try {
ImmutableMustacheRenderContext renderContext = MustacheRenderContext.builder()
.markupRenderFactory(markupRenderFactory)
.build();
return Text.builder()
.mimeType("text/html")
.text(template.execute(asMustacheContext(renderable, renderContext)))
.build();
} catch (RuntimeException rx) {
throw new RuntimeException("could not render: "+templateName,rx);
}
};
}
示例5: getTemplate
import com.samskivert.mustache.Template; //导入依赖的package包/类
/**
* Retrieve the given mustache template, compiling as necessary.
*/
public Template getTemplate(String filename) {
Template t = null;
if (templates.containsKey(filename)) {
t = templates.get(filename);
} else {
URL url = findResource(filename);
if (url != null) {
t = compile(getInputStream(filename));
templates.put(filename, t);
PMS.getFileWatcher().add(new FileWatcher.Watch(url.getFile(), recompiler));
} else {
LOGGER.warn("Couldn't find web template \"{}\"", filename);
}
}
return t;
}
示例6: 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);
}
示例7: 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);
}
示例8: sendRequest
import com.samskivert.mustache.Template; //导入依赖的package包/类
@Override
public ResponseWrapper sendRequest(Template template, Map<String, String> messageParams, String serviceAddress) {
ResponseWrapper response = null;
for (int numberOfAttempts = 1; numberOfAttempts <= MAX_ATTEMPTS; numberOfAttempts++) {
String messageId = UUID.randomUUID().toString();
response = sendRequestInternal(template, messageParams, serviceAddress, messageId);
if (response.getCode() == 200) {
return response;
}
if (!response.isInvalidSessionId()) {
throw new ApiResponseNotSuccessfulException("Invalid server response with statusCode=[" + response.getCode() + "] for messageId=[" + messageId + "]: " + response.getMessage(), response);
}
LOG.warn("Request failed due to InvalidSessionId on attempt {}, retrying", numberOfAttempts);
}
LOG.error("Request failed {} times with InvalidSessionId error, giving up", MAX_ATTEMPTS);
return response;
}
示例9: 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());
}
}
}
示例10: 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);
}
示例11: getCalendars_shouldConvertResponseIntoCalendarEntryObject
import com.samskivert.mustache.Template; //导入依赖的package包/类
@Test
public void getCalendars_shouldConvertResponseIntoCalendarEntryObject() throws Exception {
AvailableDatesService service = new AvailableDatesService(
(Template requestTemplate, Map<String, String> messageParams, String serviceAddress) -> getStandardResponse(),
null,
new FakeTemplateLoader(),
"serviceUrl");
SortedMap<String, AvailableDate> calendarEntries = service.getAvailabilityForDateRange("serviceId", LocalDate.now(), LocalDate.now());
AvailableDate availableDate = calendarEntries.get(calendarEntries.firstKey());
assertThat(calendarEntries.size(), is(1));
assertThat(availableDate.getId(), is("192"));
assertThat(availableDate.getCalendarDate(), is("2015-12-16"));
assertThat(availableDate.getAvailableTimesCount(), is(12));
}
示例12: getApiCallsSenderService
import com.samskivert.mustache.Template; //导入依赖的package包/类
private ApiCallsSenderService getApiCallsSenderService(){
return (Template requestTemplate, Map<String, String> messageParams, String serviceAddress) -> {
String response = null;
if(requestTemplate.toString().contains("GetExpectedAppointments.")){
response = getExpectedAppointmentsResponse();
} else if (requestTemplate.toString().contains("GetUnit.")){
response = getUnitDetailsResponse(messageParams);
} else if (requestTemplate.toString().contains("GetUnitLocalTime.")){
response = getUnitLocalTimeResponse(messageParams);
} else if (requestTemplate.toString().contains("GetService.")){
response = getServiceDetailsResponse(messageParams);
}
return new ResponseWrapper(200, response);
};
}
示例13: getApiCallsSenderServiceReturningAppointmentWithWrongCustomerId
import com.samskivert.mustache.Template; //导入依赖的package包/类
private ApiCallsSenderService getApiCallsSenderServiceReturningAppointmentWithWrongCustomerId(){
return (Template requestTemplate, Map<String, String> messageParams, String serviceAddress) -> {
String responseWithWrongCustomerId =
" <s:Body>\n" +
" <GetExpectedAppointmentsResponse xmlns=\"http://www.qnomy.com/Services\">\n" +
" <GetExpectedAppointmentsResult xmlns:b=\"http://schemas.datacontract.org/2004/07/QFlow.Library\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
" <b:CustomerGetExpectedAppointmentsResults>\n" +
" <b:AppointmentDate>2016-01-06T09:00:00</b:AppointmentDate>\n" +
" <b:AppointmentDuration>20</b:AppointmentDuration>\n" +
" <b:AppointmentId>117</b:AppointmentId>\n" +
" <b:AppointmentTypeId>3</b:AppointmentTypeId>\n" +
" <b:AppointmentTypeName>Standard Citizenship Appointment</b:AppointmentTypeName>\n" +
" <b:CustomerId>2323</b:CustomerId>\n" +
" <b:ProcessId>125</b:ProcessId>\n" +
" <b:ServiceId>111</b:ServiceId>\n" +
" <b:ServiceName>Citizenship Interview 20min</b:ServiceName>\n" +
" <b:UnitName>Sydney</b:UnitName>\n" +
" </b:CustomerGetExpectedAppointmentsResults>\n" +
" </GetExpectedAppointmentsResult>\n" +
" </GetExpectedAppointmentsResponse>\n" +
" </s:Body>";
return new ResponseWrapper(200, responseWithWrongCustomerId);
};
}
示例14: getApiCallsSenderServiceReturningCorrectAppointment
import com.samskivert.mustache.Template; //导入依赖的package包/类
private ApiCallsSenderService getApiCallsSenderServiceReturningCorrectAppointment(){
return (Template requestTemplate, Map<String, String> messageParams, String serviceAddress) -> {
String response =
" <s:Body>\n" +
" <GetExpectedAppointmentsResponse xmlns=\"http://www.qnomy.com/Services\">\n" +
" <GetExpectedAppointmentsResult xmlns:b=\"http://schemas.datacontract.org/2004/07/QFlow.Library\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
" <b:CustomerGetExpectedAppointmentsResults>\n" +
" <b:AppointmentDate>2016-02-06T13:00:00</b:AppointmentDate>\n" +
" <b:AppointmentDuration>20</b:AppointmentDuration>\n" +
" <b:AppointmentId>117</b:AppointmentId>\n" +
" <b:AppointmentTypeId>3</b:AppointmentTypeId>\n" +
" <b:AppointmentTypeName>Standard Citizenship Appointment</b:AppointmentTypeName>\n" +
" <b:CustomerId>40404</b:CustomerId>\n" +
" <b:ProcessId>125</b:ProcessId>\n" +
" <b:ServiceId>111</b:ServiceId>\n" +
" <b:ServiceName>Citizenship Interview 20min</b:ServiceName>\n" +
" <b:UnitName>Sydney CBD</b:UnitName>\n" +
" </b:CustomerGetExpectedAppointmentsResults>\n" +
" </GetExpectedAppointmentsResult>\n" +
" </GetExpectedAppointmentsResponse>\n" +
" </s:Body>";
return new ResponseWrapper(200, response);
};
}
示例15: getApiServiceReturningFailedPropertyValueSaveDueToExceedsLength
import com.samskivert.mustache.Template; //导入依赖的package包/类
private ApiCallsSenderService getApiServiceReturningFailedPropertyValueSaveDueToExceedsLength(){
return (Template requestTemplate, Map<String, String> messageParams, String serviceAddress) -> {
String responseWithErrorDueToExceedsLength =
" <s:Body>\n" +
" <s:Fault>\n" +
" <s:Code>\n" +
" <s:Value>s:Sender</s:Value>\n" +
" </s:Code>\n" +
" <s:Reason>\n" +
" <s:Text xml:lang=\"en-US\">Error message</s:Text>\n" +
" </s:Reason>\n" +
" <s:Detail>\n" +
" <QFlowAPIApplicationException xmlns=\"http://schemas.datacontract.org/2004/07/QFlow.Web.API\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
" <ErrorNumber>0</ErrorNumber>\n" +
" </QFlowAPIApplicationException>\n" +
" </s:Detail>\n" +
" </s:Fault>\n" +
" </s:Body>";
return new ResponseWrapper(500, responseWithErrorDueToExceedsLength);
};
}