[Webtest] How to set the charset UTF-8 for reading prop files
Marek Dębczyński
Marek Dębczyński
Fri, 23 Nov 2007 15:42:58 +0100
Hi Marc
Thanks a lot for your help.
I am very grateful.
Regards
Marek Dębczyński
> Hi,
>
> you have to define your own task to fix the limitations of Ant's
> Property task. For instance something like (my mailer is not a Groovy
> editor, syntax errors are possible):
>
> <groovyScript>
> class MyProperty extends org.apache.tools.ant.taskdefs.Property
> {
> String encoding
> protected void loadFile(File file)
> {
> def text = file.getText(encoding)
> def lines = text.split("[\\n\\r]*")
> lines.each {
> if (!it.startsWith("#")) {
> def pos = it.indexOf("=")
> if (pos > 0) {
> addProperty(it[0..pos], it[(pos+1)..-1])
> }
> }
> }
> }
> }
> project.addTaskDefinition "myProperty", MyProperty
> </groovyScript>
>
> <myProperty file="${propertiesDir}\test_001.prop" encoding="UTF-8"/=
>
> <ant antfile="${useCaseDir}\test_001.xml"/>
>
> You have to try if it can be used nested in <ant>...</ant>, I haven't
> checked.
>
> Cheers,
> Marc.
>
> Marek Dębczyński wrote:
>
>> Hi Marc.
>>
>> Thanks for answer.
>>
>> My target is set as here:
>>
>> <!-- Execute Test Case test_001-->
>> <target name="test_001">
>> <ant antfile="${useCaseDir}\test_001.xml">
>> <property file="${propertiesDir}\test_001.prop"/>
>> </ant>
>> </target>
>>
>> how to set the encoding here?
>>
>> <property name="file.encoding" value="UTF-8"/>
>> set in main xml doesn't work.
>>
>> If U will find where is the ISO-8859-1 set as default I will be very h=
appy.
>>
>> Regards
>> Marek Debczynski
>>
>> Marc Guillemot pisze:
>>
>>> Hi,
>>>
>>> seems to be a requirement for Ant. Already had a look there?
>>>
>>> Ant's property task expects properties files to be in ISO8859-1.
>>> According to a quick look at
>>> org.apache.tools.ant.taskdefs.Property#loadFile, it would be quite ea=
sy
>>> to define a custom version of <property file="..."/> that uses a
>>> different encoding.
>>>
>>> Marc.
>>>
>>>
>> _______________________________________________
>> WebTest mailing list
>> WebTest@lists.canoo.com
>> http://lists.canoo.com/mailman/listinfo/webtest
>>
>>
>
>
>