01: /**
02: * Licensed under the Common Development and Distribution License,
03: * you may not use this file except in compliance with the License.
04: * You may obtain a copy of the License at
05: *
06: * http://www.sun.com/cddl/
07: *
08: * Unless required by applicable law or agreed to in writing, software
09: * 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: */package com.sun.facelets.tag.ui;
14:
15: import java.io.IOException;
16:
17: import javax.el.ELException;
18: import javax.faces.FacesException;
19: import javax.faces.component.UIComponent;
20:
21: import com.sun.facelets.FaceletContext;
22: import com.sun.facelets.FaceletException;
23: import com.sun.facelets.FaceletHandler;
24: import com.sun.facelets.TemplateClient;
25: import com.sun.facelets.tag.TagAttribute;
26: import com.sun.facelets.tag.TagAttributeException;
27: import com.sun.facelets.tag.TagConfig;
28: import com.sun.facelets.tag.TagHandler;
29:
30: /**
31: * @author Jacob Hookom
32: * @version $Id: InsertHandler.java,v 1.6 2006/04/03 06:25:36 jhook Exp $
33: */
34: public final class InsertHandler extends TagHandler implements
35: TemplateClient {
36:
37: private final String name;
38:
39: /**
40: * @param config
41: */
42: public InsertHandler(TagConfig config) {
43: super (config);
44: TagAttribute attr = this .getAttribute("name");
45: if (attr != null) {
46: if (!attr.isLiteral()) {
47: throw new TagAttributeException(this .tag, attr,
48: "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,
64: ELException {
65:
66: ctx.extendClient(this );
67: boolean found = false;
68: try {
69: found = ctx.includeDefinition(parent, this .name);
70: } finally {
71: ctx.popClient(this );
72: }
73: if (!found) {
74: this .nextHandler.apply(ctx, parent);
75: }
76: }
77:
78: public boolean apply(FaceletContext ctx, UIComponent parent,
79: String name) throws IOException, FacesException,
80: FaceletException, ELException {
81: if (this .name == name || this .name != null
82: && this .name.equals(name)) {
83: this .nextHandler.apply(ctx, parent);
84: return true;
85: }
86: return false;
87: }
88: }
|