Package org.springframework.context

Examples of org.springframework.context.MessageSource


  @Override
  protected MessageFormat resolveCode(String code, Locale locale) {
    String codePart = code;
    MessageFormat res = super.resolveCode(codePart, locale);
    if (res == null) {
      MessageSource parent = getParentMessageSource();
      if (parent instanceof EnhancedResourceBundleMessageSource) {
        res = ((EnhancedResourceBundleMessageSource) parent).baseResolveCode(
            code, locale);
      }
    }
    int dotIndex = codePart.indexOf(DOT);

    while (resolveNested && res == null && dotIndex > 0) {
      codePart = codePart.substring(dotIndex + 1);
      res = super.resolveCode(codePart, locale);
      if (res == null) {
        MessageSource parent = getParentMessageSource();
        if (parent instanceof EnhancedResourceBundleMessageSource) {
          res = ((EnhancedResourceBundleMessageSource) parent).baseResolveCode(
              code, locale);
        }
      }
View Full Code Here


  @Override
  protected String resolveCodeWithoutArguments(String code, Locale locale) {
    String codePart = code;
    String res = super.resolveCodeWithoutArguments(codePart, locale);
    if (res == null) {
      MessageSource parent = getParentMessageSource();
      if (parent instanceof EnhancedResourceBundleMessageSource) {
        res = ((EnhancedResourceBundleMessageSource) parent)
            .baseResolveCodeWithoutArguments(code, locale);
      }
    }
    int dotIndex = codePart.indexOf(DOT);

    while (resolveNested && res == null && dotIndex > 0) {
      codePart = codePart.substring(dotIndex + 1);
      res = super.resolveCodeWithoutArguments(codePart, locale);
      if (res == null) {
        MessageSource parent = getParentMessageSource();
        if (parent instanceof EnhancedResourceBundleMessageSource) {
          res = ((EnhancedResourceBundleMessageSource) parent)
              .baseResolveCodeWithoutArguments(code, locale);
        }
      }
View Full Code Here

        return methodTextField;
    }

    @Test
    public void testTranslate() {
        MessageSource messageSource = mock(MessageSource.class);
        when(messageSource.getMessage("privateLabel.caption", null, "", Locale.ENGLISH)).thenReturn("Private Label Caption");
        when(messageSource.getMessage("publicLabel.caption", null, "", Locale.ENGLISH)).thenReturn("Public Label Caption");
        when(messageSource.getMessage("textField.caption", null, "", Locale.ENGLISH)).thenReturn("Text Field Caption");
        when(messageSource.getMessage("textField.description", null, "", Locale.ENGLISH)).thenReturn("Text Field Description");
        when(messageSource.getMessage("methodLabel.caption", null, "", Locale.ENGLISH)).thenReturn("Method Label Caption");
        when(messageSource.getMessage("methodTextField.caption", null, "", Locale.ENGLISH)).thenReturn("Method Text Field Caption");
        when(messageSource.getMessage("methodTextField.description", null, "", Locale.ENGLISH)).thenReturn("Method Text Field Description");

        new Translator(this).translate(Locale.ENGLISH, messageSource);

        assertEquals("Private Label Caption", privateLabel.getCaption());
        assertEquals("Public Label Caption", publicLabel.getCaption());
View Full Code Here

        ValidatorResources resources = getValidatorResources();

        Form form = resources.getForm(locale, formName);
        if (form != null) {
            if ("true".equalsIgnoreCase(dynamicJavascript)) {
                MessageSource messages = getMessageSource();

                List lActions = new ArrayList();
                List lActionMethods = new ArrayList();

                // Get List of actions for this Form
View Full Code Here

  public IconProgressStatusBarItem(){
  }

  public AbstractButton createCancelButton(){
    IconSource iconSource = (IconSource)ApplicationServicesLocator.services().getService(IconSource.class);
    MessageSource messageSource = (MessageSource)ApplicationServicesLocator.services().getService(MessageSource.class);
    AbstractAction action = new AbstractAction(null, iconSource.getIcon(CANCEL_ICON)){
      public void actionPerformed(ActionEvent event) {
        CancelCallback callback = getCancelCallback();
        if(callback != null){
          callback.cancelPerformed();
        }
      }
    };
    AbstractButton button = new JideButton(action);
    button.setToolTipText(messageSource.getMessage(CANCEL_TOOLTIP, new Object[]{}, Locale.getDefault()));
    return button;
  }
View Full Code Here

  /**
   * Method to obtain a message from the message source
   * defined via the services locator, at the default locale.
   */
  protected String getMessage(String key, Object[] params){
    MessageSource messageSource = (MessageSource)ApplicationServicesLocator.services().getService(MessageSource.class);
    return messageSource.getMessage(key, params, Locale.getDefault());
  }
View Full Code Here

    }
    synchronized (this.themeCache) {
      Theme theme = (Theme) this.themeCache.get(themeName);
      if (theme == null) {
        String basename = this.basenamePrefix + themeName;
        MessageSource messageSource = createMessageSource(basename);
        theme = new SimpleTheme(themeName, messageSource);
        initParent(theme);
        this.themeCache.put(themeName, theme);
        if (logger.isDebugEnabled()) {
          logger.debug("Theme created: name '" + themeName + "', basename [" + basename + "]");
View Full Code Here

  public String getStartDateToDisplay() {
    return new SimpleDateFormat(Constants.DATE_FORMAT).format(startDate);   
  }
  public String getDuration(){
    String msg="";
    MessageSource messageSource = ServiceLocator.getMessageSource();
    if(option==1)
      msg = messageSource.getMessage("label.duration.currentMonth",null, new Locale("EN"));     
    else if(option==2)
      msg = messageSource.getMessage("label.duration.currentAndLastMonth",null, new Locale("EN"))
    else if(option==4)
      msg = messageSource.getMessage("label.duration.currentYear",null, new Locale("EN"));
   
    return msg;
  }
View Full Code Here

    SeedsService seedsService = (SeedsService)BeanLocatorFactory.getBean("seedsService");
    return seedsService;
  }
   
    public static MessageSource getMessageSource(){
        MessageSource messageSource = null;
        try {
            messageSource = (MessageSource)BeanLocatorFactory.getService(MessageSource.class);
        }
        catch (BeanLookupException e) {
            e.printStackTrace();
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

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.