Coverage report

  %line %branch
org.apache.jetspeed.tools.pamanager.rules.LocalizedFieldRule
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.tools.pamanager.rules;
 18  
 
 19  
 import java.util.Locale;
 20  
 
 21  
 import org.apache.commons.digester.Rule;
 22  
 
 23  
 import org.apache.commons.logging.Log;
 24  
 import org.apache.commons.logging.LogFactory;
 25  
 
 26  
 import org.apache.jetspeed.om.common.GenericMetadata;
 27  
 import org.apache.jetspeed.om.common.LocalizedField;
 28  
 import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
 29  
 import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
 30  
 
 31  
 import org.xml.sax.Attributes;
 32  
 
 33  
 /**
 34  
  * This class helps load internationalized fields
 35  
  * 
 36  
  * @author <a href="mailto:jford@apache.org">Jeremy Ford </a>
 37  
  * @version $Id: LocalizedFieldRule.java 516448 2007-03-09 16:25:47Z ate $
 38  
  */
 39  0
 public class LocalizedFieldRule extends Rule
 40  
 {
 41  0
     protected final static Log log = LogFactory.getLog(LocalizedFieldRule.class);
 42  
 
 43  
     /**
 44  
      * Handle the beginning of an XML element.
 45  
      * 
 46  
      * @param attributes
 47  
      *            The attributes of this element
 48  
      * @exception Exception
 49  
      *                if a processing error occurs
 50  
      */
 51  
     public void begin(String namespace, String name, Attributes attributes) throws Exception
 52  
     {
 53  
 
 54  0
         if (digester.getLogger().isDebugEnabled())
 55  0
             digester.getLogger().debug("Setting localized field " + name);
 56  
         
 57  0
         Object obj = digester.peek();
 58  0
         if (null == obj)
 59  
         {
 60  0
             digester.push(null);
 61  0
             return;
 62  
         }
 63  0
         GenericMetadata metadata = null;
 64  0
         if (obj instanceof MutablePortletApplication)
 65  
         {
 66  0
             metadata = ((MutablePortletApplication) obj).getMetadata();
 67  
         }
 68  0
         if (obj instanceof PortletDefinitionComposite)
 69  
         {
 70  0
             metadata = ((PortletDefinitionComposite) obj).getMetadata();
 71  
         }
 72  0
         if (metadata != null)
 73  
         {
 74  0
             LocalizedField child = metadata.createLocalizedField();
 75  
 
 76  0
             if (name.equals("metadata"))
 77  
             {
 78  0
                 String nameAttr = attributes.getValue("name");
 79  0
                 child.setName(nameAttr);
 80  0
             }
 81  
             else
 82  
             {
 83  0
                 child.setName(name);
 84  
             }
 85  0
             String language = attributes.getValue("xml:lang");
 86  0
             Locale locale = null;
 87  0
             if (language == null)
 88  
             {
 89  0
                 locale = new Locale("en");
 90  
             }
 91  
             else
 92  
             {
 93  0
                 locale = new Locale(language);
 94  
             }
 95  
 
 96  0
             child.setLocale(locale);
 97  0
             digester.push(child);
 98  0
         }
 99  
         else
 100  
         {
 101  0
             digester.push(null);
 102  
         }
 103  0
     }
 104  
 
 105  
     public void body(String namespace, String name, String text) throws Exception
 106  
     {
 107  0
         LocalizedField child = (LocalizedField) digester.peek(0);
 108  0
         if (child != null)
 109  
         {
 110  0
             child.setValue(text);
 111  
         }
 112  0
     }
 113  
 
 114  
     public void end(String namespace, String name) throws Exception
 115  
     {
 116  0
         LocalizedField child = (LocalizedField) digester.pop();
 117  0
         if (child != null)
 118  
         {
 119  0
             Object obj = digester.peek();
 120  0
             if (null == obj)
 121  
             {
 122  0
                 digester.push(null);
 123  0
                 return;
 124  
             }
 125  0
             GenericMetadata metadata = null;
 126  0
             if (obj instanceof MutablePortletApplication)
 127  
             {
 128  0
                 metadata = ((MutablePortletApplication) obj).getMetadata();
 129  
             }
 130  0
             if (obj instanceof PortletDefinitionComposite)
 131  
             {
 132  0
                 metadata = ((PortletDefinitionComposite) obj).getMetadata();
 133  
             }
 134  0
             if (null != metadata)
 135  
             {
 136  0
                 metadata.addField(child);
 137  
             }    
 138  
         }
 139  0
     }
 140  
 }

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