Results 1 to 4 of 4

Thread: Problem reading Regular Expressions using MessageSource

  1. #1
    Join Date
    Sep 2004
    Posts
    2

    Default Problem reading Regular Expressions using MessageSource

    I am having difficulty reading regular expressions from a properties file using org.springframework.context.support.ResourceBundle MessageSource. The problem arises when the MessageSource interprets parts of the regex as asking for a substitution (like "{0}", "{1,date}", "{2,time}" within a message).

    The regex I am using is: "^\d{1,3}$", which produces an IllegalArgumentException when read from the properties file.

    Is there a way to tell MessageSource to ignore subsitution parameters? Or to hide them?

    (I would assume that if you passed in null as the second parameter to getMessage(String, Object[], Locale), it would not look for substitution parameters.)

  2. #2
    Join Date
    Aug 2004
    Posts
    109

    Default

    This has very little to do with Spring actually, but has everything to do with java.text.MessageFormat class, which spring delegates to when it comes to formatting of the resourced messages.

    So given this info, I would suggest you to read the javadoc for the above mentioned class. My guess as to what you need, to get your regexp
    Code:
    ^\d{1,3}$
    to work, the following change
    Code:
    ^\d'{'1,3'}'$
    should probably do the trick. If not then just read the doc carefully and figure what you really need, since it is pretty detailed

    HTH
    Thanks,
    Alex.

  3. #3
    Join Date
    Sep 2004
    Posts
    2

    Default

    Thanks Alex. It didn't occur to me that this was a wrapper for MessageFormat (too close to the trees to see the forest).

    I'll check out the api.


    Thanks.
    Russell

  4. #4
    Join Date
    Aug 2004
    Posts
    109

    Default

    This has very little to do with Spring actually, but has everything to do with java.text.MessageFormat class, which spring delegates to when it comes to formatting of the resourced messages.

    So given this info, I would suggest you to read the javadoc for the above mentioned class. My guess as to what you need, to get your regexp
    Code:
    ^\d{1,3}$
    to work, the following change
    Code:
    ^\d'{'1,3'}'$
    should probably do the trick. If not then just read the doc carefully and figure what you really need, since it is pretty detailed

    HTH
    Thanks,
    Alex.

Similar Threads

  1. Replies: 19
    Last Post: Sep 10th, 2007, 12:46 PM
  2. Problem in reading Property files.
    By Barani_mdu in forum Container
    Replies: 1
    Last Post: Aug 27th, 2007, 06:22 PM
  3. Reading xml beans files from jar files problem !!!
    By p_e_t_e_r in forum Container
    Replies: 10
    Last Post: Sep 26th, 2005, 12:38 AM
  4. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM
  5. Simple Regular expression problem
    By schuer in forum AOP
    Replies: 3
    Last Post: Feb 22nd, 2005, 03:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •