public static void registerServlets( PluginManager manager, final Plugin plugin, File webXML)
    {
        pluginManager = manager;

        if ( !webXML.exists() )
        {
            Log.error("Could not register plugin servlets, file " + webXML.getAbsolutePath() + " does not exist.");
            return;
        }

        // Find the name of the plugin directory given that the webXML file lives in plugins/[pluginName]/web/web.xml
        final String pluginName = webXML.getParentFile().getParentFile().getParentFile().getName();
        try
        {
            final Document webXmlDoc = WebXmlUtils.asDocument( webXML );

            final List<String> servletNames = WebXmlUtils.getServletNames( webXmlDoc );
            for ( final String servletName : servletNames )
            {
                Log.debug( "Loading servlet '{}' of plugin '{}'...", servletName, pluginName );

                final String className = WebXmlUtils.getServletClassName( webXmlDoc, servletName );
                if ( className == null || className.isEmpty() )
                {
                    Log.warn( "Could not load servlet '{}' of plugin '{}'. web-xml does not define a class name for this servlet.", servletName, pluginName );
                    continue;
                }

                try {
                    final Class<?> theClass = manager.loadClass(plugin, className);

                    final Object instance = theClass.newInstance();
                    if (!(instance instanceof GenericServlet)) {
                        Log.warn("Could not load servlet '{}' of plugin '{}'. Its class ({}) is not an instance of javax.servlet.GenericServlet.", servletName, pluginName, className);
                        continue;
                    }

                    Log.debug("Initializing servlet '{}' of plugin '{}'...", servletName, pluginName);
                    ((GenericServlet) instance).init(new ServletConfig() {
                        @Override
                        public String getServletName() {
                            return servletName;
                        }

                        @Override
                        public ServletContext getServletContext() {
                            return new PluginServletContext( servletConfig.getServletContext(), pluginManager, plugin );
                        }

                        @Override
                        public String getInitParameter( String s )
                        {
                            final Map<String, String> params = WebXmlUtils.getServletInitParams( webXmlDoc, servletName );
                            if (params.isEmpty()) {
                                return null;
                            }
                            return params.get( s );
                        }

                        @Override
                        public Enumeration<String> getInitParameterNames()
                        {
                            final Map<String, String> params = WebXmlUtils.getServletInitParams( webXmlDoc, servletName );
                            if (params.isEmpty()) {
                                return Collections.emptyEnumeration();
                            }
                            return Collections.enumeration( params.keySet() );
                        }
                    });

                    Log.debug("Registering servlet '{}' of plugin '{}' URL patterns.", servletName, pluginName);
                    final Set<String> urlPatterns = WebXmlUtils.getServletUrlPatterns(webXmlDoc, servletName);
                    for (final String urlPattern : urlPatterns) {
                        final String path = (pluginName + urlPattern).toLowerCase();
                        servlets.put(path, (GenericServlet) instance);
                        Log.debug("Servlet '{}' registered on path: {}", servletName, path);
                    }
                    Log.debug("Servlet '{}' of plugin '{}' loaded successfully.", servletName, pluginName);
                } catch (final Exception e) {
                    Log.warn("Exception attempting to load servlet '{}' ({}) of plugin '{}'", servletName, className, pluginName, e);
                }
            }


            final List<String> filterNames = WebXmlUtils.getFilterNames( webXmlDoc );
            for ( final String filterName : filterNames )
            {
                Log.debug( "Loading filter '{}' of plugin '{}'...", filterName, pluginName );
                final String className = WebXmlUtils.getFilterClassName( webXmlDoc, filterName );
                if ( className == null || className.isEmpty() )
                {
                    Log.warn( "Could not load filter '{}' of plugin '{}'. web-xml does not define a class name for this filter.", filterName, pluginName );
                    continue;
                }
                final Class<?> theClass = manager.loadClass( plugin, className );

                final Object instance = theClass.newInstance();
                if ( !(instance instanceof Filter) )
                {
                    Log.warn( "Could not load filter '{}' of plugin '{}'. Its class ({}) is not an instance of javax.servlet.Filter.", filterName, pluginName, className );
                    continue;
                }

                Log.debug( "Initializing filter '{}' of plugin '{}'...", filterName, pluginName );
                ( (Filter) instance ).init( new FilterConfig()
                {
                    @Override
                    public String getFilterName()
                    {
                        return filterName;
                    }

                    @Override
                    public ServletContext getServletContext()
                    {
                        return new PluginServletContext( servletConfig.getServletContext(), pluginManager, plugin );
                    }

                    @Override
                    public String getInitParameter( String s )
                    {
                        final Map<String, String> params = WebXmlUtils.getFilterInitParams( webXmlDoc, filterName );
                        if (params.isEmpty()) {
                            return null;
                        }
                        return params.get( s );
                    }

                    @Override
                    public Enumeration<String> getInitParameterNames()
                    {
                        final Map<String, String> params = WebXmlUtils.getFilterInitParams( webXmlDoc, filterName );
                        if (params.isEmpty()) {
                            return Collections.emptyEnumeration();
                        }
                        return Collections.enumeration( params.keySet() );
                    }
                } );

                Log.debug( "Registering filter '{}' of plugin '{}' URL patterns.", filterName, pluginName );
                final Set<String> urlPatterns = WebXmlUtils.getFilterUrlPatterns( webXmlDoc, filterName );
                for ( final String urlPattern : urlPatterns )
                {
                    PluginFilter.addPluginFilter( urlPattern, ( (Filter) instance ) );
                }
                Log.debug( "Filter '{}' of plugin '{}' loaded successfully.", filterName, pluginName );
            }
        }
        catch (Throwable e)
        {
            Log.error( "An unexpected problem occurred while attempting to register servlets for plugin '{}'.", plugin, e);
        }
    }
Registers all JSP page servlets for a plugin.

@param manager the plugin manager.
@param plugin the plugin.
@param webXML the web.xml file containing JSP page names to servlet class file
     mappings.
xmppserver/src/main/java/org/jivesoftware/openfire/container/PluginServlet.java