Coverage Report - org.apache.tapestry.dojo.DojoUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
DojoUtils
0%
0/7
0%
0/6
4
 
 1  
 // Copyright May 16, 2006 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 package org.apache.tapestry.dojo;
 15  
 
 16  
 import java.text.ParseException;
 17  
 
 18  
 import org.apache.hivemind.ApplicationRuntimeException;
 19  
 import org.apache.tapestry.IBinding;
 20  
 import org.apache.tapestry.IComponent;
 21  
 import org.apache.tapestry.json.JSONObject;
 22  
 
 23  
 /**
 24  
  * @author andyhot
 25  
  * @since 4.1
 26  
  */
 27  
 public final class DojoUtils
 28  
 {
 29  
     /* defeat instantiation */
 30  0
     private DojoUtils() { }
 31  
     
 32  
     /**
 33  
      * Converts a parameter of an {@link IComponent} to an instance of {@link JSONObject}.
 34  
      * 
 35  
      * @param component
 36  
      * @param parameterName
 37  
      * @return The parameter parsed into a json structure.
 38  
      */
 39  
     public static JSONObject parseJSONParameter(IComponent component, String parameterName)
 40  
     {
 41  0
         IBinding binding = component.getBinding(parameterName);
 42  0
         if (binding == null || binding.getObject() == null)
 43  0
             return new JSONObject();
 44  
         
 45  
         try
 46  
         {
 47  0
             return new JSONObject((String) binding.getObject(String.class));
 48  
         }
 49  0
         catch (ParseException ex)
 50  
         {
 51  0
             throw new ApplicationRuntimeException( DojoMessages.mustUseValidJsonInParameter(parameterName), 
 52  
                     binding.getLocation() , ex);
 53  
         }
 54  
     }
 55  
 }