cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java
niallp 2004/12/06 16:00:15 Modified:validator/src/share/org/apache/commons/validator Field.java Log: Revert back to version 1.35 Revision ChangesPath 1.37 +87 -94 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.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- Field.java12 Nov 2004 16:02:52 - 1.36 +++ Field.java7 Dec 2004 00:00:15 - 1.37 @@ -50,6 +50,13 @@ public class Field implements Cloneable, Serializable { /** + * This is the value that will be used as a key if the codeArg/code + * name field has no value. + */ +private static final String DEFAULT_ARG = +org.apache.commons.validator.Field.DEFAULT; + +/** * This indicates an indexed property is being referenced. */ public static final String TOKEN_INDEXED = []; @@ -85,16 +92,12 @@ protected FastHashMap hMsgs = new FastHashMap(); /** - * List containing the 'default' arguments - * @since Validator 1.2.0 - */ -protected List defaultArgs; - -/** - * Map containing the 'overriden' arguments. - * @since Validator 1.2.0 + * Holds Maps of arguments. args[0] returns the Map for the first + * replacement argument. Start with a 0 length array so that it will + * only grow to the size of the highest argument position. + * @since Validator 1.1 */ -protected Map overridenArgs; +protected Map[] args = new Map[0]; /** * Gets the page value that the Field is associated with for @@ -190,14 +193,12 @@ this.dependencyList.clear(); -if (this.depends != null) { -StringTokenizer st = new StringTokenizer(depends, ,); -while (st.hasMoreTokens()) { -String depend = st.nextToken().trim(); +StringTokenizer st = new StringTokenizer(depends, ,); +while (st.hasMoreTokens()) { +String depend = st.nextToken().trim(); -if (depend != null depend.length() 0) { -this.dependencyList.add(depend); -} +if (depend != null depend.length() 0) { +this.dependencyList.add(depend); } } } @@ -239,31 +240,38 @@ * @since Validator 1.1 */ public void addArg(Arg arg) { +// TODO this first if check can go away after arg0, etc. are removed from dtd +if (arg == null || arg.getKey() == null || arg.getKey().length() == 0) { +return; +} -// Determine if 'default' or 'overriden' -boolean isDefaultArg = arg.getName() == null; - -if (isDefaultArg) { +this.ensureArgsCapacity(arg); -if (defaultArgs == null) { -defaultArgs = new ArrayList(); -} -int pos = defaultArgs.size(); -arg.setPosition(pos); -defaultArgs.add(arg); +Map argMap = this.args[arg.getPosition()]; +if (argMap == null) { +argMap = new HashMap(); +this.args[arg.getPosition()] = argMap; +} +if (arg.getName() == null) { +argMap.put(DEFAULT_ARG, arg); } else { +argMap.put(arg.getName(), arg); +} -if (overridenArgs == null) { -overridenArgs = new HashMap(); -} -int position = arg.getPosition(); -if (position 0) { -position = defaultArgs == null ? 0 : defaultArgs.size() - 1; -arg.setPosition(position); -} -overridenArgs.put(arg.getName() + position, arg); +} +/** + * Ensures that the args array can hold the given arg. Resizes the array as + * necessary. + * @param arg Determine if the args array is long enough to store this arg's + * position. + */ +private void ensureArgsCapacity(Arg arg) { +if (arg.getPosition() = this.args.length) { +Map[] newArgs = new Map[arg.getPosition() + 1]; +System.arraycopy(this.args, 0, newArgs, 0, this.args.length); +this.args = newArgs; } } @@ -273,16 +281,7 @@ * @since Validator 1.1 */ public Arg getArg(int position) { - -if (position 0) { -return null; -} - -Arg arg = null; -if (defaultArgs != null position defaultArgs.size()) { -arg =
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java Msg.java
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 ChangesPath 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.java22 Jun 2004 02:24:38 - 1.31.2.1 +++ Field.java11 Nov 2004 12:17:32 - 1.31.2.2 @@ -239,14 +239,30 @@ * Add a codeMsg/code to the codeField/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 codeField/code's messages are returned as an + * unmodifiable codeMap/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 - 1.12 +++ Msg.java 11 Nov 2004 12:17:32 - 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 codetrue/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]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java Msg.java
niallp 2004/11/11 04:18:25 Modified:validator/src/share/org/apache/commons/validator 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 ChangesPath 1.34 +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.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- Field.java8 Jun 2004 17:17:44 - 1.33 +++ Field.java11 Nov 2004 12:18:25 - 1.34 @@ -207,14 +207,30 @@ * Add a codeMsg/code to the codeField/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 codeField/code's messages are returned as an + * unmodifiable codeMap/code. + */ +public Map getMsgs() { +return Collections.unmodifiableMap(hMsgs); } /** @@ -469,11 +485,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.13 +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.13 diff -u -r1.12 -r1.13 --- Msg.java 21 Feb 2004 17:10:29 - 1.12 +++ Msg.java 11 Nov 2004 12:18:25 - 1.13 @@ -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 codetrue/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]
Re: cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java Msg.java
Can we change getMessageObject() to getMessage() ? Most everything in Java is an object so it's redundant. Also, getMsgs() doesn't read very well; what about getMessages() ? It would be good to add @since javadoc tags so people don't assume this functionality was there from the beginning. David --- [EMAIL PROTECTED] wrote: niallp 2004/11/11 04:18:25 Modified:validator/src/share/org/apache/commons/validator 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 ChangesPath 1.34 +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.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- Field.java 8 Jun 2004 17:17:44 - 1.33 +++ Field.java 11 Nov 2004 12:18:25 - 1.34 @@ -207,14 +207,30 @@ * Add a codeMsg/code to the codeField/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 codeField/code's messages are returned as an + * unmodifiable codeMap/code. + */ +public Map getMsgs() { +return Collections.unmodifiableMap(hMsgs); } /** @@ -469,11 +485,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.13 +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.13 diff -u -r1.12 -r1.13 --- Msg.java21 Feb 2004 17:10:29 - 1.12 +++ Msg.java11 Nov 2004 12:18:25 - 1.13 @@ -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 codetrue/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]
Re: cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java Msg.java
OK I'll do that. Niall - Original Message - From: David Graham [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, November 11, 2004 2:37 PM Subject: Re: cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java Msg.java Can we change getMessageObject() to getMessage() ? Most everything in Java is an object so it's redundant. Also, getMsgs() doesn't read very well; what about getMessages() ? It would be good to add @since javadoc tags so people don't assume this functionality was there from the beginning. David --- [EMAIL PROTECTED] wrote: niallp 2004/11/11 04:18:25 Modified:validator/src/share/org/apache/commons/validator 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 ChangesPath 1.34 +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/F ield.java,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- Field.java 8 Jun 2004 17:17:44 - 1.33 +++ Field.java 11 Nov 2004 12:18:25 - 1.34 @@ -207,14 +207,30 @@ * Add a codeMsg/code to the codeField/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 codeField/code's messages are returned as an + * unmodifiable codeMap/code. + */ +public Map getMsgs() { +return Collections.unmodifiableMap(hMsgs); } /** @@ -469,11 +485,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.13 +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/M sg.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- Msg.java 21 Feb 2004 17:10:29 - 1.12 +++ Msg.java 11 Nov 2004 12:18:25 - 1.13 @@ -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 codetrue/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
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java Msg.java
niallp 2004/11/11 07:32:03 Modified:validator/src/share/org/apache/commons/validator Tag: VALIDATOR_1_1_2_BRANCH Field.java Msg.java Log: Re-name getMsgObject() and getMsgs() methods Revision ChangesPath No revision No revision 1.31.2.3 +8 -6 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.2 retrieving revision 1.31.2.3 diff -u -r1.31.2.2 -r1.31.2.3 --- Field.java11 Nov 2004 12:17:32 - 1.31.2.2 +++ Field.java11 Nov 2004 15:32:03 - 1.31.2.3 @@ -246,22 +246,24 @@ * Retrieve a message value. */ public String getMsg(String key) { -Msg msg = getMsgObject(key); +Msg msg = getMessage(key); return (msg == null) ? null : msg.getKey(); } /** * Retrieve a message object. + * @since Validator 1.1.4 */ -public Msg getMsgObject(String key) { +public Msg getMessage(String key) { return (Msg)hMsgs.get(key); } /** * The codeField/code's messages are returned as an * unmodifiable codeMap/code. + * @since Validator 1.1.4 */ -public Map getMsgs() { +public Map getMessages() { return Collections.unmodifiableMap(hMsgs); } 1.12.2.2 +6 -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.2.1 retrieving revision 1.12.2.2 diff -u -r1.12.2.1 -r1.12.2.2 --- Msg.java 11 Nov 2004 12:17:32 - 1.12.2.1 +++ Msg.java 11 Nov 2004 15:32:03 - 1.12.2.2 @@ -52,6 +52,7 @@ * 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. + * @since Validator 1.1.4 */ protected boolean resource = true; @@ -103,6 +104,7 @@ /** * Tests whether or not the key is a resource key or literal value. * @return codetrue/code if key is a resource key. + * @since Validator 1.1.4 */ public boolean isResource() { return this.resource; @@ -111,6 +113,7 @@ /** * Sets whether or not the key is a resource. * @param resource If true indicates the key is a resource. + * @since Validator 1.1.4 */ public void setResource(boolean resource) { this.resource = resource; - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java Msg.java
niallp 2004/11/11 07:32:49 Modified:validator/src/share/org/apache/commons/validator Field.java Msg.java Log: Re-name getMsgObject() and getMsgs() methods Revision ChangesPath 1.35 +8 -6 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.34 retrieving revision 1.35 diff -u -r1.34 -r1.35 --- Field.java11 Nov 2004 12:18:25 - 1.34 +++ Field.java11 Nov 2004 15:32:49 - 1.35 @@ -214,22 +214,24 @@ * Retrieve a message value. */ public String getMsg(String key) { -Msg msg = getMsgObject(key); +Msg msg = getMessage(key); return (msg == null) ? null : msg.getKey(); } /** * Retrieve a message object. + * @since Validator 1.1.4 */ -public Msg getMsgObject(String key) { +public Msg getMessage(String key) { return (Msg)hMsgs.get(key); } /** * The codeField/code's messages are returned as an * unmodifiable codeMap/code. + * @since Validator 1.1.4 */ -public Map getMsgs() { +public Map getMessages() { return Collections.unmodifiableMap(hMsgs); } 1.14 +6 -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.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- Msg.java 11 Nov 2004 12:18:25 - 1.13 +++ Msg.java 11 Nov 2004 15:32:49 - 1.14 @@ -52,6 +52,7 @@ * 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. + * @since Validator 1.1.4 */ protected boolean resource = true; @@ -103,6 +104,7 @@ /** * Tests whether or not the key is a resource key or literal value. * @return codetrue/code if key is a resource key. + * @since Validator 1.1.4 */ public boolean isResource() { return this.resource; @@ -111,6 +113,7 @@ /** * Sets whether or not the key is a resource. * @param resource If true indicates the key is a resource. + * @since Validator 1.1.4 */ public void setResource(boolean resource) { this.resource = resource; - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java Msg.java
Thanks Niall! David --- Niall Pemberton [EMAIL PROTECTED] wrote: OK I'll do that. Niall - Original Message - From: David Graham [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, November 11, 2004 2:37 PM Subject: Re: cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java Msg.java Can we change getMessageObject() to getMessage() ? Most everything in Java is an object so it's redundant. Also, getMsgs() doesn't read very well; what about getMessages() ? It would be good to add @since javadoc tags so people don't assume this functionality was there from the beginning. David --- [EMAIL PROTECTED] wrote: niallp 2004/11/11 04:18:25 Modified:validator/src/share/org/apache/commons/validator 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 ChangesPath 1.34 +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/F ield.java,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- Field.java 8 Jun 2004 17:17:44 - 1.33 +++ Field.java 11 Nov 2004 12:18:25 - 1.34 @@ -207,14 +207,30 @@ * Add a codeMsg/code to the codeField/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 codeField/code's messages are returned as an + * unmodifiable codeMap/code. + */ +public Map getMsgs() { +return Collections.unmodifiableMap(hMsgs); } /** @@ -469,11 +485,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.13 +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/M sg.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- Msg.java 21 Feb 2004 17:10:29 - 1.12 +++ Msg.java 11 Nov 2004 12:18:25 - 1.13 @@ -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 codetrue/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
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java Form.java FormSet.java
dgraham 2004/04/08 16:22:03 Modified:validator/src/share/org/apache/commons/validator Field.java Form.java FormSet.java Log: Removed items deprecated in 1.1.x series. Revision ChangesPath 1.32 +5 -176 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 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- Field.java21 Feb 2004 17:10:29 - 1.31 +++ Field.java8 Apr 2004 23:22:03 - 1.32 @@ -54,13 +54,6 @@ org.apache.commons.validator.Field.DEFAULT; /** - * This is the value that will be used as a key if the codeArg/code - * name field has no value. - * @deprecated - */ -public static final String ARG_DEFAULT = DEFAULT_ARG; - -/** * This indicates an indexed property is being referenced. */ public static final String TOKEN_INDEXED = []; @@ -84,11 +77,6 @@ protected int fieldOrder = 0; /** - * @deprecated This is no longer used. - */ -protected FastHashMap hDependencies = new FastHashMap(); - -/** * Internal representation of this.depends String as a List. This List * gets updated whenever setDepends() gets called. This List is * synchronized so a call to setDepends() (which clears the List) won't @@ -109,26 +97,6 @@ protected Map[] args = new Map[0]; /** - * @deprecated This variable is no longer used, use args instead. - */ -protected FastHashMap hArg0 = new FastHashMap(); - -/** - * @deprecated This variable is no longer used, use args instead. - */ -protected FastHashMap hArg1 = new FastHashMap(); - -/** - * @deprecated This variable is no longer used, use args instead. - */ -protected FastHashMap hArg2 = new FastHashMap(); - -/** - * @deprecated This variable is no longer used, use args instead. - */ -protected FastHashMap hArg3 = new FastHashMap(); - -/** * Gets the page value that the Field is associated with for * validation. */ @@ -339,111 +307,6 @@ } /** - * Add a codeArg/code to the arg0 list. - * @deprecated Use addArg(Arg) instead. - */ -public void addArg0(Arg arg) { -arg.setPosition(0); -this.addArg(arg); -} - -/** - * Gets the default arg0 codeArg/code object. - * @deprecated Use getArg(0) instead. - */ -public Arg getArg0() { -return this.getArg(0); -} - -/** - * Gets the arg0 codeArg/code object based on the key passed in. If - * the key finds a codenull/code value then the default value will - * be retrieved. - * @deprecated Use getArg(String, 0) instead. - */ -public Arg getArg0(String key) { -return this.getArg(key, 0); -} - -/** - * Add a codeArg/code to the arg1 list. - * @deprecated Use addArg(Arg) instead. - */ -public void addArg1(Arg arg) { -arg.setPosition(1); -this.addArg(arg); -} - -/** - * Gets the default arg1 codeArg/code object. - * @deprecated Use getArg(1) instead. - */ -public Arg getArg1() { -return this.getArg(1); -} - -/** - * Gets the arg1 codeArg/code object based on the key passed in. If the key - * finds a codenull/code value then the default value will try to be retrieved. - * @deprecated Use getArg(String, 1) instead. - */ -public Arg getArg1(String key) { -return this.getArg(key, 1); -} - -/** - * Add a codeArg/code to the arg2 list. - * @deprecated Use addArg(Arg) instead. - */ -public void addArg2(Arg arg) { -arg.setPosition(2); -this.addArg(arg); -} - -/** - * Gets the default arg2 codeArg/code object. - * @deprecated Use getArg(2) instead. - */ -public Arg getArg2() { -return this.getArg(2); -} - -/** - * Gets the arg2 codeArg/code object based on the key passed in. If the key - * finds a codenull/code value then the default value will try to be retrieved. - * @deprecated Use getArg(String, 2) instead. - */ -public Arg getArg2(String key) { -return this.getArg(key, 2); -} - -/** - * Add a codeArg/code to the arg3 list. - * @deprecated Use addArg(Arg) instead. - */ -public void addArg3(Arg arg) { -arg.setPosition(3); -this.addArg(arg); -} - -/** - *
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java Validator.java Form.java ValidatorAction.java
dgraham 2004/01/31 18:25:08 Modified:validator/src/share/org/apache/commons/validator Field.java Validator.java Form.java ValidatorAction.java Log: Refactored Validator class to place methods closer to the data required to run them. Now ValidatorActions know how to execute their validation method, Forms know how to validate a set of their Fields, and Fields can run the validations configured on them. Revision ChangesPath 1.30 +168 -5 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.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- Field.java17 Jan 2004 17:35:27 - 1.29 +++ Field.java1 Feb 2004 02:25:08 - 1.30 @@ -62,6 +62,7 @@ package org.apache.commons.validator; import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -71,16 +72,15 @@ import java.util.Map; import java.util.StringTokenizer; +import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.collections.FastHashMap; import org.apache.commons.validator.util.ValidatorUtils; /** - * p * This contains the list of pluggable validators to run on a field and any * message information and variables to perform the validations and generate * error messages. Instances of this class are configured with a * lt;fieldgt; xml element. - * /p * * @see org.apache.commons.validator.Form */ @@ -787,6 +787,169 @@ } return results.toString(); +} + +/** + * Returns an indexed property from the object we're validating. + * + * @param bean The bean to extract the indexed values from. + * @throws ValidatorException If there's an error looking up the property + * or, the property found is not indexed. + */ +Object[] getIndexedProperty(Object bean) throws ValidatorException { +Object indexedProperty = null; + +try { +indexedProperty = +PropertyUtils.getProperty(bean, this.getIndexedListProperty()); + +} catch(IllegalAccessException e) { +throw new ValidatorException(e.getMessage()); +} catch(InvocationTargetException e) { +throw new ValidatorException(e.getMessage()); +} catch(NoSuchMethodException e) { +throw new ValidatorException(e.getMessage()); +} + +if (indexedProperty instanceof Collection) { +return ((Collection) indexedProperty).toArray(); + +} else if (indexedProperty.getClass().isArray()) { +return (Object[]) indexedProperty; + +} else { +throw new ValidatorException(this.getKey() + is not indexed); +} + +} + +/** + * Executes the given ValidatorAction and all ValidatorActions that it + * depends on. + * @return true if the validation succeeded. + */ +private boolean validateForRule( +ValidatorAction va, +ValidatorResults results, +Map actions, +Map params, +int pos) +throws ValidatorException { + +ValidatorResult result = results.getValidatorResult(this.getKey()); +if (result != null result.containsAction(va.getName())) { +return result.isValid(va.getName()); +} + +if (!this.runDependentValidators(va, results, actions, params, pos)) { +return false; +} + +return va.executeValidationMethod(this, params, results, pos); +} + +/** + * Calls all of the validators that this validator depends on. + * TODO ValidatorAction should know how to run its own dependencies. + * @param va Run dependent validators for this action. + * @param results + * @param actions + * @param pos + * @return true if all of the dependent validations passed. + * @throws ValidatorException + */ +private boolean runDependentValidators( +ValidatorAction va, +ValidatorResults results, +Map actions, +Map params, +int pos) +throws ValidatorException { + +List dependentValidators = va.getDependencyList(); + +if (dependentValidators.isEmpty()) { +return true; +} + +Iterator iter = dependentValidators.iterator(); +while (iter.hasNext()) { +String depend = (String) iter.next(); + +ValidatorAction
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java
rleland 2003/11/16 19:35:30 Modified:validator/src/share/org/apache/commons/validator Field.java Log: Update JavaDocs Revision ChangesPath 1.27 +5 -4 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.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- Field.java28 Sep 2003 20:39:57 - 1.26 +++ Field.java17 Nov 2003 03:35:30 - 1.27 @@ -258,6 +258,7 @@ /** * Sets the validation rules for this field as a comma separated list. + * @param depends A comma separated list of validator names. */ public void setDepends(String depends) { this.depends = depends; - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java
dgraham 2003/09/28 11:47:32 Modified:validator/src/share/org/apache/commons/validator Field.java Log: javadoc changes only. Revision ChangesPath 1.25 +32 -25 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.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- Field.java26 Aug 2003 16:08:50 - 1.24 +++ Field.java28 Sep 2003 18:47:32 - 1.25 @@ -76,9 +76,10 @@ /** * p - * This contains the list of pluggable validators to run on a field and any message - * information and variables to perform the validations and generate error - * messages. Instances of this class are configured with a lt;fieldgt; xml element. + * This contains the list of pluggable validators to run on a field and any + * message information and variables to perform the validations and generate + * error messages. Instances of this class are configured with a + * lt;fieldgt; xml element. * /p * * @author David Winterfeldt @@ -122,6 +123,7 @@ protected String depends = null; protected int page = 0; + protected int fieldOrder = 0; /** @@ -130,19 +132,20 @@ protected FastHashMap hDependencies = new FastHashMap(); /** - * Internal representation of this.depends String as a List. This List gets updated - * whenever setDepends() gets called. This List is synchronized so a call to - * setDepends() (which clears the List) won't interfere with a call to - * isDependency(). + * Internal representation of this.depends String as a List. This List + * gets updated whenever setDepends() gets called. This List is + * synchronized so a call to setDepends() (which clears the List) won't + * interfere with a call to isDependency(). */ private List dependencyList = Collections.synchronizedList(new ArrayList()); protected FastHashMap hVars = new FastHashMap(); + protected FastHashMap hMsgs = new FastHashMap(); /** - * Holds Maps of arguments. args[0] returns the Map for the first replacement - * argument. + * Holds Maps of arguments. args[0] returns the Map for the first + * replacement argument. * @since Validator 1.1 */ protected Map[] args = new Map[10]; @@ -334,10 +337,11 @@ } /** - * Gets the default codeArg/code object at the given position. If the key - * finds a codenull/code value then the default value will try to be retrieved. - * @param key The name the Arg is stored under. If not found, the default Arg for - * the given position (if any) will be retrieved. + * Gets the codeArg/code object at the given position. If the key + * finds a codenull/code value then the default value will be + * retrieved. + * @param key The name the Arg is stored under. If not found, the default + * Arg for the given position (if any) will be retrieved. * @param position The Arg number to find. * @return The Arg with the given name and position or null if not found. * @since Validator 1.1 @@ -349,7 +353,8 @@ Arg arg = (Arg) args[position].get(key); -// Didn't find default arg so exit, otherwise we would get into infinite recursion +// Didn't find default arg so exit, otherwise we would get into +// infinite recursion if ((arg == null) key.equals(DEFAULT_ARG)) { return null; } @@ -375,8 +380,9 @@ } /** - * Gets the arg0 codeArg/code object based on the key passed in. If the key - * finds a codenull/code value then the default value will try to be retrieved. + * Gets the arg0 codeArg/code object based on the key passed in. If + * the key finds a codenull/code value then the default value will + * be retrieved. * @deprecated Use getArg(String, 0) instead. */ public Arg getArg0(String key) { @@ -542,7 +548,8 @@ /** * If there is a value specified for the indexedProperty field then - * codetrue/code will be returned. Otherwise it will be codefalse/code. + * codetrue/code will be returned. Otherwise it will be + * codefalse/code. */ public boolean isIndexed() { return ((indexedListProperty != null indexedListProperty.length() 0)); @@ -653,8 +660,8 @@ } /** - * Replace the arg codeCollection/code key value with the key/value pairs - * passed in. + * Replace the arg codeCollection/code key value with the key/value + *
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java
dgraham 2003/09/28 13:39:58 Modified:validator/src/test/org/apache/commons/validator ValidatorTestSuite.java validator/src/share/org/apache/commons/validator Field.java Added: validator/src/test/org/apache/commons/validator FieldTest.java Log: Added Field.getArgs(String) to make it easier to retrieve all of the Args for a given validator. Without this method, you need to know how many Args to retrieve with the getArg(String, int) method. Also, the Field.args array was changed to start with a 0 length instead of 10. This way the array will only grow to the length of the largest argument position. This will make populating the array slower (because of the resizing) but will make it easier for clients to deal with the array returned from getArgs(). Revision ChangesPath 1.11 +5 -4 jakarta-commons/validator/src/test/org/apache/commons/validator/ValidatorTestSuite.java Index: ValidatorTestSuite.java === RCS file: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/ValidatorTestSuite.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ValidatorTestSuite.java 8 Jun 2003 21:33:22 - 1.10 +++ ValidatorTestSuite.java 28 Sep 2003 20:39:57 - 1.11 @@ -100,6 +100,7 @@ suite.addTestSuite(CreditCardValidatorTest.class); suite.addTest(ValidatorTest.suite()); suite.addTest(LocaleTest.suite()); + suite.addTestSuite(FieldTest.class); suite.addTestSuite(FlagsTest.class); suite.addTest(UrlTest.suite()); 1.1 jakarta-commons/validator/src/test/org/apache/commons/validator/FieldTest.java Index: FieldTest.java === /* * $Header: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/FieldTest.java,v 1.1 2003/09/28 20:39:57 dgraham Exp $ * $Revision: 1.1 $ * $Date: 2003/09/28 20:39:57 $ * * * * The Apache Software License, Version 1.1 * * Copyright (c) 2001-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *notice, this list of conditions and the following disclaimer in *the documentation and/or other materials provided with the *distribution. * * 3. The end-user documentation included with the redistribution, if *any, must include the following acknowledgement: * This product includes software developed by the *Apache Software Foundation (http://www.apache.org/). *Alternately, this acknowlegement may appear in the software itself, *if and wherever such third-party acknowlegements normally appear. * * 4. The names, Apache, The Jakarta Project, Commons, and Apache Software *Foundation must not be used to endorse or promote products derived *from this software without prior written permission. For written *permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called Apache *nor may Apache appear in their name, without prior written *permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * http://www.apache.org/. * */ package
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java
rleland 2003/08/26 09:08:50 Modified:validator/src/share/org/apache/commons/validator Field.java Log: Remove unneeded cast Revision ChangesPath 1.24 +5 -5 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.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- Field.java21 Aug 2003 21:43:05 - 1.23 +++ Field.java26 Aug 2003 16:08:50 - 1.24 @@ -296,7 +296,7 @@ this.ensureArgsCapacity(arg); -Map argMap = (Map) this.args[arg.getPosition()]; +Map argMap = this.args[arg.getPosition()]; if (argMap == null) { argMap = new HashMap(); this.args[arg.getPosition()] = argMap; - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java
dgraham 2003/06/11 18:04:11 Modified:validator/src/share/org/apache/commons/validator Field.java Log: Fixed NPE in clone(). Revision ChangesPath 1.19 +31 -26 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.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- Field.java8 Jun 2003 06:03:16 - 1.18 +++ Field.java12 Jun 2003 01:04:11 - 1.19 @@ -701,32 +701,37 @@ * Creates and returns a copy of this object. */ public Object clone() { +Field field = null; try { -Field field = (Field) super.clone(); - -field.args = new Map[this.args.length]; -for (int i = 0; i this.args.length; i++) { -Map argMap = new HashMap(this.args[i]); -Iterator iter = argMap.keySet().iterator(); -while (iter.hasNext()) { -String validatorName = (String) iter.next(); -Arg arg = (Arg) argMap.get(validatorName); -argMap.put(validatorName, arg.clone()); -} -field.args[i] = argMap; -} - -field.hVars = ValidatorUtils.copyFastHashMap(hVars); -field.hMsgs = ValidatorUtils.copyFastHashMap(hMsgs); -field.hArg0 = ValidatorUtils.copyFastHashMap(hArg0); -field.hArg1 = ValidatorUtils.copyFastHashMap(hArg1); -field.hArg2 = ValidatorUtils.copyFastHashMap(hArg2); -field.hArg3 = ValidatorUtils.copyFastHashMap(hArg3); - -return field; +field = (Field) super.clone(); } catch (CloneNotSupportedException e) { throw new InternalError(e.toString()); } + +field.args = new Map[this.args.length]; +for (int i = 0; i this.args.length; i++) { +if (this.args[i] == null) { +continue; +} + +Map argMap = new HashMap(this.args[i]); +Iterator iter = argMap.keySet().iterator(); +while (iter.hasNext()) { +String validatorName = (String) iter.next(); +Arg arg = (Arg) argMap.get(validatorName); +argMap.put(validatorName, arg.clone()); +} +field.args[i] = argMap; +} + +field.hVars = ValidatorUtils.copyFastHashMap(hVars); +field.hMsgs = ValidatorUtils.copyFastHashMap(hMsgs); +field.hArg0 = ValidatorUtils.copyFastHashMap(hArg0); +field.hArg1 = ValidatorUtils.copyFastHashMap(hArg1); +field.hArg2 = ValidatorUtils.copyFastHashMap(hArg2); +field.hArg3 = ValidatorUtils.copyFastHashMap(hArg3); + +return field; } /** - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java
dgraham 2003/06/07 23:03:16 Modified:validator/src/share/org/apache/commons/validator Field.java Log: The new getArg(String, int) method did not meet the contract of the older getArg0(String) method. When the Arg for the given key is not found, it should try to return the default Arg at that position. PR# 20571 Revision ChangesPath 1.18 +22 -9 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.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- Field.java8 Jun 2003 05:29:27 - 1.17 +++ Field.java8 Jun 2003 06:03:16 - 1.18 @@ -331,20 +331,33 @@ /** * Gets the default codeArg/code object at the given position. + * @return The default Arg or null if not found. */ public Arg getArg(int position) { return this.getArg(DEFAULT_ARG, position); } /** - * Gets the default codeArg/code object at the given position. + * Gets the default codeArg/code object at the given position. If the key + * finds a codenull/code value then the default value will try to be retrieved. + * @param key The name the Arg is stored under. If not found, the default Arg for + * the given position (if any) will be retrieved. + * @param position The Arg number to find. + * @return The Arg with the given name and position or null if not found. */ public Arg getArg(String key, int position) { -if (position = this.args.length) { -return null; -} + if ((position = this.args.length) || (this.args[position] == null)) { + return null; + } -return (args[position] == null) ? null : (Arg) args[position].get(key); + Arg arg = (Arg) args[position].get(key); + +// Didn't find default arg so exit, otherwise we would get into infinite recursion + if ((arg == null) key.equals(DEFAULT_ARG)) { + return null; + } + + return (arg == null) ? this.getArg(position) : arg; } /** - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java
dgraham 2003/06/07 12:25:59 Modified:validator/src/share/org/apache/commons/validator Field.java Log: Somewhere along the way hArg0 was moved to private instead of protected, so move it back. Revision ChangesPath 1.16 +5 -6 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.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- Field.java29 May 2003 03:04:33 - 1.15 +++ Field.java7 Jun 2003 19:25:58 - 1.16 @@ -149,7 +149,7 @@ /** * @deprecated This variable is no longer used, use args instead. */ -private FastHashMap hArg0 = new FastHashMap(); +protected FastHashMap hArg0 = new FastHashMap(); /** * @deprecated This variable is no longer used, use args instead. @@ -165,7 +165,6 @@ * @deprecated This variable is no longer used, use args instead. */ protected FastHashMap hArg3 = new FastHashMap(); - /** * Gets the page value that the Field is associated with for - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java
dgraham 2003/06/07 22:29:27 Modified:validator/src/share/org/apache/commons/validator Field.java Log: Changed toString() method. Revision ChangesPath 1.17 +26 -26 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.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- Field.java7 Jun 2003 19:25:58 - 1.16 +++ Field.java8 Jun 2003 05:29:27 - 1.17 @@ -720,29 +720,29 @@ * Returns a string representation of the object. */ public String toString() { - StringBuffer results = new StringBuffer(); - - results.append(\t\tkey= + key+ \n); - results.append(\t\tproperty= + property+ \n); - results.append(\t\tindexedProperty= + indexedProperty+ \n); - results.append(\t\tindexedListProperty= + indexedListProperty+ \n); - results.append(\t\tdepends= + depends+ \n); - results.append(\t\tpage= + page+ \n); - results.append(\t\tfieldOrder= + fieldOrder+ \n); - - if (hVars != null) { - results.append(\t\tVars:\n); - for (Iterator i = hVars.keySet().iterator(); i.hasNext(); ) { - Object key = i.next(); - results.append(\t\t\t); - results.append(key); - results.append(=); - results.append(hVars.get(key)); - results.append(\n); -} + StringBuffer results = new StringBuffer(); + + results.append(\t\tkey = + key + \n); + results.append(\t\tproperty = + property + \n); + results.append(\t\tindexedProperty = + indexedProperty + \n); + results.append(\t\tindexedListProperty = + indexedListProperty + \n); + results.append(\t\tdepends = + depends + \n); + results.append(\t\tpage = + page + \n); + results.append(\t\tfieldOrder = + fieldOrder + \n); + + if (hVars != null) { + results.append(\t\tVars:\n); + for (Iterator i = hVars.keySet().iterator(); i.hasNext();) { + Object key = i.next(); + results.append(\t\t\t); + results.append(key); + results.append(=); + results.append(hVars.get(key)); + results.append(\n); + } } - - return results.toString(); + + return results.toString(); } } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java
dgraham 2003/05/28 20:04:33 Modified:validator/src/share/org/apache/commons/validator Field.java Log: Deprecated public process() method because it should only be called by the framework. Use getters internally instead of duplicating logic and casting. Revision ChangesPath 1.15 +9 -7 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.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- Field.java28 May 2003 04:14:32 - 1.14 +++ Field.java29 May 2003 03:04:33 - 1.15 @@ -547,6 +547,8 @@ /** * Replace constants with values in fields and process the depends field * to create the dependency codeMap/code. + * @deprecated This method is called by the framework. It will be made protected + * in a future release. TODO */ public void process(Map globalConstants, Map constants) { this.hMsgs.setFast(false); @@ -584,7 +586,7 @@ for (Iterator i = hVars.keySet().iterator(); i.hasNext();) { String key = (String) i.next(); String key2 = TOKEN_START + TOKEN_VAR + key + TOKEN_END; - Var var = (Var) hVars.get(key); + Var var = this.getVar(key); String replaceValue = var.getValue(); this.processMessageComponents(key2, replaceValue); @@ -600,7 +602,7 @@ Iterator i = this.hVars.keySet().iterator(); while (i.hasNext()) { String varKey = (String) i.next(); -Var var = (Var) this.hVars.get(varKey); +Var var = this.getVar(varKey); var.setValue(ValidatorUtils.replace(var.getValue(), key, replaceValue)); } @@ -626,7 +628,7 @@ if (key != null !key.startsWith(varKey)) { for (Iterator i = hMsgs.keySet().iterator(); i.hasNext();) { String msgKey = (String) i.next(); -String value = (String) hMsgs.get(msgKey); +String value = this.getMsg(msgKey); hMsgs.put(msgKey, ValidatorUtils.replace(value, key, replaceValue)); } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java
turner 2002/10/16 15:13:32 Modified:validator/src/share/org/apache/commons/validator Field.java Log: Fixes (completely) bug 13472 Revision ChangesPath 1.7 +5 -4 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.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- Field.java11 Oct 2002 01:49:33 - 1.6 +++ Field.java16 Oct 2002 22:13:32 - 1.7 @@ -498,6 +498,7 @@ hDependencies.setFast(true); } + hMsgs.setFast(true); } /** -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java
turner 2002/10/10 18:49:33 Modified:validator/src/share/org/apache/commons/validator Field.java Log: Can't modify a fast hash map while inside an iterate on it. (Closes bug 13472 ) Revision ChangesPath 1.6 +5 -5 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.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Field.java30 Mar 2002 04:33:17 - 1.5 +++ Field.java11 Oct 2002 01:49:33 - 1.6 @@ -439,7 +439,7 @@ * to create the dependency codeMap/code. */ public void process(Map globalConstants, Map constants) { - hMsgs.setFast(true); + hMsgs.setFast(false); hArg0.setFast(true); hArg1.setFast(true); hArg2.setFast(true); -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java
dwinterfeldt02/03/18 22:18:43 Modified:validator/src/share/org/apache/commons/validator Field.java Log: The isIndexed only checks if indexedListProperty is set and indexedListProperty is used instead of indexedProperty when generating the key. PropertyUtils works with just getting back a List so indexProperty may be unnecessary as a reference to getXXX(int pos) and setXXX(int pos, Object value). Revision ChangesPath 1.4 +2 -3 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Field.java13 Mar 2002 05:39:32 - 1.3 +++ Field.java19 Mar 2002 06:18:43 - 1.4 @@ -414,8 +414,7 @@ * codetrue/code will be returned. Otherwise it will be codefalse/code. */ public boolean isIndexed() { - return ((indexedProperty != null indexedProperty.length() 0) - (indexedListProperty != null indexedListProperty.length() 0)); + return ((indexedListProperty != null indexedListProperty.length() 0)); } /** @@ -423,7 +422,7 @@ */ public void generateKey() { if (isIndexed()) { - key = indexedProperty + TOKEN_INDEXED + . + property; + key = indexedListProperty + TOKEN_INDEXED + . + property; } else { key = property; } -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]