Changes using felix Properties class is committed at revision: 1153754.

On Tue, Aug 2, 2011 at 2:07 PM, han hongfang <hanhongfang@gmail.com> wrote:
Yes, just tested with unicode value in the property file, and processProperty() can not deal it correctly as java.util.Property does. I'm going to rewrite with felix properties.

On Tue, Aug 2, 2011 at 2:00 PM, David Jencks <david_jencks@yahoo.com> wrote:
I agree, this is a bad idea since the felix properties class is well known and well tested.

The usual way to use this class is to use the maven-bundle-plugin to include it in your jar.  I really don't recommend maintaining a copy in geronimo unless we really need modifications.  Any changes you want to propose should be pushed back to the felix community.

Please rewrite this using the felix properties class.

thanks
david jencks


On Aug 1, 2011, at 9:32 PM, Jarek Gawor wrote:

> I don't think I trust this processProperty() code. It doesn't seem to
> support Unicode escaping for one. I would also strongly encourage
> using the Properties class from the Felix util bundle (e.g. just pull
> in the class into Geronimo and modify as necessary).
>
> Jarek
>
> On Mon, Aug 1, 2011 at 11:40 PM,  <hanhongfang@apache.org> wrote:
>> Author: hanhongfang
>> Date: Tue Aug  2 03:40:01 2011
>> New Revision: 1153013
>>
>> URL: http://svn.apache.org/viewvc?rev=1153013&view=rev
>> Log:
>> GERONIMO-5310 Better ordering for config-substitutions.properties
>>
>> Modified:
>>    geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
>>
>> Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
>> URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java?rev=1153013&r1=1153012&r2=1153013&view=diff
>> ==============================================================================
>> --- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java (original)
>> +++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java Tue Aug  2 03:40:01 2011
>> @@ -24,10 +24,14 @@ import java.io.FileOutputStream;
>>  import java.io.FileReader;
>>  import java.io.FileWriter;
>>  import java.io.IOException;
>> +import java.io.OutputStreamWriter;
>>  import java.io.Reader;
>>  import java.io.Writer;
>>  import java.util.ArrayList;
>>  import java.util.Collection;
>> +import java.util.Collections;
>> +import java.util.Comparator;
>> +import java.util.Date;
>>  import java.util.HashMap;
>>  import java.util.Iterator;
>>  import java.util.List;
>> @@ -672,10 +676,24 @@ public class LocalAttributeManager imple
>>     private static void storeConfigSubstitutions(File configSubstitutionsFile, Properties properties) {
>>         if (configSubstitutionsFile != null) {
>>             try {
>> -                FileOutputStream out = new FileOutputStream(configSubstitutionsFile);
>> +                OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(configSubstitutionsFile),
>> +                        "ISO-8859-1");
>>                 try {
>> -                    out.write(INSTRUCTION);
>> -                    properties.store(out, null);
>> +                    out.write(new String(INSTRUCTION));
>> +                    out.write("#" + (new Date()).toString() + "\n");
>> +
>> +                    ArrayList<String> keys2 = new ArrayList(properties.keySet());
>> +                    Collections.sort(keys2, new Comparator<String>() {
>> +                        public int compare(String o1, String o2) {
>> +                            return o1.toLowerCase().compareTo(o2.toLowerCase());
>> +                        }
>> +                    });
>> +                    for (Object o : keys2) {
>> +                        String key = (String) o;
>> +                        String value = properties.getProperty(key);
>> +                        out.write(processProperty(key, true) + "=" + processProperty(value, false) + "\n");
>> +                    }
>> +                    out.flush();
>>                 } finally {
>>                     out.close();
>>                 }
>> @@ -685,6 +703,17 @@ public class LocalAttributeManager imple
>>         }
>>     }
>>
>> +    // process the value and element of property as what java.util.Properties.store(Writer writer, String comments) does
>> +    private static String processProperty(String str, boolean isKey) {
>> +        boolean hasLeadingSpace = str.startsWith(" ");
>> +        String temp0 = isKey ? str.replaceAll(" ", "\\\\ ") : (hasLeadingSpace ? str.replaceFirst(" ", "\\\\ ") : str);
>> +        String temp1 = temp0.replaceAll("!", "\\\\!");
>> +        String temp2 = temp1.replaceAll("#", "\\\\#");
>> +        String temp3 = temp2.replaceAll(":", "\\\\:");
>> +        String temp4 = temp3.replaceAll("=", "\\\\=");
>> +        return temp4;
>> +    }
>> +
>>     private static void addGeronimoSubstitutions(Map<String, Object> vars, Map props, String prefix) {
>>         if (prefix != null) {
>>             int start = prefix.length();
>>
>>
>>




--
Best regards,

Han Hong Fang (Janet)
hanhongfang AT apache.org
 




--
Best regards,

Han Hong Fang (Janet)
hanhongfang AT apache.org