Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
JspIncludeDirectiveBuilder |
|
| 2.2;2.2 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to you under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | ||
18 | /* | |
19 | * $Id: JspIncludeDirectiveBuilder.java 473459 2006-11-10 20:30:12Z gvanmatre $ | |
20 | */ | |
21 | package org.apache.shale.clay.parser.builder; | |
22 | ||
23 | import java.util.Iterator; | |
24 | ||
25 | import org.apache.shale.clay.config.beans.AttributeBean; | |
26 | import org.apache.shale.clay.config.beans.ComponentBean; | |
27 | import org.apache.shale.clay.config.beans.ElementBean; | |
28 | import org.apache.shale.clay.config.beans.SymbolBean; | |
29 | import org.apache.shale.clay.parser.Node; | |
30 | ||
31 | ||
32 | /** | |
33 | * <p>Simulates a JSP include directive.include using the | |
34 | * {@link org.apache.shale.clay.component.Clay} component. | |
35 | * For a "jsp:include" node, the child "param" nodes | |
36 | * will be converted into symbols.</p> | |
37 | */ | |
38 | 1 | public class JspIncludeDirectiveBuilder extends Builder { |
39 | ||
40 | ||
41 | ||
42 | /** | |
43 | * <p> | |
44 | * Returns the <code>jsfid</code> associated with the {@link ElementBean} | |
45 | * being build. | |
46 | * </p> | |
47 | * | |
48 | * @param node markup | |
49 | * @return jsfid | |
50 | */ | |
51 | protected String getJsfid(Node node) { | |
52 | 2 | return "clay"; |
53 | } | |
54 | ||
55 | /** | |
56 | * <p> | |
57 | * Returns the JSF component type of | |
58 | * <code>org.apache.shale.clay.component.Clay</code> that will populate the | |
59 | * componentType property of the {@link ElementBean} being created. | |
60 | * </p> | |
61 | * | |
62 | * @param node markup | |
63 | * @return component type | |
64 | */ | |
65 | protected String getComponentType(Node node) { | |
66 | 2 | return "org.apache.shale.clay.component.Clay"; |
67 | } | |
68 | ||
69 | /** | |
70 | * <p> | |
71 | * Returns a boolean value that will indicate if the target JSF component | |
72 | * will support children. | |
73 | * </p> | |
74 | * | |
75 | * @return <code>true</code> | |
76 | */ | |
77 | public boolean isChildrenAllowed() { | |
78 | 2 | return true; |
79 | } | |
80 | ||
81 | /** | |
82 | * <p>Calls super to populate the <code>target</code> config bean with the | |
83 | * html <code>node</code>'s values. | |
84 | * When processing a "jsp:directive.include", the "file" attribute doesn't have a | |
85 | * corresponding clay value so it will become a symbol aliased to | |
86 | * clay's "clayJsfid" attribute. The same goes for the "jsp:include". The | |
87 | * "page" symbol is aliased to the "clayJsfid" attribute. Nested "param" | |
88 | * nodes are converted into symbols.</p> | |
89 | * | |
90 | * @param node markup node | |
91 | * @param target config bean | |
92 | * @param root parent config bean | |
93 | */ | |
94 | protected void encodeBegin(Node node, ElementBean target, ComponentBean root) { | |
95 | 2 | super.encodeBegin(node, target, root); |
96 | ||
97 | 2 | if (node.getName().equals("directive.include")) { |
98 | 1 | AttributeBean attr = target.getAttribute("clayJsfid"); |
99 | 1 | SymbolBean symbol = target.getSymbol("file"); |
100 | 1 | if (symbol != null && attr != null) { |
101 | 1 | createAttribute(attr, "@file", target); |
102 | } | |
103 | 1 | } else if (node.getName().equals("include")) { |
104 | 1 | AttributeBean attr = target.getAttribute("clayJsfid"); |
105 | 1 | SymbolBean symbol = target.getSymbol("@page"); |
106 | 1 | if (symbol != null && attr != null) { |
107 | 1 | createAttribute(attr, "@page", target); |
108 | } | |
109 | 1 | Iterator ai = node.getChildren().iterator(); |
110 | 12 | while (ai.hasNext()) { |
111 | 11 | Node child = (Node) ai.next(); |
112 | 11 | if (child.getName() != null && child.getName().equals("param")) { |
113 | 5 | String name = (String) child.getAttributes().get("name"); |
114 | 5 | String value = (String) child.getAttributes().get("value"); |
115 | ||
116 | 5 | SymbolBean paramSymbol = new SymbolBean(); |
117 | 5 | paramSymbol.setName(name); |
118 | 5 | paramSymbol.setValue(value); |
119 | 5 | target.addSymbol(paramSymbol); |
120 | } | |
121 | 11 | } |
122 | // remove the children, don't waste any more time processing | |
123 | 1 | node.getChildren().clear(); |
124 | } | |
125 | 2 | } |
126 | ||
127 | /** | |
128 | * <p>This builder handles converting the <code>nodes</code>'s children.</p> | |
129 | * @param node markup node | |
130 | * @param target config bean | |
131 | * @return <code>true</code> indicating that children of the <code>node</code> | |
132 | * should be ignored. | |
133 | */ | |
134 | protected boolean getBuildNodeBody(Node node, ElementBean target) { | |
135 | 2 | return true; |
136 | } | |
137 | ||
138 | } |