Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DirectiveBuilderRule |
|
| 8.0;8 |
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: DirectiveBuilderRule.java 473459 2006-11-10 20:30:12Z gvanmatre $ | |
20 | */ | |
21 | package org.apache.shale.clay.parser.builder.chain; | |
22 | ||
23 | import org.apache.commons.chain.Command; | |
24 | import org.apache.commons.chain.Context; | |
25 | import org.apache.shale.clay.parser.Node; | |
26 | import org.apache.shale.clay.parser.builder.Builder; | |
27 | import org.apache.shale.clay.parser.builder.IgnoreBuilder; | |
28 | import org.apache.shale.clay.parser.builder.JspIncludeDirectiveBuilder; | |
29 | import org.apache.shale.clay.parser.builder.VoidBuilder; | |
30 | ||
31 | /** | |
32 | * <p>This builder will be ordered first in the rule registration list. | |
33 | * If the node has a <code>jsfid</code> attribute, and its value is | |
34 | * "ignore", or "void" then special assumptions will be made. | |
35 | * Beside the clay "ignore" and "void" directives, handles | |
36 | * all "jsp:" nodes. Most are are assigned to the clay "void" | |
37 | * directive except the "jsp:include" and "jsp:directive.include" | |
38 | * elements. The include and directive.include are | |
39 | * converted into a nested clay components. | |
40 | */ | |
41 | 60 | public class DirectiveBuilderRule implements Command { |
42 | ||
43 | /** | |
44 | * <p>The builders that will assined to a "ignore" or "void" | |
45 | * {@link Builder}. | |
46 | * <p> | |
47 | */ | |
48 | 1 | private static final Builder[] BUILDERS = {new IgnoreBuilder(), |
49 | new VoidBuilder(), new JspIncludeDirectiveBuilder()}; | |
50 | ||
51 | /** | |
52 | * <p>If the node has a <code>jsfid</code> attribute, and its value is | |
53 | * "ignore", child elements will be rendered as comment/verbatim | |
54 | * content. The enclosing tag will not be rendered in the document, | |
55 | * only it's children. If the <code>jsfid</code> is "void", | |
56 | * the element will not be rendered but its children will | |
57 | * keep their original characteristics.<br/><br/> | |
58 | * All "jsp:" nodes are assigned to the clay void directive except the | |
59 | * "jsp:include" and "jsp:directive.include". These are converted into a | |
60 | * nested clay component. Nodes with a jsp prefix must be in the | |
61 | * "http://java.sun.com/JSP/Page" namespace to be eligible for this | |
62 | * processing. | |
63 | * </p> | |
64 | * | |
65 | * @param context commons chains | |
66 | * @return <code>true</code> if the command ends the chain | |
67 | * @exception Exception pushes an exception back to the invoking Command | |
68 | */ | |
69 | public boolean execute(Context context) throws Exception { | |
70 | 884 | boolean isFinal = false; |
71 | ||
72 | 884 | BuilderRuleContext builderRuleContext = (BuilderRuleContext) context; |
73 | 884 | Node node = builderRuleContext.getNode(); |
74 | 884 | if (!node.isComment() && node.isStart() && node.getName() != null) { |
75 | 340 | String jsfid = (String) node.getAttributes().get("jsfid"); |
76 | 340 | if (jsfid != null) { |
77 | 27 | if (jsfid.equals("ignore")) { |
78 | builderRuleContext.setBuilder(BUILDERS[0]); | |
79 | isFinal = true; | |
80 | } else if (jsfid.equals("void")) { | |
81 | 2 | builderRuleContext.setBuilder(BUILDERS[1]); |
82 | 2 | isFinal = true; |
83 | 2 | } |
84 | 313 | } else if (node.getQname() != null) { |
85 | 5 | String uri = node.getNamespaceURI(node.getQname()); |
86 | 5 | if (uri != null && uri.equals("http://java.sun.com/JSP/Page")) { |
87 | 4 | if (node.getName().equals("directive.include") |
88 | || node.getName().equals("include")) { | |
89 | 2 | builderRuleContext.setBuilder(BUILDERS[2]); |
90 | 2 | isFinal = true; |
91 | 2 | } else { |
92 | 2 | builderRuleContext.setBuilder(BUILDERS[1]); |
93 | 2 | isFinal = true; |
94 | } | |
95 | } | |
96 | } | |
97 | } | |
98 | ||
99 | 884 | return isFinal; |
100 | } | |
101 | ||
102 | } |