Package org.springframework.context

Examples of org.springframework.context.MessageSource


   * @param requestContext the context for the current HTTP request,
   * including the ApplicationContext to expose as MessageSource
   */
  public static void exposeLocalizationContext(RequestContext requestContext) {
    Config.set(requestContext.getRequest(), Config.FMT_LOCALE, requestContext.getLocale());
    MessageSource messageSource = getJstlAwareMessageSource(
        requestContext.getServletContext(), requestContext.getMessageSource());
    LocalizationContext jstlContext = new SpringLocalizationContext(messageSource, requestContext.getRequest());
    Config.set(requestContext.getRequest(), Config.FMT_LOCALIZATION_CONTEXT, jstlContext);
  }
View Full Code Here


    }
    if (base == null && RESOURCE_BUNDLE_KEY.equals(property)) {
      context.setPropertyResolved(true);
      return MessageSource.class;
    } else if (base instanceof MessageSource) {
      MessageSource messageSource = (MessageSource) base;
      String message = messageSource.getMessage(property.toString(), null, null, getLocale());
      if (message != null) {
        context.setPropertyResolved(true);
        return String.class;
      }
    }
View Full Code Here

    }
    if (base == null && RESOURCE_BUNDLE_KEY.equals(property)) {
      context.setPropertyResolved(true);
      return getMessageSource();
    } else if (base instanceof MessageSource) {
      MessageSource messageSource = (MessageSource) base;
      String message = messageSource.getMessage(property.toString(), null, null, getLocale());
      if (message != null) {
        context.setPropertyResolved(true);
        return message;
      }
    }
View Full Code Here

   * @param locale the Locale in which to do the lookup
   * @return the resolved message, or <code>null</code> if not found
   * @see #getParentMessageSource()
   */
  protected String getMessageFromParent(String code, Object[] args, Locale locale) {
    MessageSource parent = getParentMessageSource();
    if (parent != null) {
      if (parent instanceof AbstractMessageSource) {
        // Call internal method to avoid getting the default code back
        // in case of "useCodeAsDefaultMessage" being activated.
        return ((AbstractMessageSource) parent).getMessageInternal(code, args, locale);
      }
      else {
        // Check parent MessageSource, returning null if not found there.
        return parent.getMessage(code, args, null, locale);
      }
    }
    // Not found in parent either.
    return null;
  }
