geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jarek Gawor <jga...@gmail.com>
Subject Re: svn commit: r1153013 - /geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
Date Tue, 02 Aug 2011 04:32:55 GMT
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();
>
>
>

Mime
View raw message