You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by jv...@apache.org on 2001/03/04 01:39:27 UTC
cvs commit: jakarta-velocity/src/java/org/apache/velocity/runtime/configuration Configuration.java Configurations.java ConfigurationsRepository.java ExtendedProperties.java
jvanzyl 01/03/03 16:39:27
Modified: src/java/org/apache/velocity/runtime/configuration
Configuration.java Configurations.java
ConfigurationsRepository.java
ExtendedProperties.java
Log:
- fixes to make the Configurations.subset(prefix) work correctly,
and added a setProperty(key,value) that takes into account
duplicate keys. when reading in a file the duplicate keys
were being accounted for but using setProperty() was using
Hashtable.put(key,value) which was wiping out duplicate
keys.
Revision Changes Path
1.6 +2 -2 jakarta-velocity/src/java/org/apache/velocity/runtime/configuration/Configuration.java
Index: Configuration.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/configuration/Configuration.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Configuration.java 2001/03/03 20:35:07 1.5
+++ Configuration.java 2001/03/04 00:39:24 1.6
@@ -64,7 +64,7 @@
* Based upon TurbineResources
*
* @author Dave Bryson
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public class Configuration
{
@@ -167,7 +167,7 @@
*/
public void setProperty( String name, String value )
{
- conf.getRepository().put( name, value );
+ conf.getRepository().setProperty( name, value );
}
/**
1.3 +12 -4 jakarta-velocity/src/java/org/apache/velocity/runtime/configuration/Configurations.java
Index: Configurations.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/configuration/Configurations.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Configurations.java 2001/03/03 20:33:21 1.2
+++ Configurations.java 2001/03/04 00:39:24 1.3
@@ -82,7 +82,7 @@
* configuration syntax.
*
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version $Id: Configurations.java,v 1.2 2001/03/03 20:33:21 jvanzyl Exp $
+ * @version $Id: Configurations.java,v 1.3 2001/03/04 00:39:24 jvanzyl Exp $
*/
public class Configurations
{
@@ -145,7 +145,8 @@
*
* @return A Hashtable.
*/
- public Hashtable getRepository()
+ //public Hashtable getRepository()
+ public ConfigurationsRepository getRepository()
{
return this.repository;
}
@@ -183,7 +184,14 @@
}
return matchingKeys.elements();
}
-
+
+ /**
+ * Create a Configurations object that is a subset
+ * of this one. Take into account duplicate keys
+ * by using the setProperty() in ConfigurationsRepository.
+ *
+ * @param String prefix
+ */
public Configurations subset(String prefix)
{
Configurations c = new Configurations(new ExtendedProperties());
@@ -203,7 +211,7 @@
}
String newKey = ((String)key).substring(prefix.length() + 1);
- c.getRepository().put(newKey, repository.get(key));
+ c.getRepository().setProperty(newKey, (String)repository.get(key));
}
}
1.2 +28 -1 jakarta-velocity/src/java/org/apache/velocity/runtime/configuration/ConfigurationsRepository.java
Index: ConfigurationsRepository.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/configuration/ConfigurationsRepository.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ConfigurationsRepository.java 2000/11/02 02:52:34 1.1
+++ ConfigurationsRepository.java 2001/03/04 00:39:25 1.2
@@ -75,7 +75,7 @@
*
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
* @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
- * @version $Id: ConfigurationsRepository.java,v 1.1 2000/11/02 02:52:34 daveb Exp $
+ * @version $Id: ConfigurationsRepository.java,v 1.2 2001/03/04 00:39:25 jvanzyl Exp $
*/
public abstract class ConfigurationsRepository
extends Hashtable
@@ -147,6 +147,33 @@
{
String key = (String) e.nextElement();
this.put ( key, hash.get(key) );
+ }
+ }
+
+ /**
+ * Set a property taking into consideration
+ * duplicate keys.
+ *
+ * @param String key
+ * @param String token
+ */
+ public void setProperty(String key, String token)
+ {
+ Object o = this.get(key);
+ if (o instanceof String)
+ {
+ Vector v = new Vector(2);
+ v.addElement(o);
+ v.addElement(token);
+ this.put(key, v);
+ }
+ else if (o instanceof Vector)
+ {
+ ((Vector) o).addElement(token);
+ }
+ else
+ {
+ this.put(key, token);
}
}
1.3 +4 -1 jakarta-velocity/src/java/org/apache/velocity/runtime/configuration/ExtendedProperties.java
Index: ExtendedProperties.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/configuration/ExtendedProperties.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ExtendedProperties.java 2001/01/06 20:57:03 1.2
+++ ExtendedProperties.java 2001/03/04 00:39:25 1.3
@@ -136,7 +136,7 @@
*
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
* @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
- * @version $Id: ExtendedProperties.java,v 1.2 2001/01/06 20:57:03 geirm Exp $
+ * @version $Id: ExtendedProperties.java,v 1.3 2001/03/04 00:39:25 jvanzyl Exp $
*/
public class ExtendedProperties
extends ConfigurationsRepository
@@ -347,6 +347,8 @@
while (tokenizer.hasMoreTokens())
{
String token = tokenizer.nextToken();
+ setProperty(key,token);
+ /*
Object o = this.get(key);
if (o instanceof String)
{
@@ -363,6 +365,7 @@
{
this.put(key, token);
}
+ */
}
}
}