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.ui;
20
21 import java.io.IOException;
22
23 import javax.el.ELException;
24 import javax.faces.FacesException;
25 import javax.faces.component.UIComponent;
26 import javax.faces.view.facelets.FaceletContext;
27 import javax.faces.view.facelets.FaceletException;
28 import javax.faces.view.facelets.TagAttribute;
29 import javax.faces.view.facelets.TagAttributeException;
30 import javax.faces.view.facelets.TagConfig;
31 import javax.faces.view.facelets.TagHandler;
32
33 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletAttribute;
34 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
35 import org.apache.myfaces.view.facelets.AbstractFaceletContext;
36 import org.apache.myfaces.view.facelets.TemplateClient;
37 import org.apache.myfaces.view.facelets.tag.ComponentContainerHandler;
38
39
40
41
42
43
44
45 @JSFFaceletTag(name="ui:insert")
46 public final class InsertHandler extends TagHandler implements TemplateClient, ComponentContainerHandler
47 {
48
49
50
51
52
53
54 @JSFFaceletAttribute(
55 className="javax.el.ValueExpression",
56 deferredValueType="java.lang.String",
57 required=true)
58 private final String name;
59
60
61
62
63 public InsertHandler(TagConfig config)
64 {
65 super(config);
66 TagAttribute attr = this.getAttribute("name");
67 if (attr != null)
68 {
69 if (!attr.isLiteral())
70 {
71 throw new TagAttributeException(this.tag, attr, "Must be Literal");
72 }
73 this.name = attr.getValue();
74 }
75 else
76 {
77 this.name = null;
78 }
79 }
80
81
82
83
84
85
86 public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
87 ELException
88 {
89 AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
90 actx.extendClient(this);
91 boolean found = false;
92 try
93 {
94 found = actx.includeDefinition(parent, this.name);
95 }
96 finally
97 {
98 actx.popExtendedClient(this);
99 }
100 if (!found)
101 {
102 this.nextHandler.apply(ctx, parent);
103 }
104 }
105
106 public boolean apply(FaceletContext ctx, UIComponent parent, String name) throws IOException, FacesException,
107 FaceletException, ELException
108 {
109 if (this.name == name || this.name != null && this.name.equals(name))
110 {
111 this.nextHandler.apply(ctx, parent);
112 return true;
113 }
114 return false;
115 }
116 }