use of freemarker.template.Template in project ORCID-Source by ORCID.
the class SwaggerUIBuilder method buildSwaggerHTML.
/**
* Build the swagger UI HTML page
*
* @param baseUri
* the URL of the main website. e.g. http://orcid.org
* @param apiUri
* the URL of the API e.g. http://pub.orcid.org
* @param showOAuth
* if true, input boxes allowing user to enter client id and
* secret will be shown
* @return a 200 response containing the HTML as text.
*/
public Response buildSwaggerHTML(String baseUri, String apiUri, boolean showOAuth) {
final Map<String, Object> map = new HashMap<String, Object>();
map.put("swaggerJsonUrl", apiUri + OrcidApiConstants.SWAGGER_PATH + OrcidApiConstants.SWAGGER_FILE);
map.put("swaggerBaseUrl", baseUri + SWAGGER_STATIC_HTML_PATH);
map.put("showOAuth", showOAuth);
map.put("baseUri", baseUri);
map.put("apiUri", apiUri);
try {
Template template = freeMarkerConfiguration.getTemplate(SWAGGER_UI_FTL);
StringWriter result = new StringWriter();
template.process(map, result);
return Response.ok(result.toString()).build();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (TemplateException e) {
throw new RuntimeException(e);
}
}
use of freemarker.template.Template in project opennms by OpenNMS.
the class NavBarController method afterPropertiesSet.
/**
* <p>afterPropertiesSet</p>
* @throws IOException
*/
@Override
public void afterPropertiesSet() throws IOException {
Assert.state(m_navBarItems != null, "navBarItems property has not been set");
// Initialize the Freemarker engine and fetch our template
Configuration cfg = new Configuration(Configuration.VERSION_2_3_21);
cfg.setDefaultEncoding(StandardCharsets.UTF_8.name());
cfg.setClassForTemplateLoading(NavBarController.class, "");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
Template template = cfg.getTemplate("navbar.ftl");
m_view = new FreemarkerView(template);
}
use of freemarker.template.Template in project pcgen by PCGen.
the class VariableReport method outputReport.
/**
* Output the variable report for the supplied data in a particular format.
*
* @param gameModeVarMap The map of variable definitions for each game mode.
* @param gameModeVarCountMap The map of the number of variables for each game mode.
* @param reportFormat The format in which to output the report.
* @param outputWriter The writer to output the report to.
* @throws IOException If the template cannot be accessed or the writer cannot be written to.
* @throws TemplateException If there is an error in processing the template.
*/
public void outputReport(Map<String, List<VarDefine>> gameModeVarMap, Map<String, Integer> gameModeVarCountMap, ReportFormat reportFormat, Writer outputWriter) throws IOException, TemplateException {
// Configuration
Writer file = null;
Configuration cfg = new Configuration();
int dataPathLen = ConfigurationSettings.getPccFilesDir().length();
try {
// Set Directory for templates
File codeDir = new File("code");
File templateDir = new File(codeDir, "templates");
cfg.setDirectoryForTemplateLoading(templateDir);
// load template
Template template = cfg.getTemplate(reportFormat.getTemplate());
// data-model
Map<String, Object> input = new HashMap<>();
input.put("gameModeVarMap", gameModeVarMap);
input.put("gameModeVarCountMap", gameModeVarCountMap);
input.put("pathIgnoreLen", dataPathLen + 1);
// Process the template
template.process(input, outputWriter);
outputWriter.flush();
} finally {
if (file != null) {
try {
file.close();
} catch (Exception e2) {
}
}
}
}
use of freemarker.template.Template in project OpenAM by OpenRock.
the class OpenAMResourceOwnerSessionValidator method authenticationRequired.
private ResourceOwnerAuthenticationRequired authenticationRequired(OAuth2Request request) throws AccessDeniedException, URISyntaxException, ServerException, NotFoundException, UnsupportedEncodingException {
OAuth2ProviderSettings providerSettings = providerSettingsFactory.get(request);
Template loginUrlTemplate = providerSettings.getCustomLoginUrlTemplate();
removeLoginPrompt(request.<Request>getRequest());
String gotoUrl = request.<Request>getRequest().getResourceRef().toString();
if (request.getParameter(USER_CODE) != null) {
gotoUrl += (gotoUrl.indexOf('?') > -1 ? "&" : "?") + USER_CODE + "=" + request.getParameter(USER_CODE);
}
String acrValues = request.getParameter(ACR_VALUES);
String realm = request.getParameter(OAuth2Constants.Custom.REALM);
String moduleName = request.getParameter(MODULE);
String serviceName = request.getParameter(SERVICE);
String locale = getRequestLocale(request);
URI loginUrl;
if (loginUrlTemplate != null) {
loginUrl = buildCustomLoginUrl(loginUrlTemplate, gotoUrl, acrValues, realm, moduleName, serviceName, locale);
} else {
loginUrl = buildDefaultLoginUrl(request, gotoUrl, acrValues, realm, moduleName, serviceName, locale);
}
return new ResourceOwnerAuthenticationRequired(loginUrl);
}
use of freemarker.template.Template in project OpenAM by OpenRock.
the class OpenAMResourceOwnerSessionValidatorTest method mockCustomLoginUrlTemplate.
private void mockCustomLoginUrlTemplate(String customLoginUrlTemplate) throws ServerException, IOException {
Template template = new Template("", new StringReader(customLoginUrlTemplate), new Configuration());
given(providerSettings.getCustomLoginUrlTemplate()).willReturn(template);
}
Aggregations