2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
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 * <p>Mock implementation of <code>ViewHandler</code>.</p>
29 *
30 * $Id$
31 */
32
33 public class MockViewHandler extends ViewHandler {
34
35
36
37
38
39 /***
40 * <p>Construct a default instance.</p>
41 */
42 public MockViewHandler() {
43 }
44
45
46
47
48
49
50
51
52
53
54
55 /*** {@inheritDoc} */
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 /*** {@inheritDoc} */
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 /*** {@inheritDoc} */
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 /*** {@inheritDoc} */
113 public String getActionURL(FacesContext context, String viewId) {
114
115 return FacesContext.getCurrentInstance().getExternalContext().
116 getRequestContextPath() + viewId;
117
118 }
119
120
121 /*** {@inheritDoc} */
122 public String getResourceURL(FacesContext context, String path) {
123
124 return FacesContext.getCurrentInstance().getExternalContext().
125 getRequestContextPath() + path;
126
127 }
128
129
130 /*** {@inheritDoc} */
131 public void renderView(FacesContext context, UIViewRoot view) {
132
133 throw new UnsupportedOperationException();
134
135 }
136
137
138 /*** {@inheritDoc} */
139 public UIViewRoot restoreView(FacesContext context, String viewId) {
140
141 throw new UnsupportedOperationException();
142
143 }
144
145
146 /*** {@inheritDoc} */
147 public void writeState(FacesContext context) {
148
149 throw new UnsupportedOperationException();
150
151 }
152
153
154 }