You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by T E Schmitz <ma...@numerixtechnology.de> on 2004/04/21 12:17:20 UTC
[Re: [configuration] specify a regular expression as string property]
I realize that the question below was rather too specific for anyone to
know the answer off-hand.
But does anyone know what determines whether a property is interpreted
as String, Float, Integer or ArrayList?
Regards,
Tarlika Elisabeth Schmitz
-------- Original Message --------
Subject: [configuration] specify a regular expression as string property
Date: Sun, 18 Apr 2004 00:39:20 +0100
From: T E Schmitz <ma...@numerixtechnology.de>
Reply-To: mail@numerixtechnology.de
To: commons-user@jakarta.apache.org
Hello,
I would like to specify a regular expression as a string property.
Example:
first.name.pattern=.{0,30}
or alternatively in an xml configuration file:
<pattern>.{0,30}</pattern>
Unfortunately this expression is interpreted as ArrayList. Is there any
way to escape it so that it will be interpreted as a String?
Any help is very much appreciated.
--
Regards,
Tarlika Elisabeth Schmitz
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Re: [configuration] specify a regular expression as string property]
Posted by T E Schmitz <ma...@numerixtechnology.de>.
I tested the expression with HierarchicalDom4JConfiguration. It does not
require any escaping:
<format>.{0,30}</format>
is interpreted as String.
Regards,
Tarlika Elisabeth Schmitz
Oliver Heger wrote:
> Which configuration class do you use for loading the XML file,
> Dom4JConfiguration or HierarchicalDom4JConfiguration? I think the latter
> one directly stores the values of XML elements and does not try to
> detect any list structures.
>
> AFAIK there is no special treatment of backslash characters in XML
> files, so I would suppose that a single backslash should work.
>
> Oliver
>
> T E Schmitz schrieb:
>
>>
>> Do you also happen to know how I would have to express this in an XML
>> config file? Also with a double-backslash? I remember trying one
>> backslash and that didn't escape the comma.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Re: [configuration] specify a regular expression as string property]
Posted by Oliver Heger <he...@med.uni-marburg.de>.
Which configuration class do you use for loading the XML file,
Dom4JConfiguration or HierarchicalDom4JConfiguration? I think the latter
one directly stores the values of XML elements and does not try to
detect any list structures.
AFAIK there is no special treatment of backslash characters in XML
files, so I would suppose that a single backslash should work.
Oliver
T E Schmitz schrieb:
>
> Do you also happen to know how I would have to express this in an XML
> config file? Also with a double-backslash? I remember trying one
> backslash and that didn't escape the comma.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Re: [configuration] specify a regular expression as string property]
Posted by T E Schmitz <ma...@numerixtechnology.de>.
Oliver Heger wrote:
> If you use a properties file, you will have to double the backslash so
> that it is recognized by java.util.Properties. Single backslashes are
> interpreted as the beginning of an escape sequence. So you should have
> something like
> biz.objects.brand.regex=.{0\\,30}
That works. Brilliant!!!
Do you also happen to know how I would have to express this in an XML
config file? Also with a double-backslash? I remember trying one
backslash and that didn't escape the comma.
> Have a look at the JavaDocs for the load() method of
> java.util.Properties.
Thanks for the RTFM comment ;-) I hadn't looked at that.
Best Regards,
Tarlika
>
> T E Schmitz schrieb:
>
>> Sorry guys, that doesn't work either :-(
>>
>> I had tried that before; and tried it again:
>>
>> biz.objects.brand.regex=.{0\,30}
>> Object o = config.getProperty("biz.objects.brand.regex");
>> logger.info ("REGEX " + o + " " + o.getClass());
>>
>> Message: REGEX [.{0, 30}] class java.util.ArrayList
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Re: [configuration] specify a regular expression as string property]
Posted by Oliver Heger <he...@med.uni-marburg.de>.
If you use a properties file, you will have to double the backslash so
that it is recognized by java.util.Properties. Single backslashes are
interpreted as the beginning of an escape sequence. So you should have
something like
biz.objects.brand.regex=.{0\\,30}
Have a look at the JavaDocs for the load() method of
java.util.Properties. (I ran in the same trouble once when I tried to
define windows pathes in properties files.)
Oliver
T E Schmitz schrieb:
> Sorry guys, that doesn't work either :-(
>
> I had tried that before; and tried it again:
>
> biz.objects.brand.regex=.{0\,30}
> Object o = config.getProperty("biz.objects.brand.regex");
> logger.info ("REGEX " + o + " " + o.getClass());
>
> Message: REGEX [.{0, 30}] class java.util.ArrayList
>
>
> Regards,
>
> Tarlika
>
>
> Oliver Heger wrote:
>
>> Yes, you are right. A backslash should do the trick.
>>
>> Tatu Vanhanen schrieb:
>>
>>> The PropertiesTokenizer lets you escape commas with a backslash
>>> ('\'). So
>>> the getString() should return a regular expression string with the
>>> commas,
>>> right?
>>>
>>> So have you tried
>>> first.name.pattern=.{0\,30}
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>>
>>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Re: [configuration] specify a regular expression as string property]
Posted by T E Schmitz <ma...@numerixtechnology.de>.
Sorry guys, that doesn't work either :-(
I had tried that before; and tried it again:
biz.objects.brand.regex=.{0\,30}
Object o = config.getProperty("biz.objects.brand.regex");
logger.info ("REGEX " + o + " " + o.getClass());
Message: REGEX [.{0, 30}] class java.util.ArrayList
Regards,
Tarlika
Oliver Heger wrote:
> Yes, you are right. A backslash should do the trick.
>
>
> Tatu Vanhanen schrieb:
>
>> The PropertiesTokenizer lets you escape commas with a backslash ('\'). So
>> the getString() should return a regular expression string with the
>> commas,
>> right?
>>
>> So have you tried
>> first.name.pattern=.{0\,30}
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Re: [configuration] specify a regular expression as string property]
Posted by Oliver Heger <he...@med.uni-marburg.de>.
Yes, you are right. A backslash should do the trick. Must have been blind...
Oliver
Tatu Vanhanen schrieb:
> The PropertiesTokenizer lets you escape commas with a backslash ('\'). So
> the getString() should return a regular expression string with the commas,
> right?
>
> So have you tried
> first.name.pattern=.{0\,30}
>
> Could also be that I'm missing something important...
>
> - Tatu V.
>
>
>>>of AbstractConfiguration. For String properties it essentially boils
>>>down to a special tokenizer class PropertiesTokenizer, which uses the
>>>comma "," as delimiter to split the string into a list. If I don't miss
>>>anything, I don't see a possibility to alter this behaviour, e.g. by
>>>escaping the comma.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
--
Dipl.-Inform. Oliver Heger
Zentrale Informationsverarbeitung (ZIV) / Bereich Anwenderverfahren
Klinikum der Philipps-Universität Marburg
Bunsenstraße 3,
D-35037 Marburg
Tel: +49 6421 28-66592
mailto:oliver.heger@med.uni-marburg.de
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
RE: [Re: [configuration] specify a regular expression as string property]
Posted by Tatu Vanhanen <ta...@graftor.fi>.
The PropertiesTokenizer lets you escape commas with a backslash ('\'). So
the getString() should return a regular expression string with the commas,
right?
So have you tried
first.name.pattern=.{0\,30}
Could also be that I'm missing something important...
- Tatu V.
> > of AbstractConfiguration. For String properties it essentially boils
> > down to a special tokenizer class PropertiesTokenizer, which uses the
> > comma "," as delimiter to split the string into a list. If I don't miss
> > anything, I don't see a possibility to alter this behaviour, e.g. by
> > escaping the comma.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Re: [configuration] specify a regular expression as string property]
Posted by T E Schmitz <ma...@numerixtechnology.de>.
Thank you for your reply, Oliver.
Oliver Heger wrote:
> The interpretation of properties takes place in the addProperty() method
> of AbstractConfiguration. For String properties it essentially boils
> down to a special tokenizer class PropertiesTokenizer, which uses the
> comma "," as delimiter to split the string into a list. If I don't miss
> anything, I don't see a possibility to alter this behaviour, e.g. by
> escaping the comma.
You're right - it appears that the behaviour is determined by the inner
class PropertiesTokenizer. By the looks of it the comma in my regular
expression is causing the problem then.
As far as I understand, if you load a properties file "the ordinary
way", the property will just be returned as a string. It would seem a
shame though as Commons Configuartion is such a convenient interface.
Regards,
Tarlika
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Re: [configuration] specify a regular expression as string property]
Posted by Oliver Heger <he...@med.uni-marburg.de>.
The interpretation of properties takes place in the addProperty() method
of AbstractConfiguration. For String properties it essentially boils
down to a special tokenizer class PropertiesTokenizer, which uses the
comma "," as delimiter to split the string into a list. If I don't miss
anything, I don't see a possibility to alter this behaviour, e.g. by
escaping the comma.
I remember that there was a discussion on the developer list a while ago
about the subjects list handling and escaping of string properties. You
may find something in the archieves, or maybe somebody chimes in who
knows more about this.
The type of the properties you get also depents on the getter methods
you use. Properties read from a file are usually stored as strings (or
lists of strings if they contain a comma). If you call getInt() for
instance, the method tries to convert the property into an int.
Oliver
T E Schmitz schrieb:
> I realize that the question below was rather too specific for anyone to
> know the answer off-hand.
>
> But does anyone know what determines whether a property is interpreted
> as String, Float, Integer or ArrayList?
>
>
> Regards,
>
> Tarlika Elisabeth Schmitz
>
>
> -------- Original Message --------
> Subject: [configuration] specify a regular expression as string property
> Date: Sun, 18 Apr 2004 00:39:20 +0100
> From: T E Schmitz <ma...@numerixtechnology.de>
> Reply-To: mail@numerixtechnology.de
> To: commons-user@jakarta.apache.org
>
> Hello,
>
> I would like to specify a regular expression as a string property.
> Example:
> first.name.pattern=.{0,30}
> or alternatively in an xml configuration file:
> <pattern>.{0,30}</pattern>
>
> Unfortunately this expression is interpreted as ArrayList. Is there any
> way to escape it so that it will be interpreted as a String?
>
>
> Any help is very much appreciated.
--
Dipl.-Inform. Oliver Heger
Zentrale Informationsverarbeitung (ZIV) / Bereich Anwenderverfahren
Klinikum der Philipps-Universität Marburg
Bunsenstraße 3,
D-35037 Marburg
Tel: +49 6421 28-66592
mailto:oliver.heger@med.uni-marburg.de
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org