Formatting for KEYCLOAK-1113
This commit is contained in:
parent
a2c4a1f760
commit
58068946e4
3 changed files with 43 additions and 44 deletions
|
@ -19,37 +19,37 @@ import org.keycloak.provider.Provider;
|
||||||
*/
|
*/
|
||||||
public interface AccountProvider extends Provider {
|
public interface AccountProvider extends Provider {
|
||||||
|
|
||||||
AccountProvider setUriInfo(UriInfo uriInfo);
|
AccountProvider setUriInfo(UriInfo uriInfo);
|
||||||
|
|
||||||
AccountProvider setHttpHeaders(HttpHeaders httpHeaders);
|
AccountProvider setHttpHeaders(HttpHeaders httpHeaders);
|
||||||
|
|
||||||
Response createResponse(AccountPages page);
|
Response createResponse(AccountPages page);
|
||||||
|
|
||||||
AccountProvider setError(String message, Object... parameters);
|
AccountProvider setError(String message, Object ... parameters);
|
||||||
|
|
||||||
AccountProvider setErrors(List<FormMessage> messages);
|
AccountProvider setErrors(List<FormMessage> messages);
|
||||||
|
|
||||||
AccountProvider setSuccess(String message, Object... parameters);
|
AccountProvider setSuccess(String message, Object ... parameters);
|
||||||
|
|
||||||
AccountProvider setWarning(String message, Object... parameters);
|
AccountProvider setWarning(String message, Object ... parameters);
|
||||||
|
|
||||||
AccountProvider setUser(UserModel user);
|
AccountProvider setUser(UserModel user);
|
||||||
|
|
||||||
AccountProvider setProfileFormData(MultivaluedMap<String, String> formData);
|
AccountProvider setProfileFormData(MultivaluedMap<String, String> formData);
|
||||||
|
|
||||||
AccountProvider setStatus(Response.Status status);
|
AccountProvider setStatus(Response.Status status);
|
||||||
|
|
||||||
AccountProvider setRealm(RealmModel realm);
|
AccountProvider setRealm(RealmModel realm);
|
||||||
|
|
||||||
AccountProvider setReferrer(String[] referrer);
|
AccountProvider setReferrer(String[] referrer);
|
||||||
|
|
||||||
AccountProvider setEvents(List<Event> events);
|
AccountProvider setEvents(List<Event> events);
|
||||||
|
|
||||||
AccountProvider setSessions(List<UserSessionModel> sessions);
|
AccountProvider setSessions(List<UserSessionModel> sessions);
|
||||||
|
|
||||||
AccountProvider setPasswordSet(boolean passwordSet);
|
AccountProvider setPasswordSet(boolean passwordSet);
|
||||||
|
|
||||||
AccountProvider setStateChecker(String stateChecker);
|
AccountProvider setStateChecker(String stateChecker);
|
||||||
|
|
||||||
AccountProvider setFeatures(boolean social, boolean events, boolean passwordUpdateSupported);
|
AccountProvider setFeatures(boolean social, boolean events, boolean passwordUpdateSupported);
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ public class FreeMarkerAccountProvider implements AccountProvider {
|
||||||
Locale locale = LocaleHelper.getLocale(realm, user, uriInfo, headers);
|
Locale locale = LocaleHelper.getLocale(realm, user, uriInfo, headers);
|
||||||
Properties messagesBundle;
|
Properties messagesBundle;
|
||||||
try {
|
try {
|
||||||
messagesBundle = theme.getMessages(locale);
|
messagesBundle = theme.getMessages(locale);
|
||||||
attributes.put("msg", new MessageFormatterMethod(locale, messagesBundle));
|
attributes.put("msg", new MessageFormatterMethod(locale, messagesBundle));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.warn("Failed to load messages", e);
|
logger.warn("Failed to load messages", e);
|
||||||
|
@ -204,46 +204,45 @@ public class FreeMarkerAccountProvider implements AccountProvider {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setMessage(MessageType type, String message, Object... parameters) {
|
protected void setMessage(MessageType type, String message, Object... parameters) {
|
||||||
messageType = type;
|
messageType = type;
|
||||||
messages = new ArrayList<>();
|
messages = new ArrayList<>();
|
||||||
messages.add(new FormMessage(null, message, parameters));
|
messages.add(new FormMessage(null, message, parameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String formatMessage(FormMessage message, Properties messagesBundle, Locale locale) {
|
protected String formatMessage(FormMessage message, Properties messagesBundle, Locale locale) {
|
||||||
if (message == null)
|
if (message == null)
|
||||||
return null;
|
return null;
|
||||||
if (messagesBundle.containsKey(message.getMessage())) {
|
if (messagesBundle.containsKey(message.getMessage())) {
|
||||||
return new MessageFormat(messagesBundle.getProperty(message.getMessage()), locale)
|
return new MessageFormat(messagesBundle.getProperty(message.getMessage()), locale).format(message.getParameters());
|
||||||
.format(message.getParameters());
|
} else {
|
||||||
} else {
|
return message.getMessage();
|
||||||
return message.getMessage();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AccountProvider setErrors(List<FormMessage> messages) {
|
public AccountProvider setErrors(List<FormMessage> messages) {
|
||||||
this.messageType = MessageType.ERROR;
|
this.messageType = MessageType.ERROR;
|
||||||
this.messages = new ArrayList<>(messages);
|
this.messages = new ArrayList<>(messages);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AccountProvider setError(String message, Object ... parameters) {
|
public AccountProvider setError(String message, Object ... parameters) {
|
||||||
setMessage(MessageType.ERROR, message, parameters);
|
setMessage(MessageType.ERROR, message, parameters);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AccountProvider setSuccess(String message, Object ... parameters) {
|
public AccountProvider setSuccess(String message, Object ... parameters) {
|
||||||
setMessage(MessageType.SUCCESS, message, parameters);
|
setMessage(MessageType.SUCCESS, message, parameters);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AccountProvider setWarning(String message, Object ... parameters) {
|
public AccountProvider setWarning(String message, Object ... parameters) {
|
||||||
setMessage(MessageType.WARNING, message, parameters);
|
setMessage(MessageType.WARNING, message, parameters);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ package org.keycloak.freemarker.beans;
|
||||||
* @author Vlastimil Elias (velias at redhat dot com)
|
* @author Vlastimil Elias (velias at redhat dot com)
|
||||||
*/
|
*/
|
||||||
public enum MessageType {
|
public enum MessageType {
|
||||||
|
|
||||||
SUCCESS, WARNING, ERROR
|
SUCCESS, WARNING, ERROR
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue