commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java Msg.java
Date Thu, 11 Nov 2004 12:18:25 GMT
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  Changes    Path
  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 -0000	1.33
  +++ Field.java	11 Nov 2004 12:18:25 -0000	1.34
  @@ -207,14 +207,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);
       }
   
       /**
  @@ -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 -0000	1.12
  +++ Msg.java	11 Nov 2004 12:18:25 -0000	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 <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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message