bug #299733 tweak to support JSF taglibs. ability to register additional tag-libs directly in jetty

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1215 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Hugues Malphettes 2010-01-26 09:38:55 +00:00
parent 007638800b
commit 2e5bc754e4
3 changed files with 56 additions and 23 deletions

View File

@ -19,11 +19,13 @@ import java.util.ArrayList;
import javax.servlet.Servlet;
import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.JspFactory;
import org.apache.jasper.Constants;
import org.apache.jasper.compiler.Localizer;
import org.apache.jasper.compiler.TldLocationsCache;
import org.apache.jasper.xmlparser.ParserUtils;
import org.eclipse.jetty.osgi.boot.JettyBootstrapActivator;
import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelper;
import org.eclipse.jetty.osgi.boot.utils.WebappRegistrationCustomizer;
import org.osgi.framework.Bundle;
@ -41,15 +43,37 @@ public class WebappRegistrationCustomizerImpl implements WebappRegistrationCusto
public WebappRegistrationCustomizerImpl()
{
fixupDtdResolution();
//sanity check:
try
{
//sanity check:
Class cl = getClass().getClassLoader().loadClass("org.apache.jasper.servlet.JspServlet");
//System.err.println("found the jsp servlet: " + cl.getName());
}
catch (ClassNotFoundException e)
catch (Exception e)
{
System.err.println("Unable to locate the JspServlet: jsp support unavailable.");
System.err.println("Unable to locate the JspServlet: jsp support unavailable.");
e.printStackTrace();
return;
}
try
{
//bug #299733
JspFactory fact = JspFactory.getDefaultFactory();
if (fact == null)
{ //bug #299733
//JspFactory does a simple Class.getForName("org.apache.jasper.runtime.JspFactoryImpl")
//however its bundles does not import the jasper package
//so it fails. let's help things out:
fact = (JspFactory)JettyBootstrapActivator.class.getClassLoader()
.loadClass("org.apache.jasper.runtime.JspFactoryImpl").newInstance();
JspFactory.setDefaultFactory(fact);
}
}
catch (Exception e)
{
System.err.println("Unable to set the JspFactory: jsp support incomplete.");
e.printStackTrace();
}
}

View File

@ -10,8 +10,10 @@
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.osgi.boot.jasper;
package org.eclipse.jetty.osgi.boot.jsp;
import org.eclipse.jetty.osgi.boot.internal.webapp.WebappRegistrationHelper;
import org.eclipse.jetty.osgi.boot.jasper.WebappRegistrationCustomizerImpl;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@ -20,6 +22,12 @@ import org.osgi.framework.BundleContext;
* Called by the main org.eclipse.jetty.osgi.boot bundle.
* Please note: this is not a real BundleActivator. Simply something called back by
* the host bundle.
* <p>
* It must be placed in the org.eclipse.jetty.osgi.boot.jsp package:
* this is because org.eclipse.jetty.osgi.boot.jsp is the sympbolic-name
* of this fragment. From that name, the PackageadminTracker will call
* this class. IN a different package it won't be called.
* </p>
*/
public class FragmentActivator implements BundleActivator
{
@ -27,7 +35,7 @@ public class FragmentActivator implements BundleActivator
*
*/
public void start(BundleContext context) throws Exception {
System.err.println("hello from jasper boot fragment");
WebappRegistrationHelper.JSP_REGISTRATION_HELPERS.add(new WebappRegistrationCustomizerImpl());
}
/**

View File

@ -23,9 +23,12 @@ import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
@ -77,7 +80,7 @@ import org.xml.sax.SAXParseException;
* <li>support for jarred webapps is somewhat limited.</li>
* </ul>
*/
class WebappRegistrationHelper
public class WebappRegistrationHelper
{
private static Logger __logger = Log.getLogger(WebappRegistrationHelper.class.getName());
@ -101,8 +104,12 @@ class WebappRegistrationHelper
* By default set to: {@link DefaultBundleClassLoaderHelper}. It supports
* equinox and apache-felix fragment bundles that are specific to an OSGi
* implementation should set a different implementation.
* <p>
* Several of those objects can be added here: For example we could have an optional fragment that setups
* a specific implementation of JSF for the whole of jetty-osgi.
* </p>
*/
public static WebappRegistrationCustomizer JSP_REGISTRATION_HELPER = null;
public static Collection<WebappRegistrationCustomizer> JSP_REGISTRATION_HELPERS = new ArrayList<WebappRegistrationCustomizer>();
private Server _server;
private ContextHandlerCollection _ctxtHandler;
@ -137,17 +144,6 @@ class WebappRegistrationHelper
if (!INITIALIZED)
{
INITIALIZED = true;
// setup the custom WebappRegistrationCustomizer
try
{
Class<?> cl = Class.forName(WebappRegistrationCustomizer.CLASS_NAME);
JSP_REGISTRATION_HELPER = (WebappRegistrationCustomizer)cl.newInstance();
}
catch (Throwable t)
{
// System.err.println("no jsp/jasper support");
// System.exit(1);
}
// setup the custom BundleClassLoaderHelper
try
{
@ -771,15 +767,20 @@ class WebappRegistrationHelper
*/
private URL[] getJarsWithTlds() throws Exception
{
if (JSP_REGISTRATION_HELPER != null)
ArrayList<URL> res = new ArrayList<URL>();
for (WebappRegistrationCustomizer regCustomizer : JSP_REGISTRATION_HELPERS)
{
return JSP_REGISTRATION_HELPER.getJarsWithTlds(BUNDLE_FILE_LOCATOR_HELPER);
URL[] urls = regCustomizer.getJarsWithTlds(BUNDLE_FILE_LOCATOR_HELPER);
for (URL url : urls)
{
if (!res.contains(url))
res.add(url);
}
}
if (!res.isEmpty())
return res.toArray(new URL[res.size()]);
else
{
return null;
}
}
/**