niallp 2004/11/11 04:17:32
Modified: validator/src/share/org/apache/commons/validator Tag:
VALIDATOR_1_1_2_BRANCH Field.java Msg.java
Log:
Bug 29452 Enable Field/Msg to support all DTD attributes, based on patch
submitted by Rich Wertz
Changed Field to add getMsgObject(key) and getMsgs() methods
Changed Msg to add resource property and getter/setter
Revision Changes Path
No revision
No revision
1.31.2.2 +24 -10
jakarta-commons/validator/src/share/org/apache/commons/validator/Field.java
Index: Field.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Field.java,v
retrieving revision 1.31.2.1
retrieving revision 1.31.2.2
diff -u -r1.31.2.1 -r1.31.2.2
--- Field.java 22 Jun 2004 02:24:38 -0000 1.31.2.1
+++ Field.java 11 Nov 2004 12:17:32 -0000 1.31.2.2
@@ -239,14 +239,30 @@
* Add a <code>Msg</code> to the <code>Field</code>.
*/
public void addMsg(Msg msg) {
- hMsgs.put(msg.getName(), msg.getKey());
+ hMsgs.put(msg.getName(), msg);
}
/**
* Retrieve a message value.
*/
public String getMsg(String key) {
- return (String) hMsgs.get(key);
+ Msg msg = getMsgObject(key);
+ return (msg == null) ? null : msg.getKey();
+ }
+
+ /**
+ * Retrieve a message object.
+ */
+ public Msg getMsgObject(String key) {
+ return (Msg)hMsgs.get(key);
+ }
+
+ /**
+ * The <code>Field</code>'s messages are returned as an
+ * unmodifiable <code>Map</code>.
+ */
+ public Map getMsgs() {
+ return Collections.unmodifiableMap(hMsgs);
}
/**
@@ -627,11 +643,9 @@
String varKey = TOKEN_START + TOKEN_VAR;
// Process Messages
if (key != null && !key.startsWith(varKey)) {
- for (Iterator i = hMsgs.keySet().iterator(); i.hasNext();) {
- String msgKey = (String) i.next();
- String value = this.getMsg(msgKey);
-
- hMsgs.put(msgKey, ValidatorUtils.replace(value, key,
replaceValue));
+ for (Iterator i = hMsgs.values().iterator(); i.hasNext();) {
+ Msg msg = (Msg) i.next();
+ msg.setKey(ValidatorUtils.replace(msg.getKey(), key,
replaceValue));
}
}
1.12.2.1 +30 -3
jakarta-commons/validator/src/share/org/apache/commons/validator/Msg.java
Index: Msg.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Msg.java,v
retrieving revision 1.12
retrieving revision 1.12.2.1
diff -u -r1.12 -r1.12.2.1
--- Msg.java 21 Feb 2004 17:10:29 -0000 1.12
+++ Msg.java 11 Nov 2004 12:17:32 -0000 1.12.2.1
@@ -49,6 +49,13 @@
protected String name = null;
/**
+ * Whether or not the key is a message resource (optional). Defaults to
+ * true. If it is 'true', the value will try to be resolved as a message
+ * resource.
+ */
+ protected boolean resource = true;
+
+ /**
* Returns the resource bundle name.
* @since Validator 1.1
*/
@@ -94,6 +101,22 @@
}
/**
+ * Tests whether or not the key is a resource key or literal value.
+ * @return <code>true</code> if key is a resource key.
+ */
+ public boolean isResource() {
+ return this.resource;
+ }
+
+ /**
+ * Sets whether or not the key is a resource.
+ * @param resource If true indicates the key is a resource.
+ */
+ public void setResource(boolean resource) {
+ this.resource = resource;
+ }
+
+ /**
* Creates and returns a copy of this object.
*/
public Object clone() {
@@ -115,6 +138,10 @@
results.append(name);
results.append(" key=");
results.append(key);
+ results.append(" resource=");
+ results.append(resource);
+ results.append(" bundle=");
+ results.append(bundle);
results.append("\n");
return results.toString();
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]