Java Code Examples for javax.servlet.jsp.JspFactory#getDefaultFactory()

The following examples show how to use javax.servlet.jsp.JspFactory#getDefaultFactory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSPEngineWrapper.java    From ontopia with Apache License 2.0 7 votes vote down vote up
private static WrapperIF getWrapper() {
  if (wrapper != null)
    return wrapper;

  if (JspFactory.getDefaultFactory() == null)
    // ontojsp can't set the default factory, since ontojsp needs to
    // be able to run inside app servers, which will set the default.
    // in the test suite there will therefore be no default factory.
    return new JSP12Wrapper(); 

  JspEngineInfo engine = JspFactory.getDefaultFactory().getEngineInfo();
  String version = engine.getSpecificationVersion();
  switch (version) {
    case "2.0": return new JSP20Wrapper();
    case "1.2": return new JSP12Wrapper();
    default: return new JSP11Wrapper();
  }
}
 
Example 2
Source File: JspContextWrapper.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public ELContext getELContext() {
    if (elContext == null) {
        elContext = new ELContextWrapper(rootJspCtxt.getELContext(), jspTag, this);
        JspFactory factory = JspFactory.getDefaultFactory();
        JspApplicationContext jspAppCtxt = factory.getJspApplicationContext(servletContext);
        if (jspAppCtxt instanceof JspApplicationContextImpl) {
            ((JspApplicationContextImpl) jspAppCtxt).fireListeners(elContext);
        }
    }
    return elContext;
}
 
Example 3
Source File: JasperInitializer.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Initialize Jasper.
 *
 * @param classes the classes.
 * @param servletContext the Servlet context.
 * @throws ServletException when a Servlet error occurs.
 */
@Override
public void onStartup(Set<Class<?>> classes, ServletContext servletContext)
        throws ServletException {
    LOGGER.fine("Initializing Jasper integration");
    
    if (JspFactory.getDefaultFactory() == null) {
        JspFactory.setDefaultFactory(new JspFactoryImpl());
    }
    ServletRegistration.Dynamic registration = servletContext.addServlet(
            "JSP Servlet", "org.apache.jasper.servlet.JspServlet");
    registration.addMapping("*.jsp");
    String classpath = System.getProperty("java.class.path")
            + getClassesDirectory(servletContext)
            + getJarFiles(servletContext);
    
    if (LOGGER.isLoggable(Level.FINER)) {
        LOGGER.log(Level.FINER, "Jasper classpath is: {0}", classpath);
    }
    
    registration.setInitParameter("classpath", classpath);
    registration.setInitParameter("compilerSourceVM", "1.8");
    registration.setInitParameter("compilerTargetVM", "1.8");
    WebApplication webApplication = (WebApplication) servletContext;
    webApplication.setJspManager(new JasperJspManager());
    LOGGER.fine("Initialized Jasper integration");
}
 
Example 4
Source File: ViewerPlugin.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void setupJspFactory() {

		try {
			if (JspFactory.getDefaultFactory() == null) {
				// enforce setting the jspfactory instance as we know it here
				Class clz = Class.forName("org.apache.jasper.runtime.JspFactoryImpl"); //$NON-NLS-1$
				if (clz != null) {
					JspFactory.setDefaultFactory((JspFactory) clz.newInstance());
				}
			}
		} catch (Exception ex) {

		}
	}
 
Example 5
Source File: OpenEJBLifecycle.java    From tomee with Apache License 2.0 5 votes vote down vote up
/**
 * On Tomcat we need to sometimes force a class load to get our hands on the JspFactory
 */
private static void setJspELFactory(ServletContext startupObject, ELResolver resolver)
{
    JspFactory factory = JspFactory.getDefaultFactory();
    if (factory == null)
    {
        try
        {
            try {
                Class.forName("org.apache.jasper.servlet.JasperInitializer");
            } catch (final Throwable th) {
                Class.forName("org.apache.jasper.compiler.JspRuntimeContext");
            }
            factory = JspFactory.getDefaultFactory();
        }
        catch (Exception e)
        {
            // ignore
        }

    }

    if (factory != null)
    {
        JspApplicationContext applicationCtx = factory.getJspApplicationContext(startupObject);
        applicationCtx.addELResolver(resolver);
    }
    else
    {
        logger.debug("Default JSPFactroy instance has not found. Skipping OWB JSP handling");
    }
}