Coverage Report - org.apache.tapestry.form.FormComponentContributorContextImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
FormComponentContributorContextImpl
0%
0/24
N/A
1
 
 1  
 // Copyright 2005 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  
 
 15  
 package org.apache.tapestry.form;
 16  
 
 17  
 import java.util.Locale;
 18  
 
 19  
 import org.apache.hivemind.ClassResolver;
 20  
 import org.apache.hivemind.Resource;
 21  
 import org.apache.hivemind.util.ClasspathResource;
 22  
 import org.apache.tapestry.IComponent;
 23  
 import org.apache.tapestry.IForm;
 24  
 import org.apache.tapestry.IRequestCycle;
 25  
 import org.apache.tapestry.PageRenderSupport;
 26  
 import org.apache.tapestry.TapestryUtils;
 27  
 import org.apache.tapestry.json.JSONObject;
 28  
 
 29  
 /**
 30  
  * Implementation of {@link org.apache.tapestry.form.FormComponentContributorContext}.
 31  
  * 
 32  
  * @author Howard Lewis Ship
 33  
  * @since 4.0
 34  
  */
 35  
 public class FormComponentContributorContextImpl extends ValidationMessagesImpl implements
 36  
         FormComponentContributorContext
 37  
 {
 38  
     private final ClassResolver _resolver;
 39  
 
 40  
     private final PageRenderSupport _pageRenderSupport;
 41  
 
 42  
     private final IFormComponent _field;
 43  
 
 44  
     private final IForm _form;
 45  
 
 46  
     private final String _formId;
 47  
     
 48  
     /**
 49  
      * Used only for testing.
 50  
      */
 51  
 
 52  
     FormComponentContributorContextImpl(IFormComponent field)
 53  
     {
 54  0
         super(field, Locale.ENGLISH);
 55  
 
 56  0
         _field = field;
 57  0
         _resolver = null;
 58  0
         _formId = null;
 59  0
         _pageRenderSupport = null;
 60  0
         _form = null;
 61  0
     }
 62  
 
 63  
     public FormComponentContributorContextImpl(Locale locale, IRequestCycle cycle,
 64  
             IFormComponent field)
 65  
     {
 66  0
         super(field, locale);
 67  
 
 68  0
         _field = field;
 69  0
         _form = field.getForm();
 70  0
         _formId = _form.getName();
 71  
 
 72  0
         _resolver = cycle.getInfrastructure().getClassResolver();
 73  
 
 74  0
         _pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, field);
 75  0
     }
 76  
 
 77  
     public void includeClasspathScript(String path)
 78  
     {
 79  0
         Resource resource = new ClasspathResource(_resolver, path);
 80  
         
 81  0
         _pageRenderSupport.addExternalScript(_form, resource);
 82  0
     }
 83  
     
 84  
     public void addSubmitHandler(String submitListener)
 85  
     {
 86  0
         _pageRenderSupport.addInitializationScript(_form, "Tapestry.onsubmit('" + _formId + "', "
 87  
                 + submitListener + ");");
 88  0
     }
 89  
     
 90  
     public void addInitializationScript(IComponent target, String script)
 91  
     {
 92  0
         _pageRenderSupport.addInitializationScript(_form, script);
 93  0
     }
 94  
     
 95  
     public void registerForFocus(int priority)
 96  
     {
 97  0
         _form.registerForFocus(_field, priority);
 98  0
     }
 99  
 
 100  
     public JSONObject getProfile()
 101  
     {
 102  0
         return _form.getProfile();
 103  
     }
 104  
 }