Coverage report

  %line %branch
org.apache.jetspeed.util.descriptor.ExtendedPortletMetadata
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.util.descriptor;
 18  
 
 19  
 import java.io.Reader;
 20  
 import java.util.ArrayList;
 21  
 import java.util.Collection;
 22  
 import java.util.Iterator;
 23  
 
 24  
 import org.apache.commons.digester.Digester;
 25  
 import org.apache.commons.digester.Rule;
 26  
 import org.apache.commons.logging.Log;
 27  
 import org.apache.commons.logging.LogFactory;
 28  
 import org.apache.jetspeed.om.common.portlet.CustomPortletMode;
 29  
 import org.apache.jetspeed.om.common.portlet.CustomWindowState;
 30  
 import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
 31  
 import org.apache.jetspeed.om.portlet.impl.CustomPortletModeImpl;
 32  
 import org.apache.jetspeed.om.portlet.impl.CustomWindowStateImpl;
 33  
 import org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImpl;
 34  
 import org.apache.jetspeed.tools.pamanager.rules.JetspeedServicesRuleSet;
 35  
 import org.apache.jetspeed.tools.pamanager.rules.MetadataRuleSet;
 36  
 import org.apache.jetspeed.tools.pamanager.rules.PortletRule;
 37  
 import org.apache.jetspeed.tools.pamanager.rules.SecurityConstraintRefRule;
 38  
 import org.apache.jetspeed.tools.pamanager.rules.UserAttributeRefRuleSet;
 39  
 import org.xml.sax.Attributes;
 40  
 
 41  
 /**
 42  
  * This class is used to load extended MetaData, like that of the Dublin Core, 
 43  
  * into an exsting PortletApplicationDefinition's object graph.
 44  
  * 
 45  
  * @author <a href="mailto:jford@apache.org">Jeremy Ford </a>
 46  
  * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
 47  
  * @version $Id: JetspeedDescriptorUtilities.java,v 1.10 2004/06/08 01:35:01
 48  
  *                dlestrat Exp $
 49  
  */
 50  
 public class ExtendedPortletMetadata
 51  
 {
 52  
     private static class CollectionRule extends Rule
 53  
     {
 54  
         private Collection collection;
 55  
         
 56  
         public CollectionRule(Collection collection)
 57  
         {
 58  
             this.collection = collection;
 59  
         }
 60  
 
 61  
         public void begin(String arg0, String arg1, Attributes arg2) throws Exception
 62  
         {
 63  
             digester.push(collection);
 64  
         }
 65  
 
 66  
         public void end(String arg0, String arg1) throws Exception
 67  
         {
 68  
             digester.pop();
 69  
         }        
 70  
     }
 71  
     
 72  0
     protected final static Log log = LogFactory.getLog(ExtendedPortletMetadata.class);
 73  
 
 74  
     protected Reader extendedMetaData;
 75  
     protected MutablePortletApplication portletApp;
 76  
     
 77  
     /**
 78  
      * 
 79  
      * @param extendedMetaData Reader that contains the extended metadata, usually jetspeed-portlet.xml
 80  
      * @param portletApp the MutablePortletApplication we are adding the extended metadata to.
 81  
      */
 82  
     public ExtendedPortletMetadata( Reader extendedMetaData, MutablePortletApplication portletApp )
 83  0
     {
 84  0
         this.extendedMetaData = extendedMetaData;
 85  0
         this.portletApp = portletApp;
 86  0
     }
 87  
 
 88  
     /**
 89  
      * Performs the actual loading and mapping of the metadata into the PortletApplicationDefinition.
 90  
      * 
 91  
      */
 92  
     public void load() throws MetaDataException
 93  
     {
 94  
         try
 95  
         {
 96  0
             Digester digester = new Digester();
 97  0
             digester.setClassLoader(this.getClass().getClassLoader());
 98  0
             digester.setValidating(false);
 99  0
             digester.setNamespaceAware(true);
 100  0
             digester.push(portletApp);
 101  
 
 102  0
             digester.addRuleSet(new MetadataRuleSet("portlet-app/"));
 103  0
             digester.addRuleSet(new JetspeedServicesRuleSet(portletApp));
 104  0
             digester.addRule("portlet-app/security-constraint-ref", new SecurityConstraintRefRule(portletApp));                        
 105  
             
 106  0
             digester.addRule("portlet-app/portlet/portlet-name", new PortletRule(portletApp));
 107  0
             digester.addRuleSet(new MetadataRuleSet("portlet-app/portlet/"));
 108  
             
 109  0
             digester.addRule("portlet-app/portlet/security-constraint-ref", new SecurityConstraintRefRule(portletApp));        
 110  
             
 111  0
             digester.addRuleSet(new UserAttributeRefRuleSet(portletApp));
 112  
             
 113  0
             ArrayList mappedPortletModes = new ArrayList();
 114  0
             digester.addRule("portlet-app/custom-portlet-mode",new CollectionRule(mappedPortletModes));
 115  0
             digester.addObjectCreate("portlet-app/custom-portlet-mode",CustomPortletModeImpl.class);
 116  
             
 117  0
             digester.addBeanPropertySetter("portlet-app/custom-portlet-mode/name", "customName");
 118  0
             digester.addBeanPropertySetter("portlet-app/custom-portlet-mode/mapped-name", "mappedName");
 119  0
             digester.addSetNext("portlet-app/custom-portlet-mode", "add");
 120  
             
 121  0
             ArrayList mappedWindowStates = new ArrayList();
 122  0
             digester.addRule("portlet-app/custom-window-state",new CollectionRule(mappedWindowStates));
 123  0
             digester.addObjectCreate("portlet-app/custom-window-state",CustomWindowStateImpl.class);
 124  
             
 125  0
             digester.addBeanPropertySetter("portlet-app/custom-window-state/name", "customName");
 126  0
             digester.addBeanPropertySetter("portlet-app/custom-window-state/mapped-name", "mappedName");
 127  0
             digester.addSetNext("portlet-app/custom-window-state", "add");
 128  
             
 129  0
             digester.parse(extendedMetaData);
 130  
             
 131  0
             if (mappedPortletModes.size() > 0)
 132  
             {
 133  0
                 PortletApplicationDefinitionImpl pa = (PortletApplicationDefinitionImpl)portletApp;
 134  0
                 ArrayList customModes = new ArrayList(pa.getCustomPortletModes());
 135  0
                 Iterator mappedModesIter = mappedPortletModes.iterator();
 136  0
                 while ( mappedModesIter.hasNext() )
 137  
                 {
 138  0
                     CustomPortletModeImpl mappedMode = (CustomPortletModeImpl)mappedModesIter.next();
 139  0
                     if (!mappedMode.getMappedMode().equals(mappedMode.getCustomMode()))
 140  
                     {
 141  0
                         int index = customModes.indexOf(mappedMode);
 142  0
                         if ( index > -1 )
 143  
                         {
 144  0
                             CustomPortletMode customMode = (CustomPortletMode)customModes.get(index);
 145  0
                             mappedMode.setDescription(customMode.getDescription());
 146  0
                             customModes.set(index,mappedMode);
 147  
                         }
 148  
                     }
 149  0
                 }
 150  0
                 pa.setCustomPortletModes(customModes);
 151  
             }
 152  0
             if ( mappedWindowStates.size() > 0)
 153  
             {
 154  0
                 PortletApplicationDefinitionImpl pa = (PortletApplicationDefinitionImpl)portletApp;
 155  0
                 ArrayList customStates = new ArrayList(pa.getCustomWindowStates());
 156  0
                 Iterator mappedStatesIter = mappedWindowStates.iterator();
 157  0
                 while ( mappedStatesIter.hasNext() )
 158  
                 {
 159  0
                     CustomWindowStateImpl mappedState = (CustomWindowStateImpl)mappedStatesIter.next();
 160  0
                     if (!mappedState.getMappedState().equals(mappedState.getCustomState()))
 161  
                     {
 162  0
                         int index = customStates.indexOf(mappedState);
 163  0
                         if ( index > -1 )
 164  
                         {
 165  0
                             CustomWindowState customState = (CustomWindowState)customStates.get(index);
 166  0
                             mappedState.setDescription(customState.getDescription());
 167  0
                             customStates.set(index,mappedState);
 168  
                         }
 169  
                     }
 170  0
                 }
 171  0
                 pa.setCustomWindowStates(customStates);
 172  
             }
 173  
         }
 174  0
         catch (Throwable t)
 175  
         {
 176  0
             throw new MetaDataException("Unable to marshall extended metadata.  " + t.toString(), t);
 177  0
         }
 178  0
     }
 179  
 }
 180  
 

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