1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
package org.apache.shale.test.mock; |
19 | |
|
20 | |
import java.util.Locale; |
21 | |
|
22 | |
import javax.faces.application.ViewHandler; |
23 | |
import javax.faces.component.UIViewRoot; |
24 | |
import javax.faces.context.FacesContext; |
25 | |
import javax.faces.render.RenderKitFactory; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
public class MockViewHandler extends ViewHandler { |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 18 | public MockViewHandler() { |
43 | 18 | } |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public Locale calculateLocale(FacesContext context) { |
57 | |
|
58 | |
Locale locale = context.getApplication().getDefaultLocale(); |
59 | |
if (locale == null) { |
60 | |
locale = Locale.getDefault(); |
61 | |
} |
62 | |
return locale; |
63 | |
|
64 | |
} |
65 | |
|
66 | |
|
67 | |
|
68 | |
public String calculateRenderKitId(FacesContext context) { |
69 | |
|
70 | |
String renderKitId = context.getApplication().getDefaultRenderKitId(); |
71 | |
if (renderKitId == null) { |
72 | |
renderKitId = RenderKitFactory.HTML_BASIC_RENDER_KIT; |
73 | |
} |
74 | |
return renderKitId; |
75 | |
|
76 | |
} |
77 | |
|
78 | |
|
79 | |
|
80 | |
public UIViewRoot createView(FacesContext context, String viewId) { |
81 | |
|
82 | |
|
83 | |
Locale locale = null; |
84 | |
String renderKitId = null; |
85 | |
if (context.getViewRoot() != null) { |
86 | |
locale = context.getViewRoot().getLocale(); |
87 | |
renderKitId = context.getViewRoot().getRenderKitId(); |
88 | |
} |
89 | |
|
90 | |
|
91 | |
UIViewRoot view = new UIViewRoot(); |
92 | |
view.setViewId(viewId); |
93 | |
if (locale != null) { |
94 | |
view.setLocale(locale); |
95 | |
} else { |
96 | |
view.setLocale |
97 | |
(context.getApplication().getViewHandler().calculateLocale(context)); |
98 | |
} |
99 | |
if (renderKitId != null) { |
100 | |
view.setRenderKitId(renderKitId); |
101 | |
} else { |
102 | |
view.setRenderKitId |
103 | |
(context.getApplication().getViewHandler().calculateRenderKitId(context)); |
104 | |
} |
105 | |
|
106 | |
|
107 | |
return view; |
108 | |
|
109 | |
} |
110 | |
|
111 | |
|
112 | |
|
113 | |
public String getActionURL(FacesContext context, String viewId) { |
114 | |
|
115 | |
return FacesContext.getCurrentInstance().getExternalContext(). |
116 | |
getRequestContextPath() + viewId; |
117 | |
|
118 | |
} |
119 | |
|
120 | |
|
121 | |
|
122 | |
public String getResourceURL(FacesContext context, String path) { |
123 | |
|
124 | |
return FacesContext.getCurrentInstance().getExternalContext(). |
125 | |
getRequestContextPath() + path; |
126 | |
|
127 | |
} |
128 | |
|
129 | |
|
130 | |
|
131 | |
public void renderView(FacesContext context, UIViewRoot view) { |
132 | |
|
133 | |
throw new UnsupportedOperationException(); |
134 | |
|
135 | |
} |
136 | |
|
137 | |
|
138 | |
|
139 | |
public UIViewRoot restoreView(FacesContext context, String viewId) { |
140 | |
|
141 | |
throw new UnsupportedOperationException(); |
142 | |
|
143 | |
} |
144 | |
|
145 | |
|
146 | |
|
147 | |
public void writeState(FacesContext context) { |
148 | |
|
149 | |
throw new UnsupportedOperationException(); |
150 | |
|
151 | |
} |
152 | |
|
153 | |
|
154 | |
} |