cziegeler    2004/02/09 00:00:48

  Modified:    src/blocks/portal/java/org/apache/cocoon/portal/impl
                        PortletPortalManager.java
  Log:
  Fixing bug 26566: portlet container now checks if it's running in a servlet 
environment
  Please cross-check and close the bug if it works.
  Thanks
  
  Revision  Changes    Path
  1.4       +22 -7     
cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortletPortalManager.java
  
  Index: PortletPortalManager.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortletPortalManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PortletPortalManager.java 6 Feb 2004 13:07:17 -0000       1.3
  +++ PortletPortalManager.java 9 Feb 2004 08:00:48 -0000       1.4
  @@ -116,12 +116,19 @@
        * @see 
org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
        */
       public void contextualize(Context context) throws ContextException {
  -        this.servletConfig = (ServletConfig) 
context.get(CocoonServlet.CONTEXT_SERVLET_CONFIG);
  -        // we have to somehow pass this component down to other components!
  -        // This is ugly, but it's the only chance for sofisticated component 
containers
  -        // that wrap component implementations!
  -        
this.servletConfig.getServletContext().setAttribute(PortalManager.ROLE, this);
           this.context = context;
  +        try {
  +            this.servletConfig = (ServletConfig) 
context.get(CocoonServlet.CONTEXT_SERVLET_CONFIG);
  +            // we have to somehow pass this component down to other 
components!
  +            // This is ugly, but it's the only chance for sofisticated 
component containers
  +            // that wrap component implementations!
  +            
this.servletConfig.getServletContext().setAttribute(PortalManager.ROLE, this);
  +        } catch (ContextException ignore) {
  +            // we ignore the context exception
  +            // this avoids startup errors if the portal is configured for 
the CLI
  +            // environment
  +            this.getLogger().warn("The JSR-168 support is disabled as the 
servlet context is not available.", ignore);
  +        }
       }
   
       /* (non-Javadoc)
  @@ -162,7 +169,9 @@
        * @see org.apache.avalon.framework.activity.Initializable#initialize()
        */
       public void initialize() throws Exception {
  -        this.initContainer();
  +        if ( this.servletConfig != null ) {
  +            this.initContainer();
  +        }
       }
       
       /**
  @@ -217,6 +226,12 @@
       public void process() throws ProcessingException {
           // process the events
           super.process();
  +        
  +        // if we aren't running in a servlet environment, just skip the 
JSR-168 part
  +        if ( this.servletConfig == null ) {
  +            return;
  +        }
  +        
           // do we already have an environment?
           // if not, create one
           final Map objectModel = ContextHelper.getObjectModel(this.context);
  
  
  

Reply via email to