1 14 15 package com.sun.facelets.tag.jstl.fn; 16 17 import java.lang.reflect.Method ; 18 import java.lang.reflect.Modifier ; 19 import java.util.HashMap ; 20 import java.util.Map ; 21 22 import javax.faces.FacesException; 23 24 import com.sun.facelets.tag.TagConfig; 25 import com.sun.facelets.tag.TagHandler; 26 import com.sun.facelets.tag.TagLibrary; 27 28 34 public class JstlFnLibrary implements TagLibrary { 35 36 public final static String Namespace = "http://java.sun.com/jsp/jstl/functions"; 37 38 private final Map fns = new HashMap (); 39 40 public JstlFnLibrary() { 41 super(); 42 try { 43 Method [] methods = JstlFunction.class.getMethods(); 44 for (int i = 0; i < methods.length; i++) { 45 if (Modifier.isStatic(methods[i].getModifiers())) { 46 fns.put(methods[i].getName(), methods[i]); 47 } 48 } 49 } catch (Exception e) { 50 throw new RuntimeException (e); 51 } 52 } 53 54 public boolean containsNamespace(String ns) { 55 return Namespace.equals(ns); 56 } 57 58 public boolean containsTagHandler(String ns, String localName) { 59 return false; 60 } 61 62 public TagHandler createTagHandler(String ns, String localName, 63 TagConfig tag) throws FacesException { 64 return null; 65 } 66 67 public boolean containsFunction(String ns, String name) { 68 if (Namespace.equals(ns)) { 69 return this.fns.containsKey(name); 70 } 71 return false; 72 } 73 74 public Method createFunction(String ns, String name) { 75 if (Namespace.equals(ns)) { 76 return (Method ) this.fns.get(name); 77 } 78 return null; 79 } 80 81 public static void main(String [] argv) { 82 JstlFnLibrary lib = new JstlFnLibrary(); 83 System.out.println(lib.containsFunction(JstlFnLibrary.Namespace, "toUpperCase")); 84 } 85 86 } 87 | Popular Tags |