Search in sources :

Example 81 with Locale

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);
    }
}
Also used : Locale(java.util.Locale) HttpSession(javax.servlet.http.HttpSession)

Example 82 with 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);
}
Also used : Locale(java.util.Locale) ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 83 with Locale

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;
}
Also used : Locale(java.util.Locale) MessageResources(org.apache.struts.util.MessageResources)

Example 84 with Locale

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);
}
Also used : Locale(java.util.Locale) MessageResources(org.apache.struts.util.MessageResources)

Example 85 with Locale

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;
}
Also used : Locale(java.util.Locale)

Aggregations

Locale (java.util.Locale)5854 Test (org.junit.Test)902 HashMap (java.util.HashMap)548 GenericValue (org.apache.ofbiz.entity.GenericValue)504 ArrayList (java.util.ArrayList)486 Delegator (org.apache.ofbiz.entity.Delegator)484 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)398 IOException (java.io.IOException)313 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)296 Date (java.util.Date)273 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)271 Map (java.util.Map)244 BigDecimal (java.math.BigDecimal)214 SimpleDateFormat (java.text.SimpleDateFormat)198 ResourceBundle (java.util.ResourceBundle)197 File (java.io.File)166 LinkedList (java.util.LinkedList)158 ULocale (android.icu.util.ULocale)156 List (java.util.List)147 Test (org.junit.jupiter.api.Test)132