Coverage report

  %line %branch
org.apache.jetspeed.engine.JetspeedEngine
0% 
0% 

 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  * 
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.jetspeed.engine;
 18  
 
 19  
 import java.text.DateFormat;
 20  
 import java.util.Date;
 21  
 import java.util.Map;
 22  
 
 23  
 import javax.servlet.ServletConfig;
 24  
 
 25  
 import org.apache.commons.configuration.Configuration;
 26  
 import org.apache.commons.logging.Log;
 27  
 import org.apache.commons.logging.LogFactory;
 28  
 import org.apache.jetspeed.JetspeedPortalContext;
 29  
 import org.apache.jetspeed.PortalContext;
 30  
 import org.apache.jetspeed.PortalReservedParameters;
 31  
 import org.apache.jetspeed.administration.PortalConfiguration;
 32  
 import org.apache.jetspeed.administration.PortalConfigurationImpl;
 33  
 import org.apache.jetspeed.components.ComponentManager;
 34  
 import org.apache.jetspeed.exception.JetspeedException;
 35  
 import org.apache.jetspeed.pipeline.Pipeline;
 36  
 import org.apache.jetspeed.request.RequestContext;
 37  
 import org.apache.jetspeed.request.RequestContextComponent;
 38  
 import org.apache.jetspeed.statistics.PortalStatistics;
 39  
 import org.apache.ojb.broker.util.ClassHelper;
 40  
 import org.apache.pluto.PortletContainer;
 41  
 import org.apache.pluto.PortletContainerException;
 42  
 import org.apache.pluto.factory.Factory;
 43  
 import org.apache.pluto.services.ContainerService;
 44  
 import org.apache.pluto.services.factory.FactoryManagerService;
 45  
 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
 46  
 
 47  
 
 48  
 /**
 49  
  * <p>
 50  
  * AbstractEngine
 51  
  * </p>
 52  
  * <p>
 53  
  *
 54  
  * </p>
 55  
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
 56  
  * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
 57  
  * @version $Id: AbstractEngine.java 188433 2005-03-23 22:50:44Z ate $
 58  
  *
 59  
  */
 60  
 public class JetspeedEngine implements Engine
 61  
 {   
 62  
     private final PortalContext context;
 63  
     private final ServletConfig config;
 64  
     private final ComponentManager componentManager;
 65  
     private Map pipelineMapper ;
 66  
     private PortalStatistics statistics;
 67  
     
 68  0
     protected static final Log log = LogFactory.getLog(JetspeedEngine.class);
 69  
     protected String defaultPipelineName;    
 70  
 
 71  
     public JetspeedEngine(Configuration configuration, String applicationRoot, ServletConfig config, ComponentManager componentManager )
 72  
     {
 73  0
         this(new PortalConfigurationImpl(configuration), applicationRoot, config, componentManager);
 74  0
     }
 75  
     
 76  
     public JetspeedEngine(PortalConfiguration configuration, String applicationRoot, ServletConfig config, ComponentManager componentManager )
 77  0
     {
 78  0
         this.componentManager = componentManager;
 79  0
         this.context = new JetspeedPortalContext(class="keyword">this, configuration, applicationRoot);
 80  0
         this.config = config;
 81  0
         context.setApplicationRoot(applicationRoot);
 82  0
         context.setConfiguration(configuration);           
 83  
 
 84  0
         defaultPipelineName = configuration.getString(PIPELINE_DEFAULT, "jetspeed-pipeline");
 85  0
         configuration.setString(JetspeedEngineConstants.APPLICATION_ROOT_KEY, applicationRoot);
 86  
         
 87  
         // Make these availble as beans to Spring
 88  0
         componentManager.addComponent("Engine", this);
 89  0
         componentManager.addComponent("PortalContext", context);
 90  0
         componentManager.addComponent("PortalConfiguration", configuration);
 91  0
     }  
 92  
     
 93  
     
 94  
 
 95  
     /**
 96  
      * Initializes the engine with a commons configuration, starting all early
 97  
      * initable services.
 98  
      * 
 99  
      * @param configuration
 100  
      *                  a commons <code>Configuration</code> set
 101  
      * @param applicationRoot
 102  
      *                  a <code>String</code> path to the application root for
 103  
      *                  resources
 104  
      * @param
 105  
      * @throws JetspeedException
 106  
      *                   when the engine fails to initilialize
 107  
      */
 108  
     public void start() throws JetspeedException
 109  
     {        
 110  0
         DateFormat format = DateFormat.getInstance();
 111  0
         Date startTime = new Date();        
 112  
         try
 113  
         {  
 114  0
             log.info("Starting Jetspeed Engine ("+getClass().getName()+") at "+format.format(startTime));
 115  
     
 116  
             // patch up OJB
 117  0
             ClassLoader ploader2 = this.getClass().getClassLoader();
 118  
             //ClassLoader ploader2 = Thread.currentThread().getContextClassLoader();
 119  0
             ClassHelper.setClassLoader(ploader2);
 120  
             
 121  
             //Start the ComponentManager
 122  0
             componentManager.start();               
 123  0
             pipelineMapper = (Map)componentManager.getComponent("pipeline-map");
 124  
             try
 125  
             {
 126  0
                 statistics = (PortalStatistics)componentManager.getComponent("PortalStatistics");
 127  
             }
 128  0
             catch (Exception e)
 129  
             {
 130  
                 // silenty ignore, its not configured
 131  
                 // TODO: statistics as an AOP advice
 132  0
             }
 133  
             // TODO: complete this work for JSP (https://issues.apache.org/jira/browse/JS2-711)
 134  
             // I think config.getServletName is incorrect, need to fix this and change this name to jetspeed-layouts:: when looking up in registry
 135  
             // but not when dispatching, still trying to figure that out
 136  
             //PortletApplicationManagement pam = (PortletApplicationManagement)componentManager.getComponent("PAM");
 137  
             //pam.startInternalApplication(config.getServletName());                
 138  
             
 139  
         }
 140  0
         catch (Throwable e)
 141  
         {
 142  0
             e.printStackTrace();
 143  0
             log.error(e.toString());
 144  0
             throw new JetspeedException("Jetspeed Initialization exception!", e);
 145  
         }
 146  
         finally
 147  
         {            
 148  0
             Date endTime = new Date();
 149  0
             long elapsedTime = (endTime.getTime() - startTime.getTime()) / 1000;
 150  0
             log.info("Finished starting Jetspeed Engine ("+getClass().getName()+") at "+format.format(endTime) 
 151  
                          +".  Elapsed time: "+elapsedTime+" seconds.");
 152  0
         }
 153  0
     }
 154  
 
 155  
     /**
 156  
      * Get the servlet configuration if this engine is running under a servlet
 157  
      * container.
 158  
      * 
 159  
      * @return config The servlet configuration
 160  
      */
 161  
     public ServletConfig getServletConfig()
 162  
     {
 163  0
         return this.config;
 164  
     }
 165  
 
 166  
 
 167  
 
 168  
     public void shutdown() throws JetspeedException
 169  
     {        
 170  
     
 171  
         try
 172  
         {
 173  0
             PortletContainer container = (PortletContainer) componentManager
 174  
                     .getComponent(PortletContainer.class);
 175  0
             if (container != null)
 176  
             {
 177  0
                 container.shutdown();
 178  
             }
 179  
     
 180  0
             componentManager.stop();
 181  
         }
 182  0
         catch (PortletContainerException e)
 183  
         {
 184  0
             throw new JetspeedException(e);
 185  0
         }
 186  0
         System.gc();
 187  0
     }
 188  
 
 189  
     public void service( RequestContext context ) throws JetspeedException
 190  
     {        
 191  0
         long start = System.currentTimeMillis();
 192  0
         String targetPipeline = context
 193  
                 .getRequestParameter(PortalReservedParameters.PIPELINE);
 194  0
         if (null == targetPipeline)
 195  
         {
 196  0
             targetPipeline = (String)context.getAttribute(PortalReservedParameters.PIPELINE);                
 197  0
             if (null == targetPipeline)
 198  
             {
 199  0
                 String pipelineKey = context.getRequest().getServletPath();                    
 200  0
                 if (null != pipelineKey)
 201  
                 {
 202  0
                     if (pipelineKey.equals("/portal"))
 203  0
                         targetPipeline = this.defaultPipelineName;
 204  
                     else
 205  0
                         targetPipeline = (String)pipelineMapper.get(pipelineKey); 
 206  
                     // System.out.println("pipeline = " + targetPipeline);
 207  
                 }
 208  
                 else
 209  
                 {
 210  0
                     targetPipeline = this.defaultPipelineName;
 211  
                 }
 212  
             }
 213  
         }
 214  0
         Pipeline pipeline = null;
 215  0
         if (targetPipeline != null)
 216  
         {
 217  0
             Pipeline specificPipeline = getPipeline(targetPipeline);
 218  0
             if (specclass="keyword">ificPipeline != null)
 219  
             {
 220  0
                 pipeline = specificPipeline;
 221  
             }
 222  0
         }
 223  
         else
 224  0
             pipeline = getPipeline();
 225  
         
 226  0
         context.setPipeline(pipeline);
 227  0
         pipeline.invoke(context);
 228  
    
 229  0
         long end = System.currentTimeMillis();
 230  0
         if (statistics != null)
 231  0
             statistics.logPageAccess(context, PortalStatistics.HTTP_OK, end - start);
 232  0
     }
 233  
 
 234  
     /**
 235  
      * Returns the context associated with this engine.
 236  
      * 
 237  
      * @return an <code>EngineContext</code> associated with this engine
 238  
      */
 239  
     public PortalContext getContext()
 240  
     {
 241  0
         return this.context;
 242  
     }
 243  
 
 244  
     /**
 245  
      * Given a application relative path, returns the real path relative to the
 246  
      * application root
 247  
      *  
 248  
      */
 249  
     public String getRealPath( String path )
 250  
     {
 251  0
         String result = "";
 252  0
         String base = context.getApplicationRoot();
 253  0
         if (base.endsWith(java.io.File.separator))
 254  
         {
 255  0
             if (path.startsWith("/"))
 256  
             {
 257  0
                 result = base.concat(path.substring(1));
 258  0
                 return result;
 259  
             }
 260  
         }
 261  
         else
 262  
         {
 263  0
             if (!path.startsWith("/"))
 264  
             {
 265  0
                 result = base.concat("/").concat(path);
 266  0
                 return result;
 267  
             }
 268  
         }
 269  0
         return base.concat(path);
 270  
     }
 271  
     
 272  
     public Pipeline getPipeline( String pipelineName )
 273  
     {
 274  0
         return (Pipeline) componentManager.getComponent(pipelineName);
 275  
     }
 276  
 
 277  
     public Pipeline getPipeline()
 278  
     {
 279  0
         return getPipeline(defaultPipelineName);
 280  
     }
 281  
 
 282  
     /**
 283  
      * @see org.apache.jetspeed.engine.Engine#getCurrentRequestContext()
 284  
      */
 285  
     public RequestContext getCurrentRequestContext()
 286  
     {
 287  0
         RequestContextComponent contextComponent = (RequestContextComponent) getComponentManager()
 288  
             .getComponent(RequestContextComponent.class);
 289  0
         return contextComponent.getRequestContext();
 290  
     }
 291  
 
 292  
     public ComponentManager getComponentManager()
 293  
     {
 294  0
         return this.componentManager;
 295  
     }
 296  
     /**
 297  
      * <p>
 298  
      * getFactory
 299  
      * </p>
 300  
      *
 301  
      * @see org.apache.pluto.services.factory.FactoryManagerService#getFactory(java.lang.Class)
 302  
      * @param theClass
 303  
      * @return
 304  
      */
 305  
     public Factory getFactory( Class theClass )
 306  
     {        
 307  0
         return (Factory) getComponentManager().getComponent(theClass);
 308  
     }
 309  
     /**
 310  
      * <p>
 311  
      * getContainerService
 312  
      * </p>
 313  
      *
 314  
      * @see org.apache.pluto.services.PortletContainerEnvironment#getContainerService(java.lang.Class)
 315  
      * @param service
 316  
      * @return
 317  
      */
 318  
     public ContainerService getContainerService( Class service )
 319  
     {
 320  0
         if(service.equals(FactoryManagerService.class))
 321  
         {
 322  0
             return this;
 323  
         }
 324  
 
 325  
         try
 326  
         {
 327  0
             return (ContainerService) getComponentManager().getComponent(service);
 328  
         }
 329  0
         catch (NoSuchBeanDefinitionException e)
 330  
         {
 331  0
             log.warn("No ContainerService defined for "+service.getName());
 332  0
             return null;
 333  
         }
 334  
     }
 335  
 
 336  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.