Search in sources :

Example 21 with Template

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);
    }
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) Template(freemarker.template.Template)

Example 22 with Template

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);
}
Also used : Configuration(freemarker.template.Configuration) Template(freemarker.template.Template)

Example 23 with 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) {
            }
        }
    }
}
Also used : Configuration(freemarker.template.Configuration) HashMap(java.util.HashMap) PCGFile(pcgen.io.PCGFile) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Template(freemarker.template.Template)

Example 24 with Template

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);
}
Also used : ResourceOwnerAuthenticationRequired(org.forgerock.oauth2.core.exceptions.ResourceOwnerAuthenticationRequired) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.restlet.Request) OAuth2ProviderSettings(org.forgerock.oauth2.core.OAuth2ProviderSettings) URI(java.net.URI) Template(freemarker.template.Template)

Example 25 with Template

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);
}
Also used : Configuration(freemarker.template.Configuration) StringReader(java.io.StringReader) Template(freemarker.template.Template)

Aggregations

Template (freemarker.template.Template)72 IOException (java.io.IOException)33 StringWriter (java.io.StringWriter)32 Configuration (freemarker.template.Configuration)30 Writer (java.io.Writer)26 HashMap (java.util.HashMap)26 TemplateException (freemarker.template.TemplateException)23 OutputStreamWriter (java.io.OutputStreamWriter)13 File (java.io.File)9 Map (java.util.Map)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 JSONObject (org.json.JSONObject)6 SimpleHash (freemarker.template.SimpleHash)5 ThirdEyeAnomalyConfiguration (com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration)4 StringTemplateLoader (freemarker.cache.StringTemplateLoader)4 Environment (freemarker.core.Environment)4 DefaultObjectWrapper (freemarker.template.DefaultObjectWrapper)4 BufferedWriter (java.io.BufferedWriter)4 FileOutputStream (java.io.FileOutputStream)4 StringReader (java.io.StringReader)4