public synchronized static void init(ServletContext servletContext) { JspApplicationContext jac = JspFactory.getDefaultFactory().getJspApplicationContext(servletContext); if (jspApplicationContext != jac) { jspApplicationContext = jac; jspApplicationContext.addELResolver(new ModelRecordElResolver()); } }
@Override public void contextInitialized(final ServletContextEvent sce) { // if the servlet version is 3.1 or higher, setup a ELResolver which allows usage of static fields java.lang.* final ServletContext servletContext = sce.getServletContext(); final JspApplicationContext jspApplicationContext = JspFactory.getDefaultFactory().getJspApplicationContext(servletContext); if (servletContext.getEffectiveMajorVersion() > 3 || (servletContext.getEffectiveMajorVersion() == 3 && servletContext.getEffectiveMinorVersion() >= 1)) { jspApplicationContext.addELResolver(new ImportedClassELResolver()); } // setup a wrapped JspApplicationContext if there are any EL expression factory wrappers for this servlet context final List<ExpressionFactoryWrapper> expressionFactoryWrappers = (List<ExpressionFactoryWrapper>) sce.getServletContext().getAttribute(CONTEXT_KEY); if (expressionFactoryWrappers != null && !expressionFactoryWrappers.isEmpty()) { final JspApplicationContextWrapper jspApplicationContextWrapper = new JspApplicationContextWrapper(JspApplicationContextImpl.getInstance(servletContext), expressionFactoryWrappers, sce.getServletContext()); sce.getServletContext().setAttribute(JspApplicationContextImpl.class.getName(), jspApplicationContextWrapper); } }
@Override public ExpressionFactory wrap(ExpressionFactory expressionFactory, ServletContext servletContext) { BeanManager beanManager = getBeanManager(); if(beanManager == null) { //this should never happen return expressionFactory; } // get JspApplicationContext. JspApplicationContext jspAppContext = JspFactory.getDefaultFactory().getJspApplicationContext( servletContext); // register compositeELResolver with JSP jspAppContext.addELResolver(beanManager.getELResolver()); jspAppContext.addELContextListener(Reflections.<ELContextListener>newInstance("org.jboss.weld.module.web.el.WeldELContextListener", getClass().getClassLoader())); return beanManager.wrapExpressionFactory(expressionFactory); }
@WebListener public class Config implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent event) { ServletContext servletContext = event.getServletContext(); JspApplicationContext jspContext = JspFactory.getDefaultFactory().getJspApplicationContext(servletContext); jspContext.addELResolver(new YourELResolver()); } // ... }
@Configuration ... public class SpringConfig extends WebMvcConfigurationSupport { ... @Override public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { ... // add our default method resolver to our ELResolver list. JspApplicationContext jspContext = JspFactory.getDefaultFactory().getJspApplicationContext(getServletContext()); jspContext.addELResolver(new DefaultMethodELResolver(getApplicationContext())); } }
public void contextInitialized(ServletContextEvent event) { // APF-1379: Prevent NPE when using Tomcat Maven Plugin try { Class.forName("org.apache.jasper.compiler.JspRuntimeContext"); } catch (ClassNotFoundException cnfe) { // ignore } JspFactory.getDefaultFactory() .getJspApplicationContext(event.getServletContext()) .addELResolver(new EscapeXmlELResolver()); }
@Override public void contextInitialized(final ServletContextEvent sce) { // if the servlet version is 3.1 or higher, setup a ELResolver which allows usage of static fields java.lang.* final ServletContext servletContext = sce.getServletContext(); final JspApplicationContext jspApplicationContext = JspFactory.getDefaultFactory().getJspApplicationContext(servletContext); if (servletContext.getEffectiveMajorVersion() > 3 || (servletContext.getEffectiveMajorVersion() == 3 && servletContext.getEffectiveMinorVersion() >= 1)) { jspApplicationContext.addELResolver(new ImportedClassELResolver()); } // setup a wrapped JspApplicationContext if there are any EL expression factory wrappers for this servlet context final List<ExpressionFactoryWrapper> expressionFactoryWrappers = (List<ExpressionFactoryWrapper>) sce.getServletContext().getAttribute(CONTEXT_KEY); if (expressionFactoryWrappers != null && !expressionFactoryWrappers.isEmpty()) { final JspApplicationContextWrapper jspApplicationContextWrapper = new JspApplicationContextWrapper(JspApplicationContextImpl.getInstance(servletContext), expressionFactoryWrappers, sce.getServletContext()); sce.getServletContext().setAttribute(JspApplicationContextImpl.class.getName(), jspApplicationContextWrapper); } }
public synchronized static void init(ServletContext servletContext) { JspApplicationContext jac = JspFactory.getDefaultFactory().getJspApplicationContext(servletContext); if (jspApplicationContext != jac) { jspApplicationContext = jac; jspApplicationContext.addELResolver(new ModelRecordElResolver()); } }
@Override public void contextInitialized(final ServletContextEvent sce) { // if the servlet version is 3.1 or higher, setup a ELResolver which allows usage of static fields java.lang.* final ServletContext servletContext = sce.getServletContext(); final JspApplicationContext jspApplicationContext = JspFactory.getDefaultFactory().getJspApplicationContext(servletContext); if (servletContext.getEffectiveMajorVersion() > 3 || (servletContext.getEffectiveMajorVersion() == 3 && servletContext.getEffectiveMinorVersion() >= 1)) { jspApplicationContext.addELResolver(new ImportedClassELResolver()); } // setup a wrapped JspApplicationContext if there are any EL expression factory wrappers for this servlet context final List<ExpressionFactoryWrapper> expressionFactoryWrappers = (List<ExpressionFactoryWrapper>) sce.getServletContext().getAttribute(CONTEXT_KEY); if (expressionFactoryWrappers != null && !expressionFactoryWrappers.isEmpty()) { final JspApplicationContextWrapper jspApplicationContextWrapper = new JspApplicationContextWrapper(JspApplicationContextImpl.getInstance(servletContext), expressionFactoryWrappers, sce.getServletContext()); sce.getServletContext().setAttribute(JspApplicationContextImpl.class.getName(), jspApplicationContextWrapper); } }
public synchronized static void init(ServletContext servletContext) { JspApplicationContext jac = JspFactory.getDefaultFactory().getJspApplicationContext(servletContext); if (jspApplicationContext != jac) { jspApplicationContext = jac; jspApplicationContext.addELResolver(new ModelRecordElResolver()); } }
/** * {@inheritDoc} */ public void start(ModuleLifecycleContext moduleLifecycleContext) { try { JspFactory.getDefaultFactory().getJspApplicationContext(servletContext).addELResolver(new NodeElResolver()); log.info("EL resolver for javax.jcr.Node added"); if (freemarkerConfig != null) { Map<String, TemplateModel> sharedVariables = freemarkerConfig.getSharedVariables(); Map<String, Object> plainBeans = new HashMap<String, Object>(); for (Map.Entry<String, TemplateModel> var : sharedVariables.entrySet()) { plainBeans.put(var.getKey(), ((BeanModel) var.getValue()).getWrappedObject()); } // getWrappedObject JspFactory .getDefaultFactory() .getJspApplicationContext(servletContext) .addELResolver(new BenExposingELResolver(plainBeans)); } } catch (IllegalStateException e) { // ignore, this means the module have been reloaded, but the webapp is already initialized } }
applicationCtx.addELResolver(resolver);
/** * Stash the Weld EL Resolver and Weld EL Context Listener so it is recognized by JSP. */ public void contextInitialized(ServletContextEvent servletContextEvent) { if (null != beanManager) { JspApplicationContext jspAppContext = getJspApplicationContext(servletContextEvent); jspAppContext.addELResolver(beanManager.getELResolver()); try { Class weldClass = Class.forName("org.jboss.weld.module.web.el.WeldELContextListener"); WeldELContextListener welcl = ( WeldELContextListener ) weldClass.newInstance(); jspAppContext.addELContextListener(welcl); } catch (Exception e) { logger.log(Level.WARNING, CDILoggerInfo.CDI_COULD_NOT_CREATE_WELDELCONTEXTlISTENER, new Object [] {e}); } ( ( JspApplicationContextImpl ) jspAppContext ).setExpressionFactory( beanManager.wrapExpressionFactory(jspAppContext.getExpressionFactory())); } }
/** * Register a phase listener to every lifecycle. This listener will lazy fill the el resolver for jsp as soon as the * first lifecycle is executed. This is necessarry to allow a faces application further setup after MyFaces has been * initialized. When the first request is processed no further configuation of the el resolvers is allowed. * * @param appCtx * @param runtimeConfig */ private void configureResolverForJSP(JspApplicationContext appCtx, RuntimeConfig runtimeConfig) { FacesCompositeELResolver facesCompositeELResolver = new FacesCompositeELResolver(Scope.JSP); appCtx.addELResolver(facesCompositeELResolver); PhaseListener resolverForJSPInitializer = new ResolverForJSPInitializer( createResolverBuilderForJSP(runtimeConfig), facesCompositeELResolver); LifecycleFactory factory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); for (Iterator<String> iter = factory.getLifecycleIds(); iter.hasNext();) { factory.getLifecycle(iter.next()).addPhaseListener(resolverForJSPInitializer); } }
/** * Register a phase listener to every lifecycle. This listener will lazy fill the el resolver for jsp as soon as the * first lifecycle is executed. This is necessarry to allow a faces application further setup after MyFaces has been * initialized. When the first request is processed no further configuation of the el resolvers is allowed. * * @param appCtx * @param runtimeConfig */ private void configureResolverForJSP(JspApplicationContext appCtx, RuntimeConfig runtimeConfig) { FacesCompositeELResolver facesCompositeELResolver = new FacesCompositeELResolver(Scope.JSP); appCtx.addELResolver(facesCompositeELResolver); PhaseListener resolverForJSPInitializer = new ResolverForJSPInitializer( createResolverBuilderForJSP(runtimeConfig), facesCompositeELResolver); LifecycleFactory factory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); for (Iterator<String> iter = factory.getLifecycleIds(); iter.hasNext();) { factory.getLifecycle(iter.next()).addPhaseListener(resolverForJSPInitializer); } }
/** * Register a phase listener to every lifecycle. This listener will lazy fill the el resolver for jsp as soon as the * first lifecycle is executed. This is necessarry to allow a faces application further setup after MyFaces has been * initialized. When the first request is processed no further configuation of the el resolvers is allowed. * * @param appCtx * @param runtimeConfig */ private void configureResolverForJSP(JspApplicationContext appCtx, RuntimeConfig runtimeConfig) { FacesCompositeELResolver facesCompositeELResolver = new FacesCompositeELResolver(Scope.JSP); appCtx.addELResolver(facesCompositeELResolver); PhaseListener resolverForJSPInitializer = new ResolverForJSPInitializer( createResolverBuilderForJSP(runtimeConfig), facesCompositeELResolver); LifecycleFactory factory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); for (Iterator<String> iter = factory.getLifecycleIds(); iter.hasNext();) { factory.getLifecycle(iter.next()).addPhaseListener(resolverForJSPInitializer); } }
/** * Register a phase listener to every lifecycle. This listener will lazy fill the el resolver for jsp as soon as the * first lifecycle is executed. This is necessarry to allow a faces application further setup after MyFaces has been * initialized. When the first request is processed no further configuation of the el resolvers is allowed. * * @param appCtx * @param runtimeConfig */ private void configureResolverForJSP(JspApplicationContext appCtx, RuntimeConfig runtimeConfig) { FacesCompositeELResolver facesCompositeELResolver = new FacesCompositeELResolver(Scope.JSP); appCtx.addELResolver(facesCompositeELResolver); PhaseListener resolverForJSPInitializer = new ResolverForJSPInitializer( createResolverBuilderForJSP(runtimeConfig), facesCompositeELResolver); LifecycleFactory factory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); for (Iterator<String> iter = factory.getLifecycleIds(); iter.hasNext();) { factory.getLifecycle(iter.next()).addPhaseListener(resolverForJSPInitializer); } }
@Override public void requestInitialized(ServletRequestEvent sre) { if (!installed && beanManager!= null && JspFactory.getDefaultFactory() != null) { synchronized (this) { if (!installed) { installed = true; // get JspApplicationContext. JspApplicationContext jspAppContext = JspFactory.getDefaultFactory().getJspApplicationContext( sre.getServletContext()); // register compositeELResolver with JSP jspAppContext.addELResolver(beanManager.getELResolver()); jspAppContext.addELContextListener(Reflections.<ELContextListener> newInstance( "org.jboss.weld.el.WeldELContextListener", getClass().getClassLoader())); // Hack into JBoss Web/Catalina to replace the ExpressionFactory JspApplicationContextImpl wrappedJspApplicationContextImpl = new WeldJspApplicationContextImpl( JspApplicationContextImpl.getInstance(sre.getServletContext()), beanManager .wrapExpressionFactory(jspAppContext.getExpressionFactory())); sre.getServletContext().setAttribute(JspApplicationContextImpl.class.getName(), wrappedJspApplicationContextImpl); } } } // otherwise something went wrong starting Weld, so don't register with JSP }
/** * {@inheritDoc} * <p> * {@link S2BeanELResolver} を {@link JspApplicationContext} に登録します。 * </p> */ @Override public void ready() { final JspFactory jspFactory = JspFactory.getDefaultFactory(); if (jspFactory != null) { final JspApplicationContext jspApplicationContext = jspFactory .getJspApplicationContext(servletContext); final S2Container container = SingletonS2ContainerFactory .getContainer(); final ELResolver[] elResolvers = (ELResolver[]) container .findAllComponents(ELResolver.class); for (final ELResolver elResolver : elResolvers) { jspApplicationContext.addELResolver(elResolver); logger.log("ICUB0001", new Object[] { elResolver }); } } }
private HttpJspBase loadJsp(String forwardedUrl, File compilationDir) throws MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException, ServletException { String jspClassName = toJspClassName(forwardedUrl); URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { compilationDir.toURI().toURL() }); Class<?> cls = Class.forName(jspClassName, true, classLoader); HttpJspBase instance = (HttpJspBase) cls.newInstance(); MockServletConfig servletConfig = new MockServletConfig(new MockServletContext()); servletConfig.getServletContext().setAttribute(InstanceManager.class.getName(), new InstanceManagerImplementation()); JspApplicationContext jspApplicationContext = JspFactory.getDefaultFactory().getJspApplicationContext( servletConfig.getServletContext()); // Register the ELResolver with JSP jspApplicationContext.addELResolver(manager.getELResolver()); // Register ELContextListener with JSP jspApplicationContext.addELContextListener(Reflections .<ELContextListener> newInstance("org.jboss.weld.el.WeldELContextListener")); // Push the wrapped expression factory into the servlet context so that // Tomcat or Jetty can hook it in using a container code servletConfig.getServletContext().setAttribute(EXPRESSION_FACTORY_NAME, manager.wrapExpressionFactory(jspApplicationContext.getExpressionFactory())); instance.init(servletConfig); JspFactory.setDefaultFactory(new org.apache.jasper.runtime.JspFactoryImpl()); instance._jspInit(); return instance; }