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 | |
import java.util.logging.Level; |
23 | |
import java.util.logging.Logger; |
24 | |
|
25 | |
import javax.el.ExpressionFactory; |
26 | |
import javax.faces.FactoryFinder; |
27 | |
import javax.faces.context.ExternalContext; |
28 | |
import javax.faces.event.PhaseListener; |
29 | |
import javax.faces.lifecycle.LifecycleFactory; |
30 | |
import javax.servlet.ServletContext; |
31 | |
import javax.servlet.jsp.JspApplicationContext; |
32 | |
import javax.servlet.jsp.JspFactory; |
33 | |
|
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 | |
|
51 | 0 | private static final Logger log = Logger.getLogger(Jsp21FacesInitializer.class.getName()); |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
private JspFactory jspFactory; |
57 | |
|
58 | |
@Override |
59 | |
protected void initContainerIntegration( |
60 | |
ServletContext servletContext, ExternalContext externalContext) |
61 | |
{ |
62 | 0 | JspApplicationContext appCtx = |
63 | |
getJspFactory().getJspApplicationContext(servletContext); |
64 | 0 | appCtx.addELContextListener(new FacesELContextListener()); |
65 | |
|
66 | |
|
67 | 0 | ExpressionFactory expressionFactory = getUserDefinedExpressionFactory(externalContext); |
68 | 0 | if (expressionFactory == null) |
69 | |
{ |
70 | 0 | expressionFactory = appCtx.getExpressionFactory(); |
71 | |
} |
72 | |
|
73 | 0 | RuntimeConfig runtimeConfig = |
74 | |
buildConfiguration(servletContext, externalContext, expressionFactory); |
75 | |
|
76 | |
|
77 | 0 | configureResolverForJSP(appCtx, runtimeConfig); |
78 | 0 | } |
79 | |
|
80 | |
protected JspFactory getJspFactory() |
81 | |
{ |
82 | 0 | if (jspFactory == null) |
83 | |
{ |
84 | |
|
85 | |
|
86 | |
try |
87 | |
{ |
88 | 0 | Class.forName("org.apache.jasper.compiler.JspRuntimeContext"); |
89 | |
} |
90 | 0 | catch (ClassNotFoundException e) |
91 | |
{ |
92 | |
|
93 | |
} |
94 | 0 | catch (Exception ex) |
95 | |
{ |
96 | 0 | log.log(Level.FINE, "An unexpected exception occured " |
97 | |
+ "while loading the JspRuntimeContext.", ex); |
98 | 0 | } |
99 | |
|
100 | 0 | jspFactory = JspFactory.getDefaultFactory(); |
101 | |
} |
102 | |
|
103 | 0 | return jspFactory; |
104 | |
} |
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
protected void setJspFactory(JspFactory jspFactory) |
114 | |
{ |
115 | 0 | this.jspFactory = jspFactory; |
116 | 0 | } |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
private void configureResolverForJSP(JspApplicationContext appCtx, RuntimeConfig runtimeConfig) |
127 | |
{ |
128 | 0 | FacesCompositeELResolver facesCompositeELResolver = new FacesCompositeELResolver(Scope.JSP); |
129 | 0 | appCtx.addELResolver(facesCompositeELResolver); |
130 | 0 | PhaseListener resolverForJSPInitializer = new ResolverForJSPInitializer( |
131 | |
createResolverBuilderForJSP(runtimeConfig), facesCompositeELResolver); |
132 | |
|
133 | 0 | LifecycleFactory factory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); |
134 | 0 | for (Iterator<String> iter = factory.getLifecycleIds(); iter.hasNext();) |
135 | |
{ |
136 | 0 | factory.getLifecycle(iter.next()).addPhaseListener(resolverForJSPInitializer); |
137 | |
} |
138 | 0 | } |
139 | |
|
140 | |
protected ELResolverBuilder createResolverBuilderForJSP(RuntimeConfig runtimeConfig) |
141 | |
{ |
142 | 0 | return new ResolverBuilderForJSP(runtimeConfig); |
143 | |
} |
144 | |
} |