use of java.util.Locale in project sonarqube by SonarSource.
the class RequestProcessor method processLocale.
/**
* <p>Automatically select a <code>Locale</code> for the current user, if
* requested. <strong>NOTE</strong> - configuring Locale selection will
* trigger the creation of a new <code>HttpSession</code> if
* necessary.</p>
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
*/
protected void processLocale(HttpServletRequest request, HttpServletResponse response) {
// Are we configured to select the Locale automatically?
if (!moduleConfig.getControllerConfig().getLocale()) {
return;
}
// Has a Locale already been selected?
HttpSession session = request.getSession();
if (session.getAttribute(Globals.LOCALE_KEY) != null) {
return;
}
// Use the Locale returned by the servlet container (if any)
Locale locale = request.getLocale();
if (locale != null) {
if (log.isDebugEnabled()) {
log.debug(" Setting user locale '" + locale + "'");
}
session.setAttribute(Globals.LOCALE_KEY, locale);
}
}
use of java.util.Locale in project sonarqube by SonarSource.
the class AbstractSelectLocale method execute.
// ---------------------------------------------------------- Public Methods
/**
* <p>Select the <code>Locale</code> to be used for this request.</p>
*
* @param actionCtx The <code>Context</code> for the current request
* @return <code>false</code> so that processing continues
* @throws Exception if thrown by the Action class
*/
public boolean execute(ActionContext actionCtx) throws Exception {
// Are we configured to select Locale automatically?
LOG.trace("retrieve config...");
ModuleConfig moduleConfig = actionCtx.getModuleConfig();
if (!moduleConfig.getControllerConfig().getLocale()) {
if (LOG.isDebugEnabled()) {
LOG.debug("module is not configured for a specific locale; " + "nothing to do");
}
return (false);
}
// Retrieve and cache appropriate Locale for this request
Locale locale = getLocale(actionCtx);
if (LOG.isDebugEnabled()) {
LOG.debug("set context locale to " + locale);
}
actionCtx.setLocale(locale);
return (false);
}
use of java.util.Locale in project sonarqube by SonarSource.
the class TagUtils method message.
/**
* Look up and return a message string, based on the specified
* parameters.
*
* @param pageContext The PageContext associated with this request
* @param bundle Name of the servlet context attribute for our
* message resources bundle
* @param locale Name of the session attribute for our user's Locale
* @param key Message key to be looked up and returned
* @param args Replacement parameters for this message
* @return message string
* @throws JspException if a lookup error occurs (will have been saved in
* the request already)
*/
public String message(PageContext pageContext, String bundle, String locale, String key, Object[] args) throws JspException {
MessageResources resources = retrieveMessageResources(pageContext, bundle, false);
Locale userLocale = getUserLocale(pageContext, locale);
String message = null;
if (args == null) {
message = resources.getMessage(userLocale, key);
} else {
message = resources.getMessage(userLocale, key, args);
}
if ((message == null) && log.isDebugEnabled()) {
// log missing key to ease debugging
log.debug(resources.getMessage("message.resources", key, bundle, locale));
}
return message;
}
use of java.util.Locale in project sonarqube by SonarSource.
the class TagUtils method present.
/**
* Return true if a message string for the specified message key is
* present for the specified <code>Locale</code> and bundle.
*
* @param pageContext The PageContext associated with this request
* @param bundle Name of the servlet context attribute for our
* message resources bundle
* @param locale Name of the session attribute for our user's Locale
* @param key Message key to be looked up and returned
* @return true if a message string for message key exists
* @throws JspException if a lookup error occurs (will have been saved in
* the request already)
*/
public boolean present(PageContext pageContext, String bundle, String locale, String key) throws JspException {
MessageResources resources = retrieveMessageResources(pageContext, bundle, true);
Locale userLocale = getUserLocale(pageContext, locale);
return resources.isPresent(userLocale, key);
}
use of java.util.Locale in project sonarqube by SonarSource.
the class FieldChecks method validateFloatLocale.
/**
* Checks if the field can safely be converted to a float primitive.
*
* @param bean The bean validation is being performed on.
* @param va The <code>ValidatorAction</code> that is currently
* being performed.
* @param field The <code>Field</code> object associated with the
* current field being validated.
* @param errors The <code>ActionMessages</code> object to add errors
* to if any validation errors occur.
* @param validator The <code>Validator</code> instance, used to access
* other field values.
* @param request Current request object.
* @return true if valid, false otherwise.
*/
public static Object validateFloatLocale(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request) {
Object result = null;
String value = null;
value = evaluateBean(bean, field);
if (GenericValidator.isBlankOrNull(value)) {
return Boolean.TRUE;
}
Locale locale = RequestUtils.getUserLocale(request, null);
result = GenericTypeValidator.formatFloat(value, locale);
if (result == null) {
errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
}
return (result == null) ? Boolean.FALSE : result;
}
Aggregations