From dev-return-92159-apmail-geronimo-dev-archive=geronimo.apache.org@geronimo.apache.org Tue Aug 2 05:48:19 2011 Return-Path: X-Original-To: apmail-geronimo-dev-archive@www.apache.org Delivered-To: apmail-geronimo-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D8B0C69A2 for ; Tue, 2 Aug 2011 05:48:19 +0000 (UTC) Received: (qmail 63241 invoked by uid 500); 2 Aug 2011 05:48:18 -0000 Delivered-To: apmail-geronimo-dev-archive@geronimo.apache.org Received: (qmail 62742 invoked by uid 500); 2 Aug 2011 05:48:08 -0000 Mailing-List: contact dev-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list dev@geronimo.apache.org Received: (qmail 62727 invoked by uid 99); 2 Aug 2011 05:48:04 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Aug 2011 05:48:03 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of hanhongfang@gmail.com designates 209.85.210.48 as permitted sender) Received: from [209.85.210.48] (HELO mail-pz0-f48.google.com) (209.85.210.48) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Aug 2011 05:47:55 +0000 Received: by pzk32 with SMTP id 32so14221210pzk.35 for ; Mon, 01 Aug 2011 22:47:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=TSUQWit7EK7Qe99R9HWyEcpHdJORq0MyEXoSP1LbrJU=; b=QiEL9CFvBvzMR/BMtwyCVTH0Q82IwgkfnE6nmaqbX9CW3CvKLj7Za1QoVuK4T3Lrfj Wgytn4CGq37vHcN6VeeYnwTr7rhPOQQ5ZEKHSpfjhg8cvC1qj7LdlddDnVWa3JNbYrTf V643ix8fZRy60Xu9L+TgA5WFzf7iElFcP6+c0= MIME-Version: 1.0 Received: by 10.68.1.170 with SMTP id 10mr7994754pbn.380.1312264053626; Mon, 01 Aug 2011 22:47:33 -0700 (PDT) Received: by 10.68.50.198 with HTTP; Mon, 1 Aug 2011 22:47:33 -0700 (PDT) In-Reply-To: References: <20110802034002.BD3D923888BD@eris.apache.org> Date: Tue, 2 Aug 2011 13:47:33 +0800 Message-ID: Subject: Re: svn commit: r1153013 - /geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java From: han hongfang To: dev@geronimo.apache.org Content-Type: multipart/alternative; boundary=bcaec531480fc4957004a97f4819 X-Virus-Checked: Checked by ClamAV on apache.org --bcaec531480fc4957004a97f4819 Content-Type: text/plain; charset=ISO-8859-1 Thanks Jarek for the comments. I will re-visit the processProperty method regarding unicode and also Properties in Felix. On Tue, Aug 2, 2011 at 12: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, 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 keys2 = new > ArrayList(properties.keySet()); > > + Collections.sort(keys2, new Comparator() { > > + 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 > vars, Map props, String prefix) { > > if (prefix != null) { > > int start = prefix.length(); > > > > > > > -- Best regards, Han Hong Fang (Janet) hanhongfang AT apache.org --bcaec531480fc4957004a97f4819 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thanks Jarek for the comments.

I will re-visit the processProperty = method regarding unicode and also Properties in Felix.

On Tue, Aug 2, 2011 at 12:32 PM, Jarek Gawor <jgawor@gmail.com> w= rote:
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, =A0<hanhongfang@apache.org> wrote:
> Author: hanhongfang
> Date: Tue Aug =A02 03:40:01 2011
> New Revision: 1153013
>
> URL: http://svn.apache.org/viewvc?rev=3D1153013&view= =3Drev
> Log:
> GERONIMO-5310 Better ordering for config-substitutions.properties
>
> Modified:
> =A0 =A0geronimo/server/trunk/framework/modules/geronimo-system/src/mai= n/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java<= br> >
> Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/= main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.ja= va
> URL: http://svn.apache.org/viewvc/= geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/a= pache/geronimo/system/configuration/LocalAttributeManager.java?rev=3D115301= 3&r1=3D1153012&r2=3D1153013&view=3Ddiff
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D
> --- geronimo/server/trunk/framework/modules/geronimo-system/src/main/j= ava/org/apache/geronimo/system/configuration/LocalAttributeManager.java (or= iginal)
> +++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/j= ava/org/apache/geronimo/system/configuration/LocalAttributeManager.java Tue= Aug =A02 03:40:01 2011
> @@ -24,10 +24,14 @@ import java.io.FileOutputStream;
> =A0import java.io.FileReader;
> =A0import java.io.FileWriter;
> =A0import java.io.IOException;
> +import java.io.OutputStreamWriter;
> =A0import java.io.Reader;
> =A0import java.io.Writer;
> =A0import java.util.ArrayList;
> =A0import java.util.Collection;
> +import java.util.Collections;
> +import java.util.Comparator;
> +import java.util.Date;
> =A0import java.util.HashMap;
> =A0import java.util.Iterator;
> =A0import java.util.List;
> @@ -672,10 +676,24 @@ public class LocalAttributeManager imple
> =A0 =A0 private static void storeConfigSubstitutions(File configSubsti= tutionsFile, Properties properties) {
> =A0 =A0 =A0 =A0 if (configSubstitutionsFile !=3D null) {
> =A0 =A0 =A0 =A0 =A0 =A0 try {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0FileOutputStream out =3D new FileOutp= utStream(configSubstitutionsFile);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0OutputStreamWriter out =3D new Output= StreamWriter(new FileOutputStream(configSubstitutionsFile),
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"ISO-8859-1"= ;);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 try {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0out.write(INSTRUCTION);
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0properties.store(out, null);<= br> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0out.write(new String(INSTRUCT= ION));
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0out.write("#" + (ne= w Date()).toString() + "\n");
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ArrayList<String> keys2= =3D new ArrayList(properties.keySet());
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Collections.sort(keys2, new C= omparator<String>() {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0public int compare(St= ring o1, String o2) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return o1.toL= owerCase().compareTo(o2.toLowerCase());
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0});
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0for (Object o : keys2) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0String key =3D (Strin= g) o;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0String value =3D prop= erties.getProperty(key);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0out.write(processProp= erty(key, true) + "=3D" + processProperty(value, false) + "\= n");
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0out.flush();
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } finally {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 out.close();
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> @@ -685,6 +703,17 @@ public class LocalAttributeManager imple
> =A0 =A0 =A0 =A0 }
> =A0 =A0 }
>
> + =A0 =A0// process the value and element of property as what java.uti= l.Properties.store(Writer writer, String comments) does
> + =A0 =A0private static String processProperty(String str, boolean isK= ey) {
> + =A0 =A0 =A0 =A0boolean hasLeadingSpace =3D str.startsWith(" &qu= ot;);
> + =A0 =A0 =A0 =A0String temp0 =3D isKey ? str.replaceAll(" "= , "\\\\ ") : (hasLeadingSpace ? str.replaceFirst(" ", &= quot;\\\\ ") : str);
> + =A0 =A0 =A0 =A0String temp1 =3D temp0.replaceAll("!", &quo= t;\\\\!");
> + =A0 =A0 =A0 =A0String temp2 =3D temp1.replaceAll("#", &quo= t;\\\\#");
> + =A0 =A0 =A0 =A0String temp3 =3D temp2.replaceAll(":", &quo= t;\\\\:");
> + =A0 =A0 =A0 =A0String temp4 =3D temp3.replaceAll("=3D", &q= uot;\\\\=3D");
> + =A0 =A0 =A0 =A0return temp4;
> + =A0 =A0}
> +
> =A0 =A0 private static void addGeronimoSubstitutions(Map<String, Ob= ject> vars, Map props, String prefix) {
> =A0 =A0 =A0 =A0 if (prefix !=3D null) {
> =A0 =A0 =A0 =A0 =A0 =A0 int start =3D prefix.length();
>
>
>



--
Best regards,
<= br>Han Hong Fang (Janet)
hanhongfang=A0AT apach= e.org
=A0

--bcaec531480fc4957004a97f4819--