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.composite;
20
21 import java.lang.reflect.Method;
22 import java.net.URL;
23
24 import javax.faces.FacesException;
25 import javax.faces.application.Resource;
26 import javax.faces.application.ResourceHandler;
27 import javax.faces.context.FacesContext;
28 import javax.faces.view.facelets.ComponentConfig;
29 import javax.faces.view.facelets.FaceletHandler;
30 import javax.faces.view.facelets.Tag;
31 import javax.faces.view.facelets.TagConfig;
32 import javax.faces.view.facelets.TagHandler;
33
34 import org.apache.myfaces.view.facelets.tag.TagLibrary;
35
36
37
38
39
40
41
42
43
44 public class CompositeResourceLibrary implements TagLibrary
45 {
46 public final static String NAMESPACE_PREFIX = "http://java.sun.com/jsf/composite/";
47
48 private final ResourceHandler _resourceHandler;
49
50 public CompositeResourceLibrary(FacesContext facesContext)
51 {
52 _resourceHandler = facesContext.getApplication().getResourceHandler();
53 }
54
55 public boolean containsFunction(String ns, String name)
56 {
57
58 return false;
59 }
60
61 public boolean containsNamespace(String ns)
62 {
63 if (ns != null && ns.startsWith(NAMESPACE_PREFIX))
64 {
65 if (ns.length() > NAMESPACE_PREFIX.length())
66 {
67 String libraryName = ns.substring(NAMESPACE_PREFIX.length());
68 return _resourceHandler.libraryExists(libraryName);
69 }
70 }
71 return false;
72 }
73
74 public boolean containsTagHandler(String ns, String localName)
75 {
76 if (ns != null && ns.startsWith(NAMESPACE_PREFIX))
77 {
78 if (ns.length() > NAMESPACE_PREFIX.length())
79 {
80 String libraryName = ns.substring(NAMESPACE_PREFIX.length());
81 String resourceName = localName + ".xhtml";
82 Resource compositeComponentResource = _resourceHandler.createResource(resourceName, libraryName);
83 if (compositeComponentResource != null)
84 {
85 URL url = compositeComponentResource.getURL();
86 return (url != null);
87 }
88 }
89 }
90 return false;
91 }
92
93 public Method createFunction(String ns, String name)
94 {
95
96 return null;
97 }
98
99 public TagHandler createTagHandler(String ns, String localName,
100 TagConfig tag) throws FacesException
101 {
102 if (ns != null && ns.startsWith(NAMESPACE_PREFIX))
103 {
104 if (ns.length() > NAMESPACE_PREFIX.length())
105 {
106 String libraryName = ns.substring(NAMESPACE_PREFIX.length());
107 String resourceName = localName + ".xhtml";
108
109
110
111
112
113
114
115
116 Resource compositeComponentResource = new CompositeResouceWrapper(
117 _resourceHandler.createResource(resourceName, libraryName));
118 if (compositeComponentResource != null)
119 {
120 ComponentConfig componentConfig = new ComponentConfigWrapper(tag,
121 "javax.faces.NamingContainer", null);
122
123 return new CompositeComponentResourceTagHandler(componentConfig, compositeComponentResource);
124 }
125 }
126 }
127 return null;
128 }
129
130 private static class ComponentConfigWrapper implements ComponentConfig
131 {
132
133 protected final TagConfig parent;
134
135 protected final String componentType;
136
137 protected final String rendererType;
138
139 public ComponentConfigWrapper(TagConfig parent, String componentType,
140 String rendererType)
141 {
142 this.parent = parent;
143 this.componentType = componentType;
144 this.rendererType = rendererType;
145 }
146
147 public String getComponentType()
148 {
149 return this.componentType;
150 }
151
152 public String getRendererType()
153 {
154 return this.rendererType;
155 }
156
157 public FaceletHandler getNextHandler()
158 {
159 return this.parent.getNextHandler();
160 }
161
162 public Tag getTag()
163 {
164 return this.parent.getTag();
165 }
166
167 public String getTagId()
168 {
169 return this.parent.getTagId();
170 }
171 }
172 }