Coverage report

  %line %branch
org.apache.jetspeed.om.preference.impl.FragmentPortletPreferenceSet
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.om.preference.impl;
 18  
 
 19  
 import java.util.HashMap;
 20  
 import java.util.Iterator;
 21  
 import java.util.List;
 22  
 import java.util.Map;
 23  
 import java.util.Set;
 24  
 
 25  
 import javax.portlet.PreferencesValidator;
 26  
 
 27  
 import org.apache.jetspeed.om.common.preference.PreferenceSetComposite;
 28  
 import org.apache.jetspeed.om.page.Fragment;
 29  
 import org.apache.pluto.om.common.Preference;
 30  
 
 31  
 /**
 32  
  * This is a per-request wrapper for a PreferenceSet that allows 
 33  
  * the use of fragment-specified Preferences within a portlet instance
 34  
  * in a page.
 35  
  * 
 36  
  * @author <href a="mailto:weaver@apache.org">Scott T. Weaver</a>
 37  
  *
 38  
  */
 39  
 public class FragmentPortletPreferenceSet implements PreferenceSetComposite
 40  
 {
 41  
     private final PreferenceSetComposite preferenceSet;
 42  
     private final Map prefs;
 43  
     
 44  
     public FragmentPortletPreferenceSet(PreferenceSetComposite preferenceSet, Fragment fragment)
 45  0
     {
 46  
         // save mutable preference set and read only fragment
 47  0
         this.preferenceSet = preferenceSet;
 48  
         // construct merged portlet definition prefs map;
 49  
         // note that user specific preferences accessed via
 50  
         // the portlet entity should override these defaults
 51  0
         int prefsSize = preferenceSet.size() + 1;        
 52  0
         if (fragment != null && fragment.getPreferences() != class="keyword">null)
 53  
         {
 54  0
             prefsSize += fragment.getPreferences().size();
 55  
         }
 56  0
         this.prefs = new HashMap(prefsSize);
 57  
 
 58  
         // add global portlet definition defaults to prefs
 59  0
         Iterator iterator = preferenceSet.iterator();
 60  0
         while(iterator.hasNext())
 61  
         {
 62  0
             Preference pref = (Preference) iterator.next();
 63  0
             prefs.put(pref.getName(), pref);
 64  0
         }        
 65  
 
 66  
         // add/override global portlet definition defaults
 67  
         // using more specific fragment preferences
 68  0
         if (fragment != null && fragment.getPreferences() != class="keyword">null)
 69  
         {
 70  0
             Iterator itr = fragment.getPreferences().iterator();        
 71  0
             while(itr.hasNext())
 72  
             {
 73  0
                 Preference pref = (Preference) itr.next();
 74  0
                 prefs.put(pref.getName(), pref);
 75  0
             }
 76  
         }
 77  0
     }
 78  
 
 79  
     public Preference add(String arg0, List arg1)
 80  
     {        
 81  0
         Preference pref = preferenceSet.add(arg0, arg1);
 82  0
         prefs.put(arg0, pref);
 83  0
         return pref;
 84  
     }
 85  
 
 86  
     public Preference get(String name)
 87  
     {
 88  0
         return (Preference) prefs.get(name);
 89  
     }
 90  
 
 91  
     public Set getNames()
 92  
     {
 93  0
         return prefs.keySet();
 94  
     }
 95  
 
 96  
     public PreferencesValidator getPreferencesValidator()
 97  
     {
 98  0
         return preferenceSet.getPreferencesValidator();
 99  
     }
 100  
 
 101  
     public Iterator iterator()
 102  
     {
 103  0
         return prefs.values().iterator();
 104  
     }
 105  
 
 106  
     public void remove(Preference pref)
 107  
     {
 108  0
         prefs.remove(pref.getName());
 109  0
         preferenceSet.remove(pref);
 110  0
     }
 111  
 
 112  
     public Preference remove(String name)
 113  
     {
 114  0
         Preference pref = (Preference) prefs.remove(name);
 115  0
         preferenceSet.remove(name);
 116  0
         return pref;
 117  
     }
 118  
 
 119  
     public int size()
 120  
     {
 121  0
         return prefs.size();
 122  
     }
 123  
 }

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