Coverage report

  %line %branch
org.apache.jetspeed.JetspeedPortalContext
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;
 18  
 
 19  
 import java.util.Collection;
 20  
 import java.util.Enumeration;
 21  
 import java.util.HashMap;
 22  
 
 23  
 import javax.portlet.PortletMode;
 24  
 import javax.portlet.WindowState;
 25  
 
 26  
 import org.apache.jetspeed.administration.PortalConfiguration;
 27  
 import org.apache.jetspeed.container.PortletRequestContext;
 28  
 import org.apache.jetspeed.engine.Engine;
 29  
 import org.apache.jetspeed.om.common.portlet.PortletApplication;
 30  
 import org.apache.pluto.util.Enumerator;
 31  
 
 32  
 /**
 33  
  * Implementation of Portal Context associated with running thread of the engine
 34  
  *
 35  
  * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
 36  
  * @version $Id: JetspeedPortalContext.java 553375 2007-07-05 05:37:00Z taylor $
 37  
  */
 38  
 public class JetspeedPortalContext implements PortalContext
 39  
 {
 40  
     private static final String SUPPORTED_WINDOWSTATE_ATTR = "supported.windowstate";
 41  
     private static final String SUPPORTED_PORTLETMODE_ATTR = "supported.portletmode";
 42  
     private static final String PORTAL_VERSION_ATTR = "portal.version";
 43  
     private static final String PORTAL_NAME_ATTR = "portal.name";
 44  
     
 45  
     /**
 46  
      * The engine associated with this context.
 47  
      */
 48  0
     private Engine engine = null;
 49  
 
 50  
     /**
 51  
      * Runtime attributes.
 52  
      */
 53  0
     private HashMap attributes = new HashMap();
 54  
 
 55  
     /**
 56  
      * Configuration state
 57  
      */
 58  0
     private PortalConfiguration configuration = null;
 59  
 
 60  
     /**
 61  
      * The base from which the Jetspped application will operate.
 62  
      */
 63  
     private String applicationRoot;
 64  
     
 65  
     private final String portalInfo;
 66  
 
 67  
     public JetspeedPortalContext(Engine engine, PortalConfiguration configuration, String applicationRoot)
 68  0
     {
 69  0
         this.engine = engine;
 70  0
         this.configuration = configuration;
 71  0
         this.applicationRoot = applicationRoot;
 72  
              
 73  0
         portalInfo = configuration.getString(PORTAL_NAME_ATTR) + "/" + configuration.getString(PORTAL_VERSION_ATTR);
 74  
         
 75  
         // Inititalize supported portlet modes and window states
 76  0
         String[] supportedModes = configuration.getStringArray(SUPPORTED_PORTLETMODE_ATTR);
 77  0
         String[] supportedStates = configuration.getStringArray(SUPPORTED_WINDOWSTATE_ATTR);
 78  0
         new JetspeedActions(supportedModes, supportedStates);
 79  0
     }
 80  
 
 81  
     // ------------------------------------------------------------------------
 82  
     //  A C C E S S O R S
 83  
     // ------------------------------------------------------------------------
 84  
 
 85  
     /**
 86  
      * Returns the configuration properties for this Jetspeed engine context.
 87  
      *
 88  
      * @return a <code>Configuration</code> containing the configuration properties for this Jetspeed context.
 89  
      */
 90  
     public PortalConfiguration getConfiguration()
 91  
     {
 92  0
         return configuration;
 93  
     }
 94  
 
 95  
     public String getConfigurationProperty(String key)
 96  
     {
 97  0
         return configuration.getString(key);
 98  
     }
 99  
 
 100  
     public String getConfigurationProperty(String key, String defaultValue)
 101  
     {
 102  0
         return configuration.getString(key, defaultValue);
 103  
     }
 104  
 
 105  
     /**
 106  
      * Set the configuration properties for this Jetspeed engine context.
 107  
      *
 108  
      * @param configuration - the configuration properties
 109  
      */
 110  
     public void setConfiguration(PortalConfiguration configuration)
 111  
     {
 112  0
         this.configuration = configuration;
 113  0
     }
 114  
 
 115  
     /**
 116  
      * Returns the application root for this Jetspeed engine context.
 117  
      *
 118  
      * @return a <code>String</code> containing the application root path for this Jetspeed context.
 119  
      */
 120  
     public String getApplicationRoot()
 121  
     {
 122  0
         return applicationRoot;
 123  
     }
 124  
 
 125  
     /**
 126  
      * Sets the application root path for this Jetspeed engine context.
 127  
      *
 128  
      * @param applicationRoot - the applicationRoot path on the file system.
 129  
      */
 130  
     public void setApplicationRoot(String applicationRoot)
 131  
     {
 132  0
         this.applicationRoot = applicationRoot;
 133  0
     }
 134  
 
 135  
     /**
 136  
      * Returns the engine associated with this context.
 137  
      *
 138  
      * @return an <code>Engine</code> associated with this context
 139  
      */
 140  
     public Engine getEngine()
 141  
     {
 142  0
         return this.engine;
 143  
     }
 144  
 
 145  
     /**
 146  
      * Returns the engine attribute with the given name, or null if there is no attribute by that name.
 147  
      *
 148  
      * @return an <code>Object</code> containing the value of the attribute, or null if no attribute exists matching the given name
 149  
      */
 150  
     public Object getAttribute(String name)
 151  
     {
 152  0
         return attributes.get(name);
 153  
     }
 154  
 
 155  
 
 156  
     /**
 157  
      * Binds an object to a given attribute name in this servlet context.
 158  
      *
 159  
      * @param  name - a <code>String</code> specifying the name of the attribute
 160  
      * @param value - an <code>Object</code> representing the attribute to be bound
 161  
      */
 162  
     public void setAttribute(String name, Object value)
 163  
     {
 164  0
         attributes.put(name, value);
 165  0
     }
 166  
 
 167  
     /* (non-Javadoc)
 168  
      * @see javax.portlet.PortalContext#getProperty(java.lang.String)
 169  
      */
 170  
     public String getProperty(String name)
 171  
     {
 172  0
         if (name == null) 
 173  
         {
 174  0
             throw new IllegalArgumentException("Property name == null");
 175  
         }
 176  0
         return(String) configuration.getString(name);
 177  
     }
 178  
 
 179  
     /* (non-Javadoc)
 180  
      * @see javax.portlet.PortalContext#getPropertyNames()
 181  
      */
 182  
     public Enumeration getPropertyNames()
 183  
     {
 184  0
         return new Enumerator(configuration.getKeys());
 185  
     }
 186  
     
 187  
     private Collection getSupportedModes()
 188  
     {
 189  0
         PortletRequestContext ctx = PortletRequestContext.getContext();
 190  0
         if ( ctx != null )
 191  
         {
 192  0
             PortletApplication pa = ((PortletApplication)ctx.getPortletDefinition().getPortletApplicationDefinition());
 193  0
             return pa.getSupportedPortletModes();
 194  
         }
 195  0
         return JetspeedActions.getStandardPortletModes();
 196  
     }
 197  
 
 198  
     /* (non-Javadoc)
 199  
      * @see javax.portlet.PortalContext#getSupportedPortletModes()
 200  
      */
 201  
     public Enumeration getSupportedPortletModes()
 202  
     {
 203  0
         return new Enumerator(getSupportedModes());
 204  
     }
 205  
     
 206  
     public boolean isPortletModeAllowed(PortletMode mode)
 207  
     {
 208  0
         return getSupportedModes().contains(mode);
 209  
     }
 210  
 
 211  
     private Collection getSupportedStates()
 212  
     {
 213  0
         PortletRequestContext ctx = PortletRequestContext.getContext();
 214  0
         if ( ctx != null )
 215  
         {
 216  0
             PortletApplication pa = ((PortletApplication)ctx.getPortletDefinition().getPortletApplicationDefinition());
 217  0
             return pa.getSupportedWindowStates();
 218  
         }
 219  0
         return JetspeedActions.getStandardWindowStates();
 220  
     }
 221  
     
 222  
     /* (non-Javadoc)
 223  
      * @see javax.portlet.PortalContext#getSupportedWindowStates()
 224  
      */
 225  
     public Enumeration getSupportedWindowStates()
 226  
     {
 227  0
         return new Enumerator(getSupportedStates());
 228  
     }
 229  
     
 230  
     public boolean isWindowStateAllowed(WindowState state)
 231  
     {
 232  0
         return getSupportedStates().contains(state);
 233  
     }
 234  
 
 235  
     /* (non-Javadoc)
 236  
      * @see javax.portlet.PortalContext#getPortalInfo()
 237  
      */
 238  
     public String getPortalInfo()
 239  
     {
 240  0
         return portalInfo;
 241  
     }
 242  
 }

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