KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > examples > taglib > Functions


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.taglibs.standard.examples.taglib;
18
19 import java.lang.reflect.Array JavaDoc;
20
21 import javax.servlet.jsp.JspTagException JavaDoc;
22
23 /**
24  * <p>Exmaples taglib Functions</p>
25  *
26  * @author Pierre Delisle
27  */

28
29 public class Functions {
30
31     /**
32      * Display the collection types supported by c:forEach.
33      */

34     public static String JavaDoc display(Object JavaDoc obj) throws JspTagException JavaDoc {
35         if (obj == null) return "";
36         if (obj instanceof String JavaDoc) return obj.toString();
37         /*
38         if (obj instanceof Collection) {
39             return "FIXME";
40         }
41         if (obj instanceof Map) {
42             return "FIXME";
43         }
44         if (obj instanceof Iterator) {
45             Iterator iter = (Iterator)obj;
46             while (iter.hasNext()) {
47                 iter.next();
48             }
49             return "FIXME";
50         }
51         if (obj instanceof Enumeration) {
52             Enumeration enum_ = (Enumeration)obj;
53             while (enum_.hasMoreElements()) {
54                 enum_.nextElement();
55             }
56             return "FIXME";
57         }
58         */

59         try {
60             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
61             int count = Array.getLength(obj);
62             for (int i=0; i<count; i++) {
63                 buf.append(Array.get(obj, i).toString());
64                 if (i<count-1) buf.append("<font color='red'> &#149; </font>");
65             }
66             return buf.toString();
67         } catch (IllegalArgumentException JavaDoc ex) {}
68         throw new JspTagException JavaDoc("Bad Item");
69     }
70 }
71
Popular Tags