Coverage report

  %line %branch
org.apache.jetspeed.services.title.DynamicTitleServiceImpl
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.services.title;
 18  
 
 19  
 import java.util.Iterator;
 20  
 import java.util.Locale;
 21  
 
 22  
 import javax.servlet.http.HttpServletRequest;
 23  
 
 24  
 import org.apache.jetspeed.PortalReservedParameters;
 25  
 import org.apache.jetspeed.request.RequestContext;
 26  
 import org.apache.pluto.om.common.Preference;
 27  
 import org.apache.pluto.om.entity.PortletEntity;
 28  
 import org.apache.pluto.om.window.PortletWindow;
 29  
 
 30  0
 public class DynamicTitleServiceImpl implements DynamicTitleService
 31  
 {
 32  
 
 33  
     public void setDynamicTitle(PortletWindow window,
 34  
             HttpServletRequest request, String titleArg)
 35  
     {
 36  
         //String title = getTitleFromPreference(window, request);
 37  0
         String title = null;
 38  
 //        if (title == null || title.length() < 0)
 39  
 //        {
 40  0
             if (titleArg == null || titleArg.length() == 0)
 41  
             {
 42  0
                 title = getTitleFromPortletDefinition(window, request);
 43  
             }
 44  
             else
 45  
             {
 46  0
                 title = titleArg;
 47  
             }
 48  
 
 49  
 //        }
 50  
 
 51  0
         request.setAttribute(
 52  
                 PortalReservedParameters.OVERRIDE_PORTLET_TITLE_ATTR
 53  
                         + "::window.id::" + window.getId(), title);
 54  
 
 55  0
     }
 56  
     
 57  
     public String getDynamicTitle(PortletWindow window,
 58  
             HttpServletRequest request)
 59  
     {
 60  0
         return (String)request.getAttribute(PortalReservedParameters.OVERRIDE_PORTLET_TITLE_ATTR
 61  
                         + "::window.id::" + window.getId());
 62  
     }
 63  
 
 64  
     protected final String getTitleFromPortletDefinition(PortletWindow window,
 65  
             HttpServletRequest request)
 66  
     {
 67  0
         String title = null;
 68  0
         RequestContext requestContext = (RequestContext) request
 69  
                 .getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
 70  
         
 71  0
         PortletEntity entity = window.getPortletEntity();
 72  0
         if (entity != null && entity.getPortletDefinition() != class="keyword">null)
 73  
         {
 74  0
             title = requestContext.getPreferedLanguage(
 75  
                     entity.getPortletDefinition()).getTitle();
 76  
         }
 77  
 
 78  0
         if (title == null && entity.getPortletDefinition() != class="keyword">null)
 79  
         {
 80  0
             title = entity.getPortletDefinition().getName();
 81  
         }
 82  0
         else if (title == null)
 83  
         {
 84  0
             title = "Invalid portlet entity " + entity.getId();
 85  
         }
 86  
         
 87  0
         return title;
 88  
     }
 89  
 
 90  
     protected final String getTitleFromPreference(PortletWindow window,
 91  
             HttpServletRequest request)
 92  
     {
 93  0
         Locale locale = request.getLocale();
 94  0
         String titleKey = createTitleKey(locale, false);
 95  
 
 96  0
         Preference titlePref = window.getPortletEntity().getPreferenceSet()
 97  
                 .get(titleKey);
 98  0
         if (titlePref == null)
 99  
         {
 100  0
             titleKey = createTitleKey(locale, true);
 101  0
             titlePref = window.getPortletEntity().getPreferenceSet().get(
 102  
                     titleKey);
 103  
         }
 104  
 
 105  0
         if (titlePref != null)
 106  
         {
 107  0
             Iterator values = titlePref.getValues();
 108  0
             if (values.hasNext())
 109  
             {
 110  0
                 return (String) titlePref.getValues().next();
 111  
             }
 112  
         }
 113  
 
 114  0
         return null;
 115  
     }
 116  
 
 117  
     public static String createTitleKey(Locale locale, boolean languageOnly)
 118  
     {
 119  0
         if(languageOnly)
 120  
         {
 121  0
             return "jetspeed.title."+locale.getLanguage();
 122  
         }
 123  
         else
 124  
         {
 125  0
             return "jetspeed.title."+locale.toString();
 126  
         }
 127  
     }
 128  
 
 129  
 }

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