Search in sources :

Example 1 with TemplateRepresentation

use of org.restlet.ext.freemarker.TemplateRepresentation in project OpenAM by OpenRock.

the class OAuth2Representation method getRepresentation.

/**
     * Gets the appropriate representation to send to the user agent based from the specified parameters.
     * <br/>
     * The possible values for the display are: page, popup, touch, wap.
     *
     * @param context The Restlet context.
     * @param display The display type of the page.
     * @param templateName The name of the template to display.
     * @param dataModel The data model to display on the page.
     * @return A representation of the page to send to the user agent.
     */
Representation getRepresentation(Context context, String display, String templateName, Map<String, ?> dataModel) {
    final String reference = "templates/" + (display != null ? display : "page") + "/" + templateName;
    final TemplateRepresentation result = getTemplateFactory(context).getTemplateRepresentation(reference);
    if (result != null) {
        result.setDataModel(dataModel);
    }
    return result;
}
Also used : TemplateRepresentation(org.restlet.ext.freemarker.TemplateRepresentation)

Example 2 with TemplateRepresentation

use of org.restlet.ext.freemarker.TemplateRepresentation in project OpenAM by OpenRock.

the class DeviceCodeVerificationResource method getTemplateRepresentation.

private Representation getTemplateRepresentation(String template, OAuth2Request request, String errorCode) {
    TemplateRepresentation response = getTemplateFactory(getContext()).getTemplateRepresentation(template);
    Map<String, String> dataModel = new HashMap<>();
    dataModel.put("errorCode", errorCode);
    dataModel.put("baseUrl", baseURLProviderFactory.get(request.<String>getParameter("realm")).getRootURL(ServletUtils.getRequest(getRequest())));
    List<String> locale = new ArrayList<>();
    for (Preference<Language> language : getRequest().getClientInfo().getAcceptedLanguages()) {
        locale.add(language.getMetadata().getName());
    }
    dataModel.put("locale", oAuth2Utils.join(locale, " "));
    dataModel.put("realm", request.<String>getParameter(OAuth2Constants.Params.REALM));
    response.setDataModel(dataModel);
    return response;
}
Also used : TemplateRepresentation(org.restlet.ext.freemarker.TemplateRepresentation) Language(org.restlet.data.Language) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 3 with TemplateRepresentation

use of org.restlet.ext.freemarker.TemplateRepresentation in project OpenAM by OpenRock.

the class OAuth2Representation method getFormPostRepresentation.

private Representation getFormPostRepresentation(Context context, AuthorizationToken authorizationToken, String redirectUri) {
    Map<String, Object> dataModel = new HashMap<>();
    dataModel.put("redirectUri", redirectUri);
    dataModel.put("formValues", authorizationToken.getToken());
    final String reference = "templates/FormPostResponse.ftl";
    final TemplateRepresentation result = getTemplateFactory(context).getTemplateRepresentation(reference);
    if (result != null) {
        result.setDataModel(dataModel);
    }
    return result;
}
Also used : TemplateRepresentation(org.restlet.ext.freemarker.TemplateRepresentation) HashMap(java.util.HashMap)

Aggregations

TemplateRepresentation (org.restlet.ext.freemarker.TemplateRepresentation)3 HashMap (java.util.HashMap)2 ArrayList (java.util.ArrayList)1 Language (org.restlet.data.Language)1