Source code: com/sun/facelets/tag/ui/InsertHandler.java
1 /**
2 * Licensed under the Common Development and Distribution License,
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.sun.com/cddl/
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11 * implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15 package com.sun.facelets.tag.ui;
16
17 import java.io.IOException;
18
19 import javax.el.ELException;
20 import javax.faces.FacesException;
21 import javax.faces.component.UIComponent;
22
23 import com.sun.facelets.FaceletContext;
24 import com.sun.facelets.FaceletException;
25 import com.sun.facelets.FaceletHandler;
26 import com.sun.facelets.TemplateClient;
27 import com.sun.facelets.tag.TagAttribute;
28 import com.sun.facelets.tag.TagAttributeException;
29 import com.sun.facelets.tag.TagConfig;
30 import com.sun.facelets.tag.TagHandler;
31
32 /**
33 * @author Jacob Hookom
34 * @version $Id: InsertHandler.java,v 1.6 2006/04/03 06:25:36 jhook Exp $
35 */
36 public final class InsertHandler extends TagHandler implements TemplateClient {
37
38 private final String name;
39
40 /**
41 * @param config
42 */
43 public InsertHandler(TagConfig config) {
44 super(config);
45 TagAttribute attr = this.getAttribute("name");
46 if (attr != null) {
47 if (!attr.isLiteral()) {
48 throw new TagAttributeException(this.tag, attr, "Must be Literal");
49 }
50 this.name = attr.getValue();
51 } else {
52 this.name = null;
53 }
54 }
55
56 /*
57 * (non-Javadoc)
58 *
59 * @see com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext,
60 * javax.faces.component.UIComponent)
61 */
62 public void apply(FaceletContext ctx, UIComponent parent)
63 throws IOException, FacesException, FaceletException, ELException {
64
65 ctx.extendClient(this);
66 boolean found = false;
67 try {
68 found = ctx.includeDefinition(parent, this.name);
69 } finally {
70 ctx.popClient(this);
71 }
72 if (!found) {
73 this.nextHandler.apply(ctx, parent);
74 }
75 }
76
77 public boolean apply(FaceletContext ctx, UIComponent parent, String name) throws IOException, FacesException, FaceletException, ELException {
78 if (this.name == name || this.name != null && this.name.equals(name)) {
79 this.nextHandler.apply(ctx, parent);
80 return true;
81 }
82 return false;
83 }
84 }