View Full Code Here

     * @see I18nResourceProvider#getResource(String, String, Tag, PageContext)
     */
    @Override
    public String getResource(String resourceKey, String defaultValue, Tag tag, PageContext pageContext)
    {
        MessageSource messageSource = RequestContextUtils.getWebApplicationContext(pageContext.getRequest(), pageContext.getServletContext());
        if (messageSource == null)
        {
            log.warn("messageSource not found");
            return null;
        }

        // if resourceKey isn't defined either, use defaultValue
        String key = (resourceKey != null) ? resourceKey : defaultValue;

        String message = null;

        message = messageSource.getMessage(key, null, null, RequestContextUtils
            .getLocale((HttpServletRequest) pageContext.getRequest()));

        // if user explicitely added a titleKey we guess this is an error
        if (message == null && resourceKey != null)
        {
View Full Code Here

   * @param locale the Locale in which to do the lookup
   * @return the resolved message, or <code>null</code> if not found
   * @see #getParentMessageSource()
   */
  protected String getMessageFromParent(String code, Object[] args, Locale locale) {
    MessageSource parent = getParentMessageSource();
    if (parent != null) {
      if (parent instanceof AbstractMessageSource) {
        // Call internal method to avoid getting the default code back
        // in case of "useCodeAsDefaultMessage" being activated.
        return ((AbstractMessageSource) parent).getMessageInternal(code, args, locale);
      }
      else {
        // Check parent MessageSource, returning null if not found there.
        return parent.getMessage(code, args, null, locale);
      }
    }
    // Not found in parent either.
    return null;
  }
View Full Code Here

  /**
   * Resolve the specified message into a concrete message String.
   * The returned message String should be unescaped.
   */
  protected String resolveMessage() throws JspException, NoSuchMessageException {
    MessageSource messageSource = getMessageSource();
    if (messageSource == null) {
      throw new JspTagException("No corresponding MessageSource found");
    }

    // Evaluate the specified MessageSourceResolvable, if any.
    MessageSourceResolvable resolvedMessage = null;
    if (this.message instanceof MessageSourceResolvable) {
      resolvedMessage = (MessageSourceResolvable) this.message;
    }
    else if (this.message != null) {
      String expr = this.message.toString();
      resolvedMessage = (MessageSourceResolvable)
          ExpressionEvaluationUtils.evaluate("message", expr, MessageSourceResolvable.class, pageContext);
    }

    if (resolvedMessage != null) {
      // We have a given MessageSourceResolvable.
      return messageSource.getMessage(resolvedMessage, getRequestContext().getLocale());
    }

    String resolvedCode = ExpressionEvaluationUtils.evaluateString("code", this.code, pageContext);
    String resolvedText = ExpressionEvaluationUtils.evaluateString("text", this.text, pageContext);

    if (resolvedCode != null || resolvedText != null) {
      // We have a code or default text that we need to resolve.
      Object[] argumentsArray = resolveArguments(this.arguments);
      if (resolvedText != null) {
        // We have a fallback text to consider.
        return messageSource.getMessage(
            resolvedCode, argumentsArray, resolvedText, getRequestContext().getLocale());
      }
      else {
        // We have no fallback text to consider.
        return messageSource.getMessage(
            resolvedCode, argumentsArray, getRequestContext().getLocale());
      }
    }

    // All we have is a specified literal text.
View Full Code Here

   * @param locale the Locale in which to do the lookup
   * @return the resolved message, or <code>null</code> if not found
   * @see #getParentMessageSource()
   */
  protected String getMessageFromParent(String code, Object[] args, Locale locale) {
    MessageSource parent = getParentMessageSource();
    if (parent != null) {
      if (parent instanceof AbstractMessageSource) {
        // Call internal method to avoid getting the default code back
        // in case of "useCodeAsDefaultMessage" being activated.
        return ((AbstractMessageSource) parent).getMessageInternal(code, args, locale);
      }
      else {
        // Check parent MessageSource, returning null if not found there.
        return parent.getMessage(code, args, null, locale);
      }
    }
    // Not found in parent either.
    return null;
  }
View Full Code Here

      // manually set the size, otherwise sometimes the overlay is not
      // shown (it has size 0,0)
      getControl().setSize(getControl().getPreferredSize());

      if (visible) {
        MessageSource messageSource = (MessageSource) ApplicationServicesLocator.services().getService(
            MessageSource.class);
        String dirtyTooltip = messageSource.getMessage(DIRTY_MESSAGE_KEY, new Object[] {
            formModel.getFieldFace(propertyName).getDisplayName(), originalValueHolder.getValue() }, Locale
            .getDefault());
        dirtyLabel.setToolTipText(dirtyTooltip);

        String revertTooltip = messageSource.getMessage(REVERT_MESSAGE_KEY, new Object[] { formModel
            .getFieldFace(propertyName).getDisplayName() }, Locale.getDefault());
        revertButton.setToolTipText(revertTooltip);
      }
    }
View Full Code Here

      GoogleSearch googleSearch = new GoogleSearch();
      googleSearch.setKey(getGoogleKey());
      googleSearch.setQueryString(query);
      googleSearch.setStartResult(startResult);
      try{
        MessageSource messageSource = (MessageSource)ApplicationServicesLocator.services().getService(MessageSource.class);
        String title = messageSource.getMessage(PROGESS_MESSAGE, new Object[]{}, Locale.getDefault());
        getStatusBar().getProgressMonitor().taskStarted(title, StatusBarProgressMonitor.UNKNOWN);
        return googleSearch.doSearch();
      }
      finally{
        getStatusBar().getProgressMonitor().done();
View Full Code Here

TOP

Related Classes of org.springframework.context.MessageSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.