Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 42094 invoked from network); 16 Aug 2005 20:52:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 16 Aug 2005 20:52:42 -0000 Received: (qmail 81632 invoked by uid 500); 16 Aug 2005 20:52:39 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 81571 invoked by uid 500); 16 Aug 2005 20:52:39 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 81558 invoked by uid 99); 16 Aug 2005 20:52:39 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Aug 2005 13:52:39 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of tomAtLinux@gmx.at designates 213.165.64.20 as permitted sender) Received: from [213.165.64.20] (HELO mail.gmx.net) (213.165.64.20) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 16 Aug 2005 13:52:59 -0700 Received: (qmail invoked by alias); 16 Aug 2005 20:52:36 -0000 Received: from mail.bestsolution.at (EHLO [192.168.100.12]) [83.64.113.2] by mail.gmx.net (mp001) with SMTP; 16 Aug 2005 22:52:36 +0200 X-Authenticated: #6137719 Message-ID: <43025214.3000307@gmx.at> Date: Tue, 16 Aug 2005 22:52:36 +0200 From: Tom Schindl User-Agent: Mozilla Thunderbird 1.0.6-1mdk (X11/20050322) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jakarta Commons Developers List Subject: Re: [lang] Questions concerning VariableFormatter References: In-Reply-To: X-Enigmail-Version: 0.92.0.0 Content-Type: multipart/mixed; boundary="------------000506000409000802070209" X-Y-GMX-Trusted: 0 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --------------000506000409000802070209 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 oh. and the last VariableFormatter now really working. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org iD8DBQFDAlIUkVPeOFLgZFIRAp9PAJ9/VFwjRFT62dF+dmREvbsHV3L0pQCgrYmm g2j04O/D+oOmFZwT9jxs/WA= =Ij5q -----END PGP SIGNATURE----- --------------000506000409000802070209 Content-Type: text/x-java; name="VariableFormatterWithFormating.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="VariableFormatterWithFormating.java" package org.apache.commons.lang.text; import java.text.MessageFormat; import java.util.Map; public class VariableFormatterWithFormating extends VariableFormatter { /** *

* A VariableResolver backed by a {@link Map} who uses Formats like MessageFormat does *

* @author Tom Schindl * @version $Id: $ */ public static class MapVariableResolverWithFormats extends MapVariableResolver { /** * Creates a new variable resolver to handle formats like * {@link MessageFormat} does it. You can use e.g. {today,date,short} to * format the variable today as a short date * * @param map * The variable names and values. */ public MapVariableResolverWithFormats(Map map) { super(map); } /** * Resolves the variable and formats the object retrieved using * {@link MessageFormat} * * @param varName * name of the variable and optionally the data-type and * data-format seperated by comma */ public Object resolveVariable(String varName) { int index; if (this.getMap() != null && (index = varName.indexOf(",")) != -1) { return MessageFormat.format("{0" + varName.substring(index) + "}", new Object[] { this.getMap().get( varName.substring(0, index)) }); } else { return super.resolveVariable(varName); } } } /** * Creates a new instance with defaults for variable prefix and suffix and the escaping character. */ public VariableFormatterWithFormating() { this((VariableResolver) null, DEFAULT_PREFIX, DEFAULT_SUFFIX, DEFAULT_ESCAPE); } /** * Creates a new instance and initializes it. Uses defaults for variable prefix and suffix and the escaping * character. * * @param valueMap * the map with the variables' values */ public VariableFormatterWithFormating(Map valueMap) { this(valueMap, DEFAULT_PREFIX, DEFAULT_SUFFIX, DEFAULT_ESCAPE); } /** * Creates a new instance and initializes it. Uses a default escaping character. * * @param valueMap * the map with the variables' values * @param prefix * the prefix for variables * @param suffix * the suffix for variables */ public VariableFormatterWithFormating(Map valueMap, String prefix, String suffix) { this(valueMap, prefix, suffix, DEFAULT_ESCAPE); } /** * Creates a new instance and initializes it. * * @param valueMap * the map with the variables' values * @param prefix * the prefix for variables * @param suffix * the suffix for variables * @param escape * the escape character */ public VariableFormatterWithFormating(Map valueMap, String prefix, String suffix, char escape) { this(new MapVariableResolverWithFormats(valueMap), prefix, suffix, escape); } /** * Creates a new instance and initializes it. * * @param variableResolver * the variable resolver * @param prefix * the prefix for variables * @param suffix * the suffix for variables * @param escape * the escape character */ public VariableFormatterWithFormating(VariableResolver variableResolver, String prefix, String suffix, char escape) { super(variableResolver,prefix,suffix,escape); } /** * Replaces the occurrences of all variables in the given source data by their current values obtained from the * passed in map. * * @param valueMap * the map with the values * @param source * the source text * @return the result of the replace operation */ public static String replace(Map valueMap, Object source) { return new VariableFormatterWithFormating(valueMap).replace(source); } /** * Replaces the occurrences of all variables in the given source data by their current values obtained from the * passed in map. This method allows to specifiy a custom variable prefix and suffix * * @param valueMap * the map with the values * @param prefix * the prefix of variables * @param suffix * the suffix of variables * @param source * the source text * @return the result of the replace operation */ public static String replace(Map valueMap, String prefix, String suffix, Object source) { return new VariableFormatterWithFormating(valueMap, prefix, suffix).replace(source); } /** * Replaces all variables in the given source data with values obtained from system properties. * * @param source * the source text * @return the result of the replace operation */ public static String replaceSystemProperties(Object source) { return new VariableFormatterWithFormating(System.getProperties()).replace(source); } } --------------000506000409000802070209 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org --------------000506000409000802070209--