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.jsf.core; |
20 | |
|
21 | |
import java.io.IOException; |
22 | |
import java.util.ArrayList; |
23 | |
import java.util.List; |
24 | |
|
25 | |
import javax.el.ELException; |
26 | |
import javax.el.MethodExpression; |
27 | |
import javax.faces.FacesException; |
28 | |
import javax.faces.component.UIComponent; |
29 | |
import javax.faces.component.UIViewRoot; |
30 | |
import javax.faces.event.PhaseEvent; |
31 | |
import javax.faces.view.facelets.FaceletContext; |
32 | |
import javax.faces.view.facelets.FaceletException; |
33 | |
import javax.faces.view.facelets.TagAttribute; |
34 | |
import javax.faces.view.facelets.TagConfig; |
35 | |
import javax.faces.view.facelets.TagHandler; |
36 | |
|
37 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletAttribute; |
38 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag; |
39 | |
import org.apache.myfaces.shared.util.StringUtils; |
40 | |
import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
@JSFFaceletTag( |
50 | |
name = "f:view", |
51 | |
bodyContent = "empty", |
52 | |
componentClass="javax.faces.component.UIViewRoot") |
53 | |
public final class ViewHandler extends TagHandler |
54 | |
{ |
55 | |
|
56 | 0 | private final static Class<?>[] LISTENER_SIG = new Class<?>[] { PhaseEvent.class }; |
57 | |
|
58 | |
@JSFFaceletAttribute |
59 | |
private final TagAttribute locale; |
60 | |
|
61 | |
@JSFFaceletAttribute |
62 | |
private final TagAttribute renderKitId; |
63 | |
|
64 | |
@JSFFaceletAttribute |
65 | |
private final TagAttribute contentType; |
66 | |
|
67 | |
@JSFFaceletAttribute |
68 | |
private final TagAttribute encoding; |
69 | |
|
70 | |
@JSFFaceletAttribute |
71 | |
private final TagAttribute beforePhase; |
72 | |
|
73 | |
@JSFFaceletAttribute |
74 | |
private final TagAttribute afterPhase; |
75 | |
|
76 | |
@JSFFaceletAttribute(name="transient") |
77 | |
private final TagAttribute transientAttribute; |
78 | |
|
79 | |
private final TagAttribute contracts; |
80 | |
|
81 | |
private final TagAttribute oamEnableViewPool; |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
public ViewHandler(TagConfig config) |
87 | |
{ |
88 | 0 | super(config); |
89 | 0 | this.locale = this.getAttribute("locale"); |
90 | 0 | this.renderKitId = this.getAttribute("renderKitId"); |
91 | 0 | this.contentType = this.getAttribute("contentType"); |
92 | 0 | this.encoding = this.getAttribute("encoding"); |
93 | 0 | this.beforePhase = this.getAttribute("beforePhase"); |
94 | 0 | this.afterPhase = this.getAttribute("afterPhase"); |
95 | 0 | this.transientAttribute = this.getAttribute("transient"); |
96 | 0 | this.contracts = this.getAttribute("contracts"); |
97 | 0 | this.oamEnableViewPool = this.getAttribute("oamEnableViewPool"); |
98 | 0 | } |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException, |
106 | |
ELException |
107 | |
{ |
108 | 0 | UIViewRoot root = ComponentSupport.getViewRoot(ctx, parent); |
109 | 0 | if (root != null) |
110 | |
{ |
111 | 0 | if (this.locale != null) |
112 | |
{ |
113 | 0 | root.setLocale(ComponentSupport.getLocale(ctx, this.locale)); |
114 | |
} |
115 | 0 | if (this.renderKitId != null) |
116 | |
{ |
117 | 0 | String v = this.renderKitId.getValue(ctx); |
118 | 0 | root.setRenderKitId(v); |
119 | |
} |
120 | 0 | String encodingValue = null; |
121 | 0 | if (this.contentType != null) |
122 | |
{ |
123 | |
|
124 | |
|
125 | |
|
126 | 0 | String v = this.contentType.getValue(ctx); |
127 | 0 | if (v != null) |
128 | |
{ |
129 | 0 | int j = v.indexOf(';'); |
130 | 0 | if (j >= 0) |
131 | |
{ |
132 | 0 | int i = v.indexOf("charset",j); |
133 | 0 | if (i >= 0) |
134 | |
{ |
135 | 0 | i = v.indexOf('=',i)+1; |
136 | 0 | if (v.length() > i) |
137 | |
{ |
138 | 0 | encodingValue = v.substring(i); |
139 | |
} |
140 | |
|
141 | |
|
142 | |
|
143 | 0 | v = v.substring(0 , j); |
144 | |
} |
145 | |
} |
146 | |
} |
147 | 0 | ctx.getFacesContext().getAttributes().put("facelets.ContentType", v); |
148 | |
} |
149 | 0 | if (this.encoding != null) |
150 | |
{ |
151 | 0 | String v = this.encoding.getValue(ctx); |
152 | 0 | ctx.getFacesContext().getAttributes().put("facelets.Encoding", v); |
153 | 0 | } |
154 | 0 | else if (encodingValue != null) |
155 | |
{ |
156 | 0 | ctx.getFacesContext().getAttributes().put("facelets.Encoding", encodingValue); |
157 | |
} |
158 | 0 | if (this.beforePhase != null) |
159 | |
{ |
160 | 0 | MethodExpression m = this.beforePhase.getMethodExpression(ctx, null, LISTENER_SIG); |
161 | 0 | root.setBeforePhaseListener(m); |
162 | |
} |
163 | 0 | if (this.afterPhase != null) |
164 | |
{ |
165 | 0 | MethodExpression m = this.afterPhase.getMethodExpression(ctx, null, LISTENER_SIG); |
166 | 0 | root.setAfterPhaseListener(m); |
167 | |
} |
168 | 0 | if (this.transientAttribute != null) |
169 | |
{ |
170 | 0 | root.setTransient(this.transientAttribute.getBoolean(ctx)); |
171 | |
} |
172 | 0 | if (this.contracts != null) |
173 | |
{ |
174 | 0 | String contractsValue = this.contracts.getValue(ctx); |
175 | 0 | if (contractsValue != null) |
176 | |
{ |
177 | 0 | String[] values = StringUtils.trim( |
178 | |
StringUtils.splitShortString(contractsValue, ',')); |
179 | 0 | if (values != null) |
180 | |
{ |
181 | 0 | List<String> list = new ArrayList<String>(); |
182 | 0 | for (String v : values) |
183 | |
{ |
184 | 0 | list.add(v); |
185 | |
} |
186 | 0 | ctx.getFacesContext().setResourceLibraryContracts(list); |
187 | |
} |
188 | |
} |
189 | |
} |
190 | 0 | if (this.oamEnableViewPool != null) |
191 | |
{ |
192 | 0 | root.getAttributes().put("oamEnableViewPool", this.oamEnableViewPool.getBoolean(ctx)); |
193 | |
} |
194 | |
} |
195 | 0 | this.nextHandler.apply(ctx, parent); |
196 | 0 | } |
197 | |
|
198 | |
} |