Coverage report

  %line %branch
org.apache.jetspeed.search.handlers.pam.PortletDefinitionHandler
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.search.handlers.pam;
 18  
 
 19  
 import java.util.Collection;
 20  
 import java.util.HashSet;
 21  
 import java.util.Iterator;
 22  
 
 23  
 import org.apache.commons.collections.MultiHashMap;
 24  
 import org.apache.jetspeed.om.common.LocalizedField;
 25  
 import org.apache.jetspeed.om.common.portlet.PortletApplication;
 26  
 import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
 27  
 import org.apache.jetspeed.search.AbstractObjectHandler;
 28  
 import org.apache.jetspeed.search.BaseParsedObject;
 29  
 import org.apache.jetspeed.search.ParsedObject;
 30  
 import org.apache.jetspeed.util.JetspeedLocale;
 31  
 import org.apache.pluto.om.common.Description;
 32  
 import org.apache.pluto.om.common.DisplayName;
 33  
 import org.apache.pluto.om.common.Language;
 34  
 
 35  
 /**
 36  
  * @author <a href="mailto: jford@apache.org">Jeremy Ford</a>
 37  
  */
 38  0
 public class PortletDefinitionHandler extends AbstractObjectHandler
 39  
 {
 40  
     private static final String KEY_PREFIX = "PortletDefinition::";
 41  
     private static final String ID = "ID";
 42  
     private static final String PORTLET_APPLICATION = "portlet_application";
 43  
     
 44  
     {
 45  0
         fields.add(ID);
 46  0
         fields.add(PORTLET_APPLICATION);
 47  0
     }
 48  
 
 49  
     /* (non-Javadoc)
 50  
      * @see org.apache.jetspeed.search.ObjectHandler#parseObject(java.lang.Object)
 51  
      */
 52  
     public ParsedObject parseObject(Object o)
 53  
     {
 54  0
         BaseParsedObject result = null;
 55  0
         if(o instanceof PortletDefinitionComposite)
 56  
         {
 57  0
             result = new BaseParsedObject();
 58  0
             PortletDefinitionComposite pd = (PortletDefinitionComposite)o;
 59  
             
 60  
             //need to get Locale here
 61  0
             String displayNameText = pd.getDisplayNameText(JetspeedLocale.getDefaultLocale());
 62  0
             result.setTitle(displayNameText);
 63  
             
 64  0
             String description = pd.getDescriptionText(JetspeedLocale.getDefaultLocale());
 65  0
             result.setDescription(description);
 66  
             
 67  0
             result.setClassName(pd.getClass().getName());
 68  0
             result.setKey(KEY_PREFIX + pd.getUniqueName());
 69  0
             result.setType(ParsedObject.OBJECT_TYPE_PORTLET);
 70  
             
 71  
             //TODO: this is common to PAs as well, possible refactor
 72  0
             MultiHashMap fieldMap = new MultiHashMap();
 73  0
             fieldMap.put(ID, pd.getName());
 74  
             
 75  0
             PortletApplication pa = (PortletApplication)pd.getPortletApplicationDefinition();
 76  0
             fieldMap.put(PORTLET_APPLICATION, pa.getName()); 
 77  
             
 78  0
             Collection mdFields = pd.getMetadata().getFields();
 79  0
             for (Iterator fieldIter = mdFields.iterator(); fieldIter.hasNext();)
 80  
             {
 81  0
                 LocalizedField field = (LocalizedField) fieldIter.next();                
 82  0
                 fieldMap.put(field.getName(), field.getValue());
 83  0
             }
 84  
             
 85  
             //Handle descriptions
 86  0
             Iterator descIter = pd.getDescriptionSet().iterator();
 87  0
             while (descIter.hasNext())
 88  
             {
 89  0
                 Description desc = (Description) descIter.next();
 90  0
                 fieldMap.put(ParsedObject.FIELDNAME_DESCRIPTION, desc.getDescription());
 91  0
             }
 92  
             
 93  
             //Handle keywords and titles
 94  0
             Iterator displayNameIter = pd.getDisplayNameSet().iterator();
 95  0
             while (displayNameIter.hasNext())
 96  
             {
 97  0
                 DisplayName displayName = (DisplayName) displayNameIter.next();
 98  0
                 fieldMap.put(ParsedObject.FIELDNAME_TITLE, displayName.getDisplayName());
 99  0
             }
 100  
             
 101  0
             HashSet keywordSet = new HashSet();
 102  
             
 103  0
             Iterator langIter = pd.getLanguageSet().iterator();
 104  0
             while (langIter.hasNext())
 105  
             {
 106  0
                 Language lang = (Language) langIter.next();
 107  0
                 fieldMap.put(ParsedObject.FIELDNAME_TITLE, lang.getTitle());
 108  0
                 fieldMap.put(ParsedObject.FIELDNAME_TITLE, lang.getShortTitle());
 109  
                 
 110  0
                 Iterator keywordIter = lang.getKeywords();
 111  0
                 if (keywordIter != null)
 112  
                 {
 113  0
                     while (keywordIter.hasNext())
 114  
                     {
 115  0
                         String keyword = (String) keywordIter.next();
 116  0
                         keywordSet.add(keyword);
 117  0
                     }
 118  
                 }
 119  0
             }
 120  
             
 121  0
             String[] temp = new String[keywordSet.size()];
 122  0
             result.setKeywords((String[])keywordSet.toArray(temp));
 123  0
             result.setFields(fieldMap);
 124  
         }
 125  0
         return result;
 126  
     }
 127  
 }

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