use of com.github.jknack.handlebars.Template in project ddf by codice.
the class KmlEndpoint method createRootNetworkLink.
private Kml createRootNetworkLink(UriInfo uriInfo) throws UnknownHostException {
Kml kml = KmlFactory.createKml();
NetworkLink rootNetworkLink = kml.createAndSetNetworkLink();
rootNetworkLink.setName(this.productName);
rootNetworkLink.setSnippet(KmlFactory.createSnippet().withMaxLines(0));
UriBuilder baseUrlBuidler = UriBuilder.fromUri(uriInfo.getBaseUri());
baseUrlBuidler.replacePath("");
this.baseUrl = baseUrlBuidler.build().toString();
String descriptionHtml = description;
Handlebars handlebars = new Handlebars(templateLoader);
try {
Template template = handlebars.compile("description");
descriptionHtml = template.apply(this);
LOGGER.debug(descriptionHtml);
} catch (IOException e) {
LOGGER.debug("Failed to apply description Template", e);
}
rootNetworkLink.setDescription(descriptionHtml);
rootNetworkLink.setOpen(true);
rootNetworkLink.setVisibility(false);
Link link = rootNetworkLink.createAndSetLink();
UriBuilder builder = UriBuilder.fromUri(uriInfo.getBaseUri());
builder = generateEndpointUrl(SystemBaseUrl.getRootContext() + FORWARD_SLASH + CATALOG_URL_PATH + FORWARD_SLASH + KML_TRANSFORM_PARAM + FORWARD_SLASH + "sources", builder);
link.setHref(builder.build().toString());
link.setViewRefreshMode(ViewRefreshMode.NEVER);
link.setRefreshMode(RefreshMode.ON_INTERVAL);
link.setRefreshInterval(REFRESH_INTERVAL);
return kml;
}
use of com.github.jknack.handlebars.Template in project ddf by codice.
the class KMLTransformerImpl method performDefaultTransformation.
/**
* The default Transformation from a {@link Metacard} to a KML {@link Placemark}. Protected to
* easily allow other default transformations.
*
* @param entry
* - the {@link Metacard} to transform.
* @param urlToMetacard
* @return
* @throws javax.xml.transform.TransformerException
*/
protected Placemark performDefaultTransformation(Metacard entry, String url) throws CatalogTransformerException {
// wrap metacard to work around classLoader/reflection issues
entry = new MetacardImpl(entry);
Placemark kmlPlacemark = KmlFactory.createPlacemark();
kmlPlacemark.setId("Placemark-" + entry.getId());
kmlPlacemark.setName(entry.getTitle());
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
String effectiveTime = null;
if (entry.getEffectiveDate() == null) {
effectiveTime = dateFormat.format(new Date());
} else {
effectiveTime = dateFormat.format(entry.getEffectiveDate());
}
TimeSpan timeSpan = KmlFactory.createTimeSpan();
timeSpan.setBegin(effectiveTime);
kmlPlacemark.setTimePrimitive(timeSpan);
kmlPlacemark.setGeometry(getKmlGeoFromWkt(entry.getLocation()));
String description = entry.getTitle();
Handlebars handlebars = new Handlebars(templateLoader);
handlebars.registerHelpers(templateHelper);
try {
Template template = handlebars.compile(DESCRIPTION_TEMPLATE);
description = template.apply(new HandlebarsMetacard(entry));
LOGGER.debug(description);
} catch (IOException e) {
LOGGER.debug("Failed to apply description Template", e);
}
kmlPlacemark.setDescription(description);
String styleUrl = styleMapper.getStyleForMetacard(entry);
if (StringUtils.isNotBlank(styleUrl)) {
kmlPlacemark.setStyleUrl(styleUrl);
}
return kmlPlacemark;
}
use of com.github.jknack.handlebars.Template in project ddf by codice.
the class RegistryReportBuilder method getHtmlFromRegistryPackage.
public String getHtmlFromRegistryPackage(RegistryPackageType registryPackage, String handlebarTemplate) throws IOException {
Map<String, Object> reportMap = new HashMap<>();
if (handlebarTemplate.equals(ORGANIZATIONS)) {
reportMap = getOrganizationMap(registryPackage);
} else if (handlebarTemplate.equals(REPORT)) {
reportMap = getFullRegistryMap(registryPackage);
}
Template template = handlebars.compile(handlebarTemplate);
String html = template.apply(reportMap);
html = html.replaceAll("\n", "");
return html;
}
use of com.github.jknack.handlebars.Template in project ddf by codice.
the class RegistryReportBuilder method getErrorHtml.
public String getErrorHtml(String errorMessage) throws IOException {
Template template = handlebars.compile(ERROR);
String html = template.apply(errorMessage);
return html;
}
use of com.github.jknack.handlebars.Template in project ddf by codice.
the class LandingPage method compileTemplateWithProperties.
// package-private for unit testing
String compileTemplateWithProperties() {
title = getTitle();
version = branding.map(registry -> registry.getAttributeFromBranding(BrandingPlugin::getProductName)).orElse("");
logoToUse = StringUtils.isNotEmpty(logo) ? logo : getProductImage();
// FieldValueResolver so this class' fields can be accessed in the template.
// MapValueResolver so we can access {{@index}} in the #each helper in the template.
final Context context = Context.newBuilder(this).resolver(FieldValueResolver.INSTANCE, MapValueResolver.INSTANCE).build();
// The template is "index.handlebars".
final TemplateLoader templateLoader = new ClassPathTemplateLoader("/", ".handlebars");
final Handlebars handlebars = new Handlebars(templateLoader);
// extractDate(), extractAnnouncement(), expanded(), and in() are helper functions used in the template.
handlebars.registerHelpers(this);
String landingPageHtml;
try {
final Template template = handlebars.compile(LANDING_PAGE_FILE);
landingPageHtml = template.apply(context);
} catch (IOException e) {
LOGGER.info("Unable to compile Landing Page template.", e);
landingPageHtml = "<p>We are experiencing some issues. Please contact an administrator.</p>";
}
return landingPageHtml;
}
Aggregations