1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    * 
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   * 
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   */
19  package org.apache.myfaces.trinidad.context;
20  
21  import java.awt.Color;
22  import java.util.HashMap;
23  import java.util.List;
24  import java.util.Locale;
25  import java.util.Map;
26  import java.util.TimeZone;
27  
28  import javax.faces.component.UIComponent;
29  import javax.faces.component.UIViewRoot;
30  import javax.faces.context.FacesContext;
31  
32  import org.apache.myfaces.trinidad.change.ChangeManager;
33  import org.apache.myfaces.trinidad.config.RegionManager;
34  import org.apache.myfaces.trinidad.webapp.UploadedFileProcessor;
35  
36  
37  public class MockRequestContext extends RequestContext
38  {
39    public MockRequestContext()
40    {
41      attach();
42    }
43  
44    // Support setting the agent so we can create one RequestContext
45    // and mutate it
46  
47    public void setAgent(Agent agent)
48    {
49      _agent = agent;
50    }
51  
52    @Override
53    public Agent getAgent()
54    {
55      return _agent;
56    }
57  
58    @Override
59    public PageResolver getPageResolver()
60    {
61      throw new UnsupportedOperationException("Not implemented yet");
62    }
63  
64    @Override
65    public PageFlowScopeProvider getPageFlowScopeProvider()
66    {
67      throw new UnsupportedOperationException("Not implemented yet");
68    }
69  
70    @Override
71    public DialogService getDialogService()
72    {
73      throw new UnsupportedOperationException("Not implemented yet");
74    }
75  
76    @Override
77    public Map<String, Object> getPageFlowScope()
78    {
79      return new HashMap<String, Object>();
80    }
81  
82    @Override
83    public void returnFromDialog(Object returnValue, Map<Object, Object> returnParam)
84    {
85      throw new UnsupportedOperationException("Should not be called during rendering");
86    }
87  
88    @Override
89    public void launchDialog(
90        UIViewRoot dialogRoot, 
91        Map<String, Object> dialogParameters, 
92        UIComponent source, 
93        boolean useWindow, 
94        Map<String, Object> windowProperties)
95    {
96      throw new UnsupportedOperationException("Should not be called during rendering");
97    }
98  
99    @Override
100   public boolean isPostback()
101   {
102     return false;
103   }
104   
105   @Override
106   public boolean isPartialRequest(FacesContext context)
107   {
108     return false;
109   }
110 
111   @Override
112   public boolean isDebugOutput()
113   {
114     return false;
115   }
116 
117   @Override
118   public ClientValidation getClientValidation()
119   {
120     return ClientValidation.ALERT;
121   }
122 
123   @Override
124   public boolean isClientValidationDisabled()
125   {
126     return false;
127   }
128 
129   @Override
130   public String getOutputMode()
131   {
132     return null;
133   }
134 
135   public void setSkinFamily(String skin)
136   {
137     _skin = skin;
138   }
139 
140   @Override
141   public String getSkinFamily()
142   {
143     return _skin;
144   }
145 
146   @Override
147   public Accessibility getAccessibilityMode()
148   {
149     return _accMode;
150   }
151 
152   public void setAccessibilityMode(Accessibility accMode)
153   {
154     _accMode = accMode;
155   }
156 
157   @Override
158   public AccessibilityProfile getAccessibilityProfile()
159   {
160     return _accProfile;
161   }
162 
163   public void setAccessibilityProfile(AccessibilityProfile accProfile)
164   {
165     _accProfile = accProfile;
166   }
167 
168   @Override
169   public boolean isRightToLeft()
170   {
171     return _rtl;
172   }
173 
174   public void setRightToLeft(boolean rtl)
175   {
176     _rtl = rtl;
177   }
178 
179   public void setAnimationEnabled(boolean animationEnabled)
180   {
181     _animationEnabled = animationEnabled;
182   }
183 
184   @Override
185   public boolean isAnimationEnabled()
186   {
187     return _animationEnabled;
188   }
189 
190   @Override
191   public Locale getFormattingLocale()
192   {
193     return _formattingLocale;
194   }
195 
196   public void setFormattingLocale(Locale formattingLocale)
197   {
198     _formattingLocale = formattingLocale;
199   }
200 
201   @Override
202   public char getNumberGroupingSeparator()
203   {
204     return _numberGroupingSeparator;
205   }
206 
207   public void setNumberGroupingSeparator(char sep)
208   {
209     _numberGroupingSeparator = sep;
210   }
211 
212   @Override
213   public char getDecimalSeparator()
214   {
215     return _decimalSeparator;
216   }
217 
218   public void setDecimalSeparator(char sep)
219   {
220     _decimalSeparator = sep;
221   }
222 
223   @Override
224   public String getCurrencyCode()
225   {
226     return _currencyCode;
227   }
228 
229   public void setCurrencyCode(String code)
230   {
231     _currencyCode = code;
232   }
233 
234   @Override
235   public int getTwoDigitYearStart()
236   {
237     return _twoDigitYearStart;
238   }
239 
240   public void setTwoDigitYearStart(int start)
241   {
242     _twoDigitYearStart = start;
243   }
244 
245   @Override
246   public String getOracleHelpServletUrl()
247   {
248     throw new UnsupportedOperationException("Not implemented yet");
249   }
250 
251   @Override
252   public Map<String, Object> getHelpTopic()
253   {
254     throw new UnsupportedOperationException("Not implemented yet");
255   }
256 
257   @Override
258   public Map<String, Object> getHelpSystem()
259   {
260     throw new UnsupportedOperationException("Not implemented yet");
261   }
262 
263   @Override
264   public TimeZone getTimeZone()
265   {
266     return _timeZone;
267   }
268 
269   public void setTimeZone(TimeZone timeZone)
270   {
271     _timeZone = timeZone;
272   }
273 
274   @Override
275   public void addPartialTarget(UIComponent newTarget)
276   {
277     // throw new UnsupportedOperationException("Not implemented yet");
278   }
279   
280   /**
281    * @see org.apache.myfaces.trinidad.context.RequestContext#addPartialTargets(javax.faces.component.UIComponent, java.lang.String[])
282    */
283   @Override
284   public void addPartialTargets(UIComponent from, String... targets)
285   {
286     
287   }
288 
289   @Override
290   public void addPartialTriggerListeners(UIComponent listener, String[] trigger)
291   {
292     throw new UnsupportedOperationException("Should not be called during rendering");
293   }
294 
295   @Override
296   public void partialUpdateNotify(UIComponent updated)
297   {
298     throw new UnsupportedOperationException("Should not be called during rendering");
299   }
300 
301   @Override
302   public UploadedFileProcessor getUploadedFileProcessor()
303   {
304     throw new UnsupportedOperationException("Should not be called during rendering");
305   }
306 
307   @Override
308   public Map<String, List<Color>> getColorPalette()
309   {
310     throw new UnsupportedOperationException("Not implemented yet");
311   }
312 
313   @Override
314   public Map<Object, Map<Object,String>> getFormatter()
315   {
316     throw new UnsupportedOperationException("Not implemented yet");
317   }
318 
319   @Override
320   public ChangeManager getChangeManager()
321   {
322     throw new UnsupportedOperationException("Not implemented yet");
323   }
324 
325   @Override
326   public RegionManager getRegionManager()
327   {
328     throw new UnsupportedOperationException("Not implemented yet");
329   }
330 
331   @Override
332   public Object saveComponent(UIComponent component)
333   {
334     throw new UnsupportedOperationException("Not implemented yet");
335   }
336 
337 
338   @Override
339   public UIComponent restoreComponent(Object state)
340   {
341     throw new UnsupportedOperationException("Not implemented yet");
342   }
343 
344 
345   static private final TimeZone _FIXED_TIME_ZONE =
346     TimeZone.getTimeZone("America/Los_Angeles");
347 
348   private char _numberGroupingSeparator = ',';
349   private char _decimalSeparator = '.';
350   private String _currencyCode = null;
351   private int _twoDigitYearStart = 1950;
352   private TimeZone _timeZone = _FIXED_TIME_ZONE;
353 
354   private String _skin;
355   private Accessibility _accMode;
356   private AccessibilityProfile _accProfile;
357   private Agent _agent;
358   private boolean _rtl = false;
359   private boolean _animationEnabled = true;
360   private Locale _formattingLocale;
361 }