2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

View Javadoc

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  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      // ------------------------------------------------------------ Constructors
37  
38  
39      /***
40       * <p>Construct a default instance.</p>
41       */
42      public MockViewHandler() {
43      }
44  
45  
46      // ----------------------------------------------------- Mock Object Methods
47  
48  
49      // ------------------------------------------------------ Instance Variables
50  
51  
52      // ----------------------------------------------------- ViewHandler Methods
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          // Save locale and renderKitId from previous view (if any), per spec
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          // Configure a new UIViewRoot instance
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         // Return the configured instance
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 }