1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.tag.jstl.fn;
20
21 import java.lang.reflect.Method;
22 import java.lang.reflect.Modifier;
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import javax.faces.FacesException;
27 import javax.faces.view.facelets.TagConfig;
28 import javax.faces.view.facelets.TagHandler;
29
30 import org.apache.myfaces.view.facelets.tag.TagLibrary;
31
32
33
34
35
36
37
38 public class JstlFnLibrary implements TagLibrary
39 {
40 public final static String Namespace = "http://java.sun.com/jsp/jstl/functions";
41
42 private final Map<String, Method> fns = new HashMap<String, Method>();
43
44 public JstlFnLibrary()
45 {
46 super();
47 try
48 {
49 Method[] methods = JstlFunction.class.getMethods();
50 for (int i = 0; i < methods.length; i++)
51 {
52 if (Modifier.isStatic(methods[i].getModifiers()))
53 {
54 fns.put(methods[i].getName(), methods[i]);
55 }
56 }
57 }
58 catch (Exception e)
59 {
60 throw new RuntimeException(e);
61 }
62 }
63
64 public boolean containsNamespace(String ns)
65 {
66 return Namespace.equals(ns);
67 }
68
69 public boolean containsTagHandler(String ns, String localName)
70 {
71 return false;
72 }
73
74 public TagHandler createTagHandler(String ns, String localName, TagConfig tag) throws FacesException
75 {
76 return null;
77 }
78
79 public boolean containsFunction(String ns, String name)
80 {
81 if (Namespace.equals(ns))
82 {
83 return this.fns.containsKey(name);
84 }
85
86 return false;
87 }
88
89 public Method createFunction(String ns, String name)
90 {
91 if (Namespace.equals(ns))
92 {
93 return (Method) this.fns.get(name);
94 }
95
96 return null;
97 }
98 }