Package org.springframework.context

Examples of org.springframework.context.MessageSourceResolvable


    add(getMessageCode(e.getConstraint()),
        new Object[] { e.getParameter() }, e.toString());
  }

  public void add(String code, Object[] args, String defaultMessage) {
    MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(
        new String[] { code }, args, defaultMessage);
    if (logger.isDebugEnabled()) {
      logger.debug("Adding resolvable: " + resolvable);
    }
    this.args.add(resolvable);
View Full Code Here


  // @TODO - consider standard visitor here...
  void visit(StringLengthConstraint constraint) {
    ClosureResultConstraint c = (ClosureResultConstraint) constraint
        .getPredicate();
    Object p = c.getPredicate();
    MessageSourceResolvable resolvable;
    if (p instanceof ParameterizedBinaryConstraint) {
      resolvable = handleParameterizedBinaryPredicate((ParameterizedBinaryConstraint) p);
    } else {
      resolvable = handleRange((Range) p);
    }
View Full Code Here

    visitorSupport.invokeVisit(this, c.getPredicate());
  }

  private MessageSourceResolvable handleParameterizedBinaryPredicate(
      ParameterizedBinaryConstraint p) {
    MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(
        new String[] { getMessageCode(p.getConstraint()) },
        new Object[] { p.getParameter() }, p.toString());
    return resolvable;
  }
View Full Code Here

        new Object[] { p.getParameter() }, p.toString());
    return resolvable;
  }

  private MessageSourceResolvable handleRange(Range r) {
    MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(
        new String[] { getMessageCode(r) }, new Object[] { r.getMin(),
            r.getMax() }, r.toString());
    return resolvable;
  }
View Full Code Here

        rc.getMessage("testArgs", new String[] {"arg1", "arg2"}, "default"));
    assertEquals("test arg1 message arg2",
        rc.getMessage("testArgs", Arrays.asList(new String[] {"arg1", "arg2"}), "default"));
    assertEquals("default", rc.getMessage("testa", "default"));
    assertEquals("default", rc.getMessage("testa", (List) null, "default"));
    MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"test"});
    assertEquals("test message", rc.getMessage(resolvable));
  }
View Full Code Here

    finally {
      LocaleContextHolder.setLocale(null);
    }

    assertEquals("message3", ac.getMessage("code3", null, Locale.ENGLISH));
    MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable("code3");
    assertEquals("message3", ac.getMessage(resolvable, Locale.ENGLISH));
    resolvable = new DefaultMessageSourceResolvable(new String[] {"code4", "code3"});
    assertEquals("message3", ac.getMessage(resolvable, Locale.ENGLISH));

    assertEquals("message3", ac.getMessage("code3", null, Locale.ENGLISH));
View Full Code Here

  }

  public void testMessageSourceResolvable() {
    // first code valid
    String[] codes1 = new String[] {"message.format.example3", "message.format.example2"};
    MessageSourceResolvable resolvable1 = new DefaultMessageSourceResolvable(codes1, null, "default");
    try {
      assertTrue("correct message retrieved", MSG_TXT3_US.equals(sac.getMessage(resolvable1, Locale.US)));
    }
    catch (NoSuchMessageException ex) {
      fail("Should not throw NoSuchMessageException");
    }

    // only second code valid
    String[] codes2 = new String[] {"message.format.example99", "message.format.example2"};
    MessageSourceResolvable resolvable2 = new DefaultMessageSourceResolvable(codes2, null, "default");
    try {
      assertTrue("correct message retrieved", MSG_TXT2_US.equals(sac.getMessage(resolvable2, Locale.US)));
    }
    catch (NoSuchMessageException ex) {
      fail("Should not throw NoSuchMessageException");
    }

    // no code valid, but default given
    String[] codes3 = new String[] {"message.format.example99", "message.format.example98"};
    MessageSourceResolvable resolvable3 = new DefaultMessageSourceResolvable(codes3, null, "default");
    try {
      assertTrue("correct message retrieved", "default".equals(sac.getMessage(resolvable3, Locale.US)));
    }
    catch (NoSuchMessageException ex) {
      fail("Should not throw NoSuchMessageException");
    }

    // no code valid, no default
    String[] codes4 = new String[] {"message.format.example99", "message.format.example98"};
    MessageSourceResolvable resolvable4 = new DefaultMessageSourceResolvable(codes4);
    try {
      sac.getMessage(resolvable4, Locale.US);
      fail("Should have thrown NoSuchMessageException");
    }
    catch (NoSuchMessageException ex) {
View Full Code Here

    source.setParentMessageSource(parent);

    source.addMessage("param", Locale.ENGLISH, "value");
    parent.addMessage("with.param", Locale.ENGLISH, "put {0} here");

    MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(
        new String[] {"with.param"}, new Object[] {new DefaultMessageSourceResolvable("param")});

    assertEquals("put value here", source.getMessage(resolvable, Locale.ENGLISH));
  }
View Full Code Here

    source.setParentMessageSource(parent);

    parent.addMessage("param", Locale.ENGLISH, "value");
    source.addMessage("with.param", Locale.ENGLISH, "put {0} here");

    MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(
        new String[] {"with.param"}, new Object[] {new DefaultMessageSourceResolvable("param")});

    assertEquals("put value here", source.getMessage(resolvable, Locale.ENGLISH));
  }
View Full Code Here

        rc.getThemeMessage("themetestArgs", new String[] {"arg1"}));
    assertEquals("theme test message arg1",
        rc.getThemeMessage("themetestArgs", Arrays.asList(new String[] {"arg1"})));
    assertEquals("default", rc.getThemeMessage("themetesta", "default"));
    assertEquals("default", rc.getThemeMessage("themetesta", (List) null, "default"));
    MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"themetest"});
    assertEquals("theme test message", rc.getThemeMessage(resolvable));
  }
View Full Code Here

TOP

Related Classes of org.springframework.context.MessageSourceResolvable

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.