Modified: 
jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Util.java
URL: 
http://svn.apache.org/viewvc/jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Util.java?view=diff&rev=531141&r1=531140&r2=531141
==============================================================================
--- jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Util.java 
(original)
+++ jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Util.java 
Sat Apr 21 21:22:25 2007
@@ -47,269 +47,253 @@
 
 class Util {
 
-    /** Print out any HTML tag attributes we might have been passed. */
-    public static void printAttributes(JspWriter out, Map attributes)
-            throws JspTagException, IOException {
-        if (attributes != null) {
-            Iterator i = attributes.keySet().iterator();
-            while (i.hasNext()) {
-                Object oKey = i.next();
-                Object oVal = attributes.get(oKey);
-
-                /*
-                 * If the attribute contains non-Strings, give the user a more
-                 * meaningful message than what he or she would get if we just
-                 * propagated a ClassCastException back. (This'll get caught
-                 * below.)
-                 */
-                if (!(oKey instanceof String)
-                        || (oVal != null && !(oVal instanceof String)))
-                    throw new JspTagException(
-                            "all members in attributes Map must be Strings");
-                String key = (String) oKey;
-                String value = (String) oVal;
-
-                // check for illegal keys
-                if (key.equals("name") || key.equals("value")
-                        || key.equals("type") || key.equals("checked"))
-                    throw new JspTagException("illegal key '" + key
-                            + "'found in attributes Map");
-
-                /*
-                 * Print the key and value. If the value is null, make it equal
-                 * to the key. This follows the conventions of XHTML 1.0 and
-                 * does not break regular HTML.
-                 */
-                if (value == null)
-                    value = key;
-
-                out.print(" " + quote(key) + "=\"" + quote(value) + "\"");
-            }
-        }
-    }
-
-    /** Quote metacharacters in HTML. */
-    public static String quote(String x) {
-        if (x == null)
-            return null;
-        else {
-            // deal with ampersands first so we can ignore the ones we add 
later
-            x = replace(x, "&", "&");
-            x = replace(x, "\"", """);
-            x = replace(x, "<", "&lt;");
-            x = replace(x, ">", "&gt;");
-            return x;
-        }
-    }
-
-    /**
-     * Efficient string replace function. Replaces instances of the substring
-     * find with replace in the string subject. [EMAIL PROTECTED]
-     * 
-     * @param subject
-     *            The string to search for and replace in.
-     * @param find
-     *            The substring to search for.
-     * @param replace
-     *            The string to replace instances of the string find with.
-     */
-    public static String replace(String subject, String find, String replace) {
-        StringBuffer buf = new StringBuffer();
-        int l = find.length();
-        int s = 0;
-        int i = subject.indexOf(find);
-        while (i != -1) {
-            buf.append(subject.substring(s, i));
-            buf.append(replace);
-            s = i + l;
-            i = subject.indexOf(find, s);
-        }
-        buf.append(subject.substring(s));
-        return buf.toString();
-    }
-    
-    public static String capitalize(String s) {
-       if (s == null || s.length() == 0) {
-           return s;
-       }
-       char chars[] = s.toCharArray();
-       chars[0] = Character.toUpperCase(chars[0]);
-       return new String(chars);
-    }
-
-    /**
-     * Gets a named property from a JavaBean and returns its value as an 
Object,
-     * possibly null.
-     */
-    public static Object beanPropertyValueObject(Object bean, String name)
-            throws JspTagException {
-        if (bean != null) {
-            Method reader = null;
-            Object[] params = null;
-
-            // Try to find a reader method for the named property
-            try {
-               PropertyDescriptor prop = new PropertyDescriptor(name, bean
-                        .getClass());
-                reader = prop.getReadMethod();
-            } catch (IntrospectionException e) {
-               try {
-                       /* Only try to get a reader method, we don't care about 
a writer. We pass through the
-                        * reader method as isName following the pattern in 
PropertyDescriptor. The PropertyDescriptor
-                        * finds the right read method. This allows us to 
specify null for the writer method and thus
-                        * find read only properties.
-                        */
-                       PropertyDescriptor prop = new PropertyDescriptor(name, 
bean
-                               .getClass(), "is" + capitalize(name), null);
-                       reader = prop.getReadMethod();
-                   } catch (IntrospectionException f) {
-                       // No property exists with that name, try a generic get 
method
-                       // Object get( Object key )
-                       try {
-                           reader = bean.getClass().getMethod("get",
-                                   new Class[] { Object.class });
-                           params = new Object[] { name };
-                       } catch (NoSuchMethodException g) {
-                           // Try an Object get( String key) method
-                           try {
-                               reader = bean.getClass().getMethod("get",
-                                       new Class[] { String.class });
-                               params = new Object[] { name };
-                           } catch (NoSuchMethodException h) {
-                               // Give up
-                           }
-                       }
-                   }
-            }
-
-            // If a reader method has been found
-            if (reader != null) {
-                try {
-                    return reader.invoke(bean, params);
-                } catch (IllegalAccessException e) {
-                } catch (IllegalArgumentException e) {
-                } catch (InvocationTargetException e) {
-                    throw new JspTagException("Exception getting property \""
-                            + name + "\" from bean "
-                            + bean.getClass().getName() + ": "
-                            + e.getTargetException());
-                }
-            }
-        }
-
-        return null;
-    }
-    
-    public static Object beanPropertyValueObject(Object bean, String name, int 
index) throws JspTagException {
-       Object value = beanPropertyValueObject(bean, name);
-       if (value != null) {
-               if (value.getClass().isArray()) {
-                       return Array.get(value, index);
-               }
-               else if (index == 0) {
-                       return value;
-               }
-               else {
-                       return null;
-               }
-       }
-       else {
-               return null;
-       }
-    }
-
-    /**
-     * Gets a named property from a JavaBean and returns its value as a String,
-     * possibly null.
-     */
-    public static String beanPropertyValue(Object bean, String name)
-            throws JspTagException {
-        Object value = beanPropertyValueObject(bean, name);
-        return (value != null ? value.toString() : null);
-    }
-
-    /**
-     * Gets a named property from a JavaBean and returns its value as a String,
-     * possibly null.
-     */
-    public static String beanPropertyValue(Object bean, String name, int index)
-            throws JspTagException {
-        Object value = beanPropertyValueObject(bean, name);
-        if (value != null) {
-               if (value.getClass().isArray()) {
-                       value = Array.get(value, index);
-               }
-               else if (index != 0) {
-                       value = null;
-               }
-               return (value != null ? value.toString() : null);
-        }
-        else {
-               return null;
-        }
-    }
-
-    /**
-     * Gets a named property (possibly an array property) from a JavaBean and
-     * returns its values as an array of Strings, possibly null. If the 
property
-     * is not an array property, an array of size 1 is returned.
-     */
-    public static String[] beanPropertyValues(Object bean, String name)
-            throws JspTagException {
-        Object value = beanPropertyValueObject(bean, name);
-        return valueToStringArray(value);
-    }
-    
-    public static String[] beanPropertyValues(Object bean, String name, int 
index) throws JspTagException {
-       Object value = beanPropertyValueObject(bean, name, index);
-        return valueToStringArray(value);
-    }
-    
-    private static String[] valueToStringArray(Object value) {
-       if (value != null) {
-            // Check if the value is an array object
-            if (value.getClass().isArray()) {
-                // Convert to an array of Strings
-                int n = java.lang.reflect.Array.getLength(value);
-                String[] strs = new String[n];
-                for (int i = 0; i < n; i++) {
-                    Object o = java.lang.reflect.Array.get(value, i);
-                    strs[i] = (o != null ? o.toString() : null);
-                }
-                return strs;
-            }
-            // If not an array, just convert the object to a String in an array
-            // and return
-            else {
-                return new String[] { value.toString() };
-            }
-        } else {
-            return null;
-        }
-    }
-
-    /**
-     * Finds the input:form tag enclosing the given tag and returns it.
-     */
-    public static Form findFormTag(Tag tag) {
-        Tag formTag = TagSupport.findAncestorWithClass(tag, Form.class);
-        if (formTag != null) {
-            return (Form) formTag;
-        } else {
-            return null;
-        }
-    }
-
-    /**
-     * Finds the input:form tag enclosing the given tag and returns the "bean"
-     * property from it, that is the default bean for this form, possibly null.
-     */
-    public static String defaultFormBeanId(Tag tag) {
-        Form form = findFormTag(tag);
-        if (form != null) {
-            return form.getBean();
-        } else {
-            return null;
-        }
-    }
+       /** Print out any HTML tag attributes we might have been passed. */
+       static void printAttributes(JspWriter out, Map attributes) throws 
JspTagException, IOException {
+               if (attributes != null) {
+                       Iterator i = attributes.keySet().iterator();
+                       while (i.hasNext()) {
+                               Object oKey = i.next();
+                               Object oVal = attributes.get(oKey);
+
+                               /*
+                                * If the attribute contains non-Strings, give 
the user a more
+                                * meaningful message than what he or she would 
get if we just
+                                * propagated a ClassCastException back. 
(This'll get caught
+                                * below.)
+                                */
+                               if (!(oKey instanceof String) || (oVal != null 
&& !(oVal instanceof String)))
+                                       throw new JspTagException("all members 
in attributes Map must be Strings");
+                               String key = (String) oKey;
+                               String value = (String) oVal;
+
+                               // check for illegal keys
+                               if (key.equals("name") || key.equals("value") 
|| key.equals("type") || key.equals("checked"))
+                                       throw new JspTagException("illegal key 
'" + key + "'found in attributes Map");
+
+                               /*
+                                * Print the key and value. If the value is 
null, make it equal
+                                * to the key. This follows the conventions of 
XHTML 1.0 and
+                                * does not break regular HTML.
+                                */
+                               if (value == null)
+                                       value = key;
+
+                               out.print(" " + quote(key) + "=\"" + 
quote(value) + "\"");
+                       }
+               }
+       }
+
+       /** Quote metacharacters in HTML. */
+       static String quote(String x) {
+               if (x == null)
+                       return null;
+               else {
+                       // deal with ampersands first so we can ignore the ones 
we add later
+                       x = replace(x, "&", "&amp;");
+                       x = replace(x, "\"", "&quot;");
+                       x = replace(x, "<", "&lt;");
+                       x = replace(x, ">", "&gt;");
+                       return x;
+               }
+       }
+
+       /**
+        * Efficient string replace function. Replaces instances of the 
substring
+        * find with replace in the string subject. [EMAIL PROTECTED]
+        * 
+        * @param subject
+        *            The string to search for and replace in.
+        * @param find
+        *            The substring to search for.
+        * @param replace
+        *            The string to replace instances of the string find with.
+        */
+       static String replace(String subject, String find, String replace) {
+               StringBuffer buf = new StringBuffer();
+               int l = find.length();
+               int s = 0;
+               int i = subject.indexOf(find);
+               while (i != -1) {
+                       buf.append(subject.substring(s, i));
+                       buf.append(replace);
+                       s = i + l;
+                       i = subject.indexOf(find, s);
+               }
+               buf.append(subject.substring(s));
+               return buf.toString();
+       }
+
+       static String capitalize(String s) {
+               if (s == null || s.length() == 0) {
+                       return s;
+               }
+               char chars[] = s.toCharArray();
+               chars[0] = Character.toUpperCase(chars[0]);
+               return new String(chars);
+       }
+
+       /**
+        * Gets a named property from a JavaBean and returns its value as an 
Object,
+        * possibly null.
+        */
+       static Object beanPropertyValueObject(Object bean, String name) throws 
JspTagException {
+               if (bean != null) {
+                       Method reader = null;
+                       Object[] params = null;
+
+                       // Try to find a reader method for the named property
+                       try {
+                               PropertyDescriptor prop = new 
PropertyDescriptor(name, bean.getClass());
+                               reader = prop.getReadMethod();
+                       } catch (IntrospectionException e) {
+                               try {
+                                       /*
+                                        * Only try to get a reader method, we 
don't care about a
+                                        * writer. We pass through the reader 
method as isName
+                                        * following the pattern in 
PropertyDescriptor. The
+                                        * PropertyDescriptor finds the right 
read method. This
+                                        * allows us to specify null for the 
writer method and thus
+                                        * find read only properties.
+                                        */
+                                       PropertyDescriptor prop = new 
PropertyDescriptor(name, bean.getClass(), "is" + capitalize(name), null);
+                                       reader = prop.getReadMethod();
+                               } catch (IntrospectionException f) {
+                                       // No property exists with that name, 
try a generic get
+                                       // method
+                                       // Object get( Object key )
+                                       try {
+                                               reader = 
bean.getClass().getMethod("get", new Class[] { Object.class });
+                                               params = new Object[] { name };
+                                       } catch (NoSuchMethodException g) {
+                                               // Try an Object get( String 
key) method
+                                               try {
+                                                       reader = 
bean.getClass().getMethod("get", new Class[] { String.class });
+                                                       params = new Object[] { 
name };
+                                               } catch (NoSuchMethodException 
h) {
+                                                       // Give up
+                                               }
+                                       }
+                               }
+                       }
+
+                       // If a reader method has been found
+                       if (reader != null) {
+                               try {
+                                       return reader.invoke(bean, params);
+                               } catch (IllegalAccessException e) {
+                               } catch (IllegalArgumentException e) {
+                               } catch (InvocationTargetException e) {
+                                       throw new JspTagException("Exception 
getting property \"" + name + "\" from bean " + bean.getClass().getName() + ": "
+                                                       + 
e.getTargetException());
+                               }
+                       }
+               }
+
+               return null;
+       }
+
+       static Object beanPropertyValueObject(Object bean, String name, int 
index) throws JspTagException {
+               Object value = beanPropertyValueObject(bean, name);
+               if (value != null) {
+                       if (value.getClass().isArray()) {
+                               return Array.get(value, index);
+                       } else if (index == 0) {
+                               return value;
+                       } else {
+                               return null;
+                       }
+               } else {
+                       return null;
+               }
+       }
+
+       /**
+        * Gets a named property from a JavaBean and returns its value as a 
String,
+        * possibly null.
+        */
+       static String beanPropertyValue(Object bean, String name) throws 
JspTagException {
+               Object value = beanPropertyValueObject(bean, name);
+               return (value != null ? value.toString() : null);
+       }
+
+       /**
+        * Gets a named property from a JavaBean and returns its value as a 
String,
+        * possibly null.
+        */
+       static String beanPropertyValue(Object bean, String name, int index) 
throws JspTagException {
+               Object value = beanPropertyValueObject(bean, name);
+               if (value != null) {
+                       if (value.getClass().isArray()) {
+                               value = Array.get(value, index);
+                       } else if (index != 0) {
+                               value = null;
+                       }
+                       return (value != null ? value.toString() : null);
+               } else {
+                       return null;
+               }
+       }
+
+       /**
+        * Gets a named property (possibly an array property) from a JavaBean 
and
+        * returns its values as an array of Strings, possibly null. If the 
property
+        * is not an array property, an array of size 1 is returned.
+        */
+       static String[] beanPropertyValues(Object bean, String name) throws 
JspTagException {
+               Object value = beanPropertyValueObject(bean, name);
+               return valueToStringArray(value);
+       }
+
+       static String[] beanPropertyValues(Object bean, String name, int index) 
throws JspTagException {
+               Object value = beanPropertyValueObject(bean, name, index);
+               return valueToStringArray(value);
+       }
+
+       private static String[] valueToStringArray(Object value) {
+               if (value != null) {
+                       // Check if the value is an array object
+                       if (value.getClass().isArray()) {
+                               // Convert to an array of Strings
+                               int n = 
java.lang.reflect.Array.getLength(value);
+                               String[] strs = new String[n];
+                               for (int i = 0; i < n; i++) {
+                                       Object o = 
java.lang.reflect.Array.get(value, i);
+                                       strs[i] = (o != null ? o.toString() : 
null);
+                               }
+                               return strs;
+                       }
+                       // If not an array, just convert the object to a String 
in an array
+                       // and return
+                       else {
+                               return new String[] { value.toString() };
+                       }
+               } else {
+                       return null;
+               }
+       }
+
+       /**
+        * Finds the input:form tag enclosing the given tag and returns it.
+        */
+       static Form findFormTag(Tag tag) {
+               Tag formTag = TagSupport.findAncestorWithClass(tag, Form.class);
+               if (formTag != null) {
+                       return (Form) formTag;
+               } else {
+                       return null;
+               }
+       }
+
+       /**
+        * Finds the input:form tag enclosing the given tag and returns the 
"bean"
+        * property from it, that is the default bean for this form, possibly 
null.
+        */
+       static String defaultFormBeanId(Tag tag) {
+               Form form = findFormTag(tag);
+               if (form != null) {
+                       return form.getBean();
+               } else {
+                       return null;
+               }
+       }
 }

Modified: jakarta/taglibs/proper/input/trunk/xml/input.xml
URL: 
http://svn.apache.org/viewvc/jakarta/taglibs/proper/input/trunk/xml/input.xml?view=diff&rev=531141&r1=531140&r2=531141
==============================================================================
--- jakarta/taglibs/proper/input/trunk/xml/input.xml (original)
+++ jakarta/taglibs/proper/input/trunk/xml/input.xml Sat Apr 21 21:22:25 2007
@@ -45,13 +45,13 @@
        <taglib>
                <!-- The following elements are from the JSP 1.2 TLD DTD -->
                <!-- Version number of this tagib -->
-               <tlib-version>1.0</tlib-version>
+               <tlib-version>1.2</tlib-version>
                <!-- Minimum version of JSP spec required -->
                <jsp-version>1.1</jsp-version>
                <!-- jakarta-taglib name of this tag library -->
                <short-name>input</short-name>
                <!-- URI of taglib -->
-               <uri>http://jakarta.apache.org/taglibs/input-1.0</uri>
+               <uri>http://jakarta.apache.org/taglibs/input-1.2</uri>
                <!-- The name to use in titles, etc. for the taglib -->
                <display-name>Input Tag library</display-name>
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to