Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2008 Sonatype, Inc. All rights reserved. This program is licensed to you under the Apache License Version 2.0, and you may not use this file except in compliance with the Apache License Version 2.0. You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the Apache License Version 2.0 is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
 
 package org.sonatype.sisu.jetty.custom;
 
 import java.util.List;
 
Listener to disable taglibs on a webapp. There were problems with Jetty6 when it was trying to "reach out" to get the DTDs of it's default taglibs and in isolated environments it caused long pauses on boot.

Author(s):
jdcasey
 
 public class DisableTagLibsListener
     implements LifeCycle.Listener
 {
     public void lifeCycleStartingLifeCycle lifecycle )
     {
         if ( lifecycle instanceof ContextHandlerCollection )
         {
             disableTagLibs( (ContextHandlerCollectionlifecycle );
         }
     }
 
     public void lifeCycleStartedLifeCycle lifecycle )
     {
         // NOP
     }
 
     public void lifeCycleStoppingLifeCycle lifecycle )
     {
         // NOP
     }
 
     public void lifeCycleStoppedLifeCycle lifecycle )
     {
         // NOP
     }
 
     public void lifeCycleFailureLifeCycle lifecycleThrowable cause )
     {
         // NOP
     }
 
     // ==
 
     private void disableTagLibsContextHandlerCollection collection )
     {
         Logger logger = Log.getLoggergetClass().getName() );
 
         Handler[] childHandlers = collection.getChildHandlers();
 
         if ( childHandlers != null && childHandlers.length > 0 )
         {
             for ( Handler child : childHandlers )
             {
                 if ( child instanceof WebAppContext )
                 {
                     WebAppContext webapp = (WebAppContextchild;
 
                     if ( logger != null )
                     {
                         logger.info"Disabling TLD support for WebAppContext on context path: {}"webapp.getContextPath() );
                     }
 
                     Configuration[] configs = webapp.getConfigurations();
                     if ( configs != null )
                     {
                         List<ConfigurationtoSet = new ArrayList<Configuration>();
 
                         for ( int i = 0; i < configs.lengthi++ )
                         {
                             if ( !( configs[iinstanceof TagLibConfiguration ) )
                             {
                                 toSet.addconfigs[i] );
                             }
                         }
 
                         boolean hasDisabledTaglibs = false;
                         for ( Configuration configuration : toSet )
                        {
                            if ( configuration instanceof DisabledTagLibConfiguration )
                            {
                                hasDisabledTaglibs = true;
                                break;
                            }
                        }
                        if ( !hasDisabledTaglibs )
                        {
                            toSet.addnew DisabledTagLibConfiguration() );
                        }
                        webapp.setConfigurationstoSet.toArrayconfigs ) );
                    }
                    else
                    {
                        String[] configClasses = webapp.getConfigurationClasses();
                        if ( configClasses == null )
                        {
                            configClasses = new String[1];
                            configClasses[0] = DisabledTagLibConfiguration.class.getName();
                        }
                        else
                        {
                            List<StringtoSet = new ArrayList<String>();
                            for ( int i = 0; i < configClasses.lengthi++ )
                            {
                                toSet.addconfigClasses[i] );
                            }
                            toSet.removeTagLibConfiguration.class.getName() );
                            if ( !toSet.containsDisabledTagLibConfiguration.class.getName() ) )
                            {
                                toSet.addDisabledTagLibConfiguration.class.getName() );
                            }
                            configClasses = toSet.toArrayconfigClasses );
                        }
                        webapp.setConfigurationClassesconfigClasses );
                    }
                    if ( logger != null && logger.isDebugEnabled() )
                    {
                        StringBuilder builder = new StringBuilder();
                        if ( webapp.getConfigurations() != null )
                        {
                            for ( Configuration configuration : webapp.getConfigurations() )
                            {
                                builder.append"\n" ).appendconfiguration.getClass().getName() );
                            }
                            logger.debug"\n\nThe following configurations are in use for this webapp: {}"builder,
                                null );
                        }
                        builder.setLength( 0 );
                        if ( webapp.getConfigurationClasses() != null )
                        {
                            for ( String configClass : webapp.getConfigurationClasses() )
                            {
                                builder.append"\n" ).appendconfigClass );
                            }
                            logger.debug"\n\nThe following configurationClasses are in use for this webapp: {}",
                                buildernull );
                        }
                    }
                }
            }
        }
    }
    public static class DisabledTagLibConfiguration
        extends TagLibConfiguration
    {
        @Override
        public void preConfigureWebAppContext context )
            throws Exception
        {
            // Disable this from the superclass.
        }
    }
New to GrepCode? Check out our FAQ X