1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.context; |
20 | |
|
21 | |
import javax.faces.FacesException; |
22 | |
import javax.faces.FactoryFinder; |
23 | |
import javax.faces.context.ExternalContext; |
24 | |
import javax.faces.context.ExternalContextFactory; |
25 | |
import javax.faces.context.FlashFactory; |
26 | |
import javax.servlet.ServletContext; |
27 | |
import javax.servlet.ServletRequest; |
28 | |
import javax.servlet.ServletResponse; |
29 | |
|
30 | |
import org.apache.myfaces.context.servlet.ServletExternalContextImpl; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class ExternalContextFactoryImpl extends ExternalContextFactory |
39 | |
{ |
40 | |
|
41 | |
public static final String EXTERNAL_CONTEXT_KEY = |
42 | |
"org.apache.myfaces.context.servlet.ServletExternalContextImpl"; |
43 | |
|
44 | |
private final FlashFactory _flashFactory; |
45 | |
|
46 | |
public ExternalContextFactoryImpl() |
47 | 0 | { |
48 | 0 | _flashFactory = (FlashFactory) FactoryFinder.getFactory( |
49 | |
FactoryFinder.FLASH_FACTORY); |
50 | 0 | } |
51 | |
|
52 | |
@Override |
53 | |
public ExternalContext getExternalContext(Object context, Object request, |
54 | |
Object response) throws FacesException |
55 | |
{ |
56 | 0 | if (context == null) |
57 | |
{ |
58 | 0 | throw new NullPointerException("context"); |
59 | |
} |
60 | 0 | if (request == null) |
61 | |
{ |
62 | 0 | throw new NullPointerException("request"); |
63 | |
} |
64 | 0 | if (response == null) |
65 | |
{ |
66 | 0 | throw new NullPointerException("response"); |
67 | |
} |
68 | |
|
69 | 0 | if (context instanceof ServletContext) |
70 | |
{ |
71 | 0 | ExternalContext externalContext = new ServletExternalContextImpl( |
72 | |
(ServletContext) context, (ServletRequest) request, (ServletResponse) response, |
73 | |
_flashFactory); |
74 | |
|
75 | 0 | externalContext.getRequestMap().put(EXTERNAL_CONTEXT_KEY, externalContext); |
76 | |
|
77 | 0 | return externalContext; |
78 | |
} |
79 | |
|
80 | 0 | throw new FacesException("Unsupported context type " + context.getClass().getName()); |
81 | |
} |
82 | |
} |