- adding ${variable} interpolation to the getString() methods. the

code was taken from the jetspeed codebase.
PR:
Obtained from:
Submitted by:
Reviewed by:


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130503 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2001-09-21 03:14:40 +00:00
parent 71a401b27b
commit 30a8d35e54
1 changed files with 38 additions and 5 deletions

View File

@ -168,7 +168,7 @@ import java.util.Vector;
* @author <a href="mailto:kjohnson@transparent.com">Kent Johnson</a>
* @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
* @author <a href="mailto:ipriha@surfeu.fi">Ilkka Priha</a>
* @version $Id: ExtendedProperties.java,v 1.4 2001/05/13 21:46:22 geirm Exp $
* @version $Id: ExtendedProperties.java,v 1.5 2001/09/21 03:14:40 jvanzyl Exp $
*/
public class ExtendedProperties extends Hashtable
{
@ -215,6 +215,39 @@ public class ExtendedProperties extends Hashtable
*/
protected ArrayList keysAsListed = new ArrayList();
protected final static String START_TOKEN="${";
protected final static String END_TOKEN="}";
protected String interpolate(String base)
{
if (base == null)
{
return null;
}
int begin = -1;
int end = -1;
int prec = 0 - END_TOKEN.length();
String variable = null;
StringBuffer result = new StringBuffer();
// FIXME: we should probably allow the escaping of the start token
while ( ((begin=base.indexOf(START_TOKEN,prec+END_TOKEN.length()))>-1)
&& ((end=base.indexOf(END_TOKEN,begin))>-1) )
{
result.append(base.substring(prec+END_TOKEN.length(),begin));
variable = base.substring(begin+START_TOKEN.length(),end);
if (get(variable)!=null)
{
result.append(get(variable));
}
prec=end;
}
result.append(base.substring(prec+END_TOKEN.length(),base.length()));
return result.toString();
}
/**
* This class is used to read properties lines. These lines do
* not terminate with new-line chars but rather when there is no
@ -986,22 +1019,22 @@ public class ExtendedProperties extends Hashtable
if (value instanceof String)
{
return (String) value;
return (String) interpolate((String)value);
}
else if (value == null)
{
if (defaults != null)
{
return defaults.getString(key, defaultValue);
return interpolate(defaults.getString(key, defaultValue));
}
else
{
return defaultValue;
return interpolate(defaultValue);
}
}
else if (value instanceof Vector)
{
return (String) ((Vector) value).get(0);
return interpolate((String) ((Vector) value).get(0));
}
else
{