Coverage report

  %line %branch
org.apache.jetspeed.container.JetspeedPortletContext
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.container;
 18  
 
 19  
 import java.io.InputStream;
 20  
 import java.util.Collection;
 21  
 import java.util.Enumeration;
 22  
 import java.util.Iterator;
 23  
 
 24  
 import javax.servlet.ServletContext;
 25  
 import javax.servlet.RequestDispatcher;
 26  
 
 27  
 import javax.portlet.PortletContext;
 28  
 import javax.portlet.PortletRequestDispatcher;
 29  
 
 30  
 import org.apache.jetspeed.dispatcher.JetspeedRequestDispatcher;
 31  
 import org.apache.jetspeed.om.common.JetspeedServiceReference;
 32  
 import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
 33  
 import org.apache.jetspeed.services.JetspeedPortletServices;
 34  
 import org.apache.jetspeed.services.PortletServices;
 35  
 import org.apache.pluto.om.portlet.PortletApplicationDefinition;
 36  
 
 37  
 /**
 38  
  * Implements the Portlet API Portlet Context class
 39  
  *
 40  
  * TODO: on LOCAL apps, we need to merge in web.xml props. See PLT 10.3
 41  
  *
 42  
  * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
 43  
  * @version $Id: JetspeedPortletContext.java 516448 2007-03-09 16:25:47Z ate $
 44  
  */
 45  
 public class JetspeedPortletContext implements PortletContext, InternalPortletContext
 46  
 {
 47  
     /**
 48  
      * The path to the Local Portlet Apps directory
 49  
      */
 50  
     public static final String LOCAL_PA_ROOT = "/WEB-INF/apps";
 51  
 
 52  
     private ServletContext servletContext;
 53  
     private MutablePortletApplication application;
 54  
 
 55  
     public JetspeedPortletContext(ServletContext servletContext, PortletApplicationDefinition application)
 56  0
     {
 57  0
         this.servletContext = servletContext;
 58  0
         this.application = (MutablePortletApplication)application;
 59  0
     }
 60  
 
 61  
     public int getMajorVersion()
 62  
     {
 63  0
         return ContainerInfo.getMajorSpecificationVersion();
 64  
     }
 65  
 
 66  
     public int getMinorVersion()
 67  
     {
 68  0
         return ContainerInfo.getMinorSpecificationVersion();
 69  
     }
 70  
 
 71  
     // Delegated methods
 72  
 
 73  
     public java.util.Set getResourcePaths(String path)
 74  
     {
 75  0
         return servletContext.getResourcePaths(path);
 76  
     }
 77  
 
 78  
     public javax.portlet.PortletRequestDispatcher getRequestDispatcher(String path)
 79  
     {
 80  0
         String localizedPath = localizePath(path, this.application);
 81  0
         RequestDispatcher rd = null;
 82  
         
 83  
         try
 84  
         {
 85  0
             rd = servletContext.getRequestDispatcher(localizedPath);
 86  
         }
 87  0
         catch (Exception e)
 88  
         {
 89  
             // Portlet API says: return null
 90  0
         }
 91  
 
 92  
         // TODO: factory
 93  0
         if ( rd != null )
 94  
         {
 95  0
             return new JetspeedRequestDispatcher(rd);
 96  
         }
 97  0
         return null;
 98  
     }
 99  
 
 100  
     public PortletRequestDispatcher getNamedDispatcher(String name)
 101  
     {
 102  
         // TODO: localize name
 103  
 
 104  0
         RequestDispatcher rd = null;
 105  
         
 106  
         try
 107  
         {
 108  0
             rd = servletContext.getNamedDispatcher(name);
 109  
         }
 110  0
         catch (Exception e)
 111  
         {
 112  
             // Portlet API says: return null
 113  0
         }
 114  
         
 115  
         // TODO: factory
 116  
 
 117  0
         if ( rd != null )
 118  
         {
 119  0
             return new JetspeedRequestDispatcher(rd);
 120  
         }
 121  0
         return null;
 122  
     }
 123  
 
 124  
     public String getMimeType(String file)
 125  
     {
 126  0
         return servletContext.getMimeType(file);
 127  
     }
 128  
 
 129  
     public InputStream getResourceAsStream(String path)
 130  
     {
 131  0
         return servletContext.getResourceAsStream(localizePath(path, this.application));
 132  
     }
 133  
 
 134  
     public java.lang.Object getAttribute(java.lang.String name)
 135  
     {
 136  0
         if ( name == null )
 137  
         {
 138  0
             throw new IllegalArgumentException("Required parameter name is null");
 139  
         }
 140  
         
 141  0
         if (name.startsWith("cps:"))
 142  
         {
 143  0
             String serviceName = name.substring("cps:".length());
 144  
             
 145  
             // validate service
 146  0
             Collection validServices = application.getJetspeedServices();
 147  0
             if (null == validServices)
 148  
             {
 149  0
                 return null;
 150  
             }
 151  0
             boolean found = false;
 152  0
             Iterator iterator = validServices.iterator();
 153  0
             while (iterator.hasNext())
 154  
             {
 155  0
                 JetspeedServiceReference validService = (JetspeedServiceReference)iterator.next();
 156  0
                 if (validService.getName().equals(serviceName))
 157  
                 {
 158  0
                     found = true;
 159  0
                     break;
 160  
                 }
 161  0
             }
 162  
             
 163  0
             if (!found)
 164  
             {
 165  0
                 return null;
 166  
             }
 167  
             
 168  
             // return the service
 169  0
             PortletServices services = JetspeedPortletServices.getSingleton();
 170  0
             return services.getService(serviceName);
 171  
         }
 172  0
         return servletContext.getAttribute(name);
 173  
     }
 174  
 
 175  
     public void log(java.lang.String msg)
 176  
     {
 177  
         // TODO: setup a logger for the portlet application
 178  0
         servletContext.log(msg);
 179  0
     }
 180  
 
 181  
     public void log(java.lang.String message, java.lang.Throwable throwable)
 182  
     {
 183  
         // TODO: setup a logger for the portlet application
 184  0
         servletContext.log(message, throwable);
 185  0
     }
 186  
 
 187  
     public String getRealPath(String path)
 188  
     {
 189  0
         return servletContext.getRealPath(localizePath(path, this.application));
 190  
     }
 191  
 
 192  
     public java.net.URL getResource(String path) throws java.net.MalformedURLException
 193  
     {
 194  0
         return servletContext.getResource(localizePath(path, this.application));
 195  
     }
 196  
 
 197  
     public Enumeration getAttributeNames()
 198  
     {
 199  0
         return servletContext.getAttributeNames();
 200  
     }
 201  
 
 202  
     public java.lang.String getInitParameter(java.lang.String name)
 203  
     {
 204  0
         if ( name == null )
 205  
         {
 206  0
             throw new IllegalArgumentException("Required parameter name is null");
 207  
         }
 208  0
         return servletContext.getInitParameter(name);
 209  
     }
 210  
 
 211  
     public java.util.Enumeration getInitParameterNames()
 212  
     {
 213  0
         return servletContext.getInitParameterNames();
 214  
     }
 215  
 
 216  
     public void removeAttribute(java.lang.String name)
 217  
     {
 218  0
         if (name == null)
 219  
         {
 220  0
             throw new IllegalArgumentException("Attribute name == null");
 221  
         }
 222  
 
 223  0
         servletContext.removeAttribute(name);
 224  0
     }
 225  
 
 226  
     public void setAttribute(java.lang.String name, java.lang.Object object)
 227  
     {
 228  0
         if (name == null)
 229  
         {
 230  0
             throw new IllegalArgumentException("Attribute name == null");
 231  
         }
 232  0
         servletContext.setAttribute(name, object);
 233  0
     }
 234  
 
 235  
     public String getServerInfo()
 236  
     {
 237  0
         return ContainerInfo.getServerInfo();
 238  
     }
 239  
 
 240  
     // internal portlet context implementation
 241  
 
 242  
     public ServletContext getServletContext()
 243  
     {
 244  0
         return this.servletContext;
 245  
     }
 246  
 
 247  
     /**
 248  
      * @see org.apache.jetspeed.container.InternalPortletContext#getApplication()
 249  
      */
 250  
     public PortletApplicationDefinition getApplication()
 251  
     {
 252  0
         return this.application;
 253  
     }
 254  
 
 255  
     public String getPortletContextName()
 256  
     {
 257  0
         return servletContext.getServletContextName();
 258  
     }
 259  
 
 260  
     private String localizePath(String path, MutablePortletApplication app)
 261  
     {
 262  0
         if (path == null)
 263  
         {
 264  0
             return "/";
 265  
         }
 266  0
         return path;
 267  
         // TODO: local PA with own/extra resource paths support
 268  
 /*        
 269  
         if (app.getApplicationType() == MutablePortletApplication.WEBAPP)
 270  
         {
 271  
             return path;
 272  
         }
 273  
 
 274  
         StringBuffer pathBuffer = new StringBuffer(LOCAL_PA_ROOT);
 275  
         pathBuffer.append(app.getWebApplicationDefinition().getContextRoot());
 276  
         if (!path.startsWith("/"))
 277  
         {
 278  
             pathBuffer.append("/");
 279  
         }
 280  
         pathBuffer.append(path);
 281  
         String result = pathBuffer.toString();
 282  
         return result;
 283  
 */        
 284  
     }
 285  
 }

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