1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.webapp; |
20 | |
|
21 | |
import java.util.Iterator; |
22 | |
|
23 | |
import javax.el.ExpressionFactory; |
24 | |
import javax.faces.FactoryFinder; |
25 | |
import javax.faces.context.ExternalContext; |
26 | |
import javax.faces.event.PhaseListener; |
27 | |
import javax.faces.lifecycle.LifecycleFactory; |
28 | |
import javax.servlet.ServletContext; |
29 | |
import javax.servlet.jsp.JspApplicationContext; |
30 | |
import javax.servlet.jsp.JspFactory; |
31 | |
|
32 | |
import org.apache.commons.logging.Log; |
33 | |
import org.apache.commons.logging.LogFactory; |
34 | |
import org.apache.myfaces.config.RuntimeConfig; |
35 | |
import org.apache.myfaces.el.ResolverForJSPInitializer; |
36 | |
import org.apache.myfaces.el.unified.ELResolverBuilder; |
37 | |
import org.apache.myfaces.el.unified.ResolverBuilderForJSP; |
38 | |
import org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver; |
39 | |
import org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.Scope; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 0 | public class Jsp21FacesInitializer extends AbstractFacesInitializer |
46 | |
{ |
47 | |
|
48 | |
|
49 | |
|
50 | 0 | private static final Log log = LogFactory.getLog(Jsp21FacesInitializer.class); |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
private JspFactory jspFactory; |
56 | |
|
57 | |
@Override |
58 | |
protected void initContainerIntegration( |
59 | |
ServletContext servletContext, ExternalContext externalContext) |
60 | |
{ |
61 | 0 | JspApplicationContext appCtx = |
62 | |
getJspFactory().getJspApplicationContext(servletContext); |
63 | 0 | appCtx.addELContextListener(new FacesELContextListener()); |
64 | |
|
65 | |
|
66 | 0 | ExpressionFactory expressionFactory = getUserDefinedExpressionFactory(externalContext); |
67 | 0 | if (expressionFactory == null) |
68 | |
{ |
69 | 0 | expressionFactory = appCtx.getExpressionFactory(); |
70 | |
} |
71 | |
|
72 | 0 | RuntimeConfig runtimeConfig = |
73 | |
buildConfiguration(servletContext, externalContext, expressionFactory); |
74 | |
|
75 | |
|
76 | 0 | configureResolverForJSP(appCtx, runtimeConfig); |
77 | 0 | } |
78 | |
|
79 | |
protected JspFactory getJspFactory() |
80 | |
{ |
81 | 0 | if (jspFactory == null) { |
82 | |
|
83 | |
|
84 | |
try { |
85 | 0 | Class.forName("org.apache.jasper.compiler.JspRuntimeContext"); |
86 | 0 | } catch (ClassNotFoundException e) { |
87 | |
; |
88 | 0 | } catch (Exception ex) { |
89 | 0 | log.debug("An unexpected exception occured " |
90 | |
+ "while loading the JspRuntimeContext.", ex); |
91 | 0 | } |
92 | |
|
93 | 0 | jspFactory = JspFactory.getDefaultFactory(); |
94 | |
} |
95 | |
|
96 | 0 | return jspFactory; |
97 | |
} |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
protected void setJspFactory(JspFactory jspFactory) |
107 | |
{ |
108 | 0 | this.jspFactory = jspFactory; |
109 | 0 | } |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
private void configureResolverForJSP(JspApplicationContext appCtx, RuntimeConfig runtimeConfig) |
120 | |
{ |
121 | 0 | FacesCompositeELResolver facesCompositeELResolver = new FacesCompositeELResolver(Scope.JSP); |
122 | 0 | appCtx.addELResolver(facesCompositeELResolver); |
123 | 0 | PhaseListener resolverForJSPInitializer = new ResolverForJSPInitializer( |
124 | |
createResolverBuilderForJSP(runtimeConfig), facesCompositeELResolver); |
125 | |
|
126 | 0 | LifecycleFactory factory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); |
127 | 0 | for (Iterator<String> iter = factory.getLifecycleIds(); iter.hasNext();) |
128 | |
{ |
129 | 0 | factory.getLifecycle(iter.next()).addPhaseListener(resolverForJSPInitializer); |
130 | |
} |
131 | 0 | } |
132 | |
|
133 | |
protected ELResolverBuilder createResolverBuilderForJSP(RuntimeConfig runtimeConfig) |
134 | |
{ |
135 | 0 | return new ResolverBuilderForJSP(runtimeConfig); |
136 | |
} |
137 | |
} |