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 @Override
87 public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
88 ELException
89 {
90 AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
91 actx.extendClient(this);
92 boolean found = false;
93 try
94 {
95 found = actx.includeDefinition(parent, this.name);
96 }
97 finally
98 {
99 actx.popExtendedClient(this);
100 }
101 if (!found)
102 {
103 this.nextHandler.apply(ctx, parent);
104 }
105 }
106
107 public boolean apply(FaceletContext ctx, UIComponent parent, String name) throws IOException, FacesException,
108 FaceletException, ELException
109 {
110 if (this.name == name || this.name != null && this.name.equals(name))
111 {
112 this.nextHandler.apply(ctx, parent);
113 return true;
114 }
115 return false;
116 }
117 }