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.compiler; |
20 | |
|
21 | |
import java.io.IOException; |
22 | |
import java.lang.reflect.Method; |
23 | |
import java.util.Map; |
24 | |
import javax.el.ELContext; |
25 | |
|
26 | |
import javax.el.ELException; |
27 | |
import javax.el.FunctionMapper; |
28 | |
import javax.faces.FacesException; |
29 | |
import javax.faces.component.UIComponent; |
30 | |
import javax.faces.view.facelets.ComponentHandler; |
31 | |
import javax.faces.view.facelets.FaceletContext; |
32 | |
import javax.faces.view.facelets.FaceletException; |
33 | |
import javax.faces.view.facelets.FaceletHandler; |
34 | |
import org.apache.myfaces.el.unified.FacesELContext; |
35 | |
|
36 | |
import org.apache.myfaces.view.facelets.el.CompositeFunctionMapper; |
37 | |
import org.apache.myfaces.view.facelets.tag.TagLibrary; |
38 | |
import org.apache.myfaces.view.facelets.tag.composite.CompositeComponentResourceTagHandler; |
39 | |
|
40 | |
final class NamespaceHandler extends FunctionMapper implements FaceletHandler |
41 | |
{ |
42 | |
|
43 | |
private final TagLibrary library; |
44 | |
private final Map<String, String> ns; |
45 | |
private FaceletHandler next; |
46 | |
|
47 | |
public NamespaceHandler(FaceletHandler next, TagLibrary library, Map<String, String> ns) |
48 | 0 | { |
49 | 0 | this.library = library; |
50 | 0 | this.ns = ns; |
51 | 0 | this.next = next; |
52 | 0 | } |
53 | |
|
54 | |
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException, |
55 | |
ELException |
56 | |
{ |
57 | 0 | FunctionMapper orig = ctx.getFunctionMapper(); |
58 | 0 | ELContext elContext = ctx.getFacesContext().getELContext(); |
59 | 0 | if (elContext instanceof FacesELContext) |
60 | |
{ |
61 | 0 | ((FacesELContext) elContext).setFunctionMapper(this); |
62 | |
} |
63 | 0 | ctx.setFunctionMapper(new CompositeFunctionMapper(this, orig)); |
64 | |
try |
65 | |
{ |
66 | 0 | next.apply(ctx, parent); |
67 | |
} |
68 | |
finally |
69 | |
{ |
70 | 0 | ctx.setFunctionMapper(orig); |
71 | 0 | } |
72 | 0 | } |
73 | |
|
74 | |
public Method resolveFunction(String prefix, String localName) |
75 | |
{ |
76 | 0 | String uri = (String) this.ns.get(prefix); |
77 | 0 | if (uri != null) |
78 | |
{ |
79 | 0 | return this.library.createFunction(uri, localName); |
80 | |
} |
81 | 0 | return null; |
82 | |
} |
83 | |
|
84 | |
public boolean isNextHandlerComponent() |
85 | |
{ |
86 | 0 | return (next instanceof ComponentHandler); |
87 | |
} |
88 | |
|
89 | |
public boolean isNextHandlerCompositeComponent() |
90 | |
{ |
91 | 0 | return (next instanceof CompositeComponentResourceTagHandler); |
92 | |
} |
93 | |
} |