1 16 package org.apache.cocoon.forms.binding; 17 18 import org.apache.cocoon.forms.FormsConstants; 19 import org.apache.cocoon.forms.datatype.convertor.Convertor; 20 import org.apache.cocoon.forms.util.DomHelper; 21 import org.apache.cocoon.i18n.I18nUtils; 22 import org.w3c.dom.Element ; 23 24 import java.util.Locale ; 25 26 42 public class ValueJXPathBindingBuilder extends JXPathBindingBuilderBase { 43 44 48 public JXPathBindingBase buildBinding(Element bindingElm, JXPathBindingManager.Assistant assistant) throws BindingException { 49 50 try { 51 CommonAttributes commonAtts = JXPathBindingBuilderBase.getCommonAttributes(bindingElm); 52 String xpath = DomHelper.getAttribute(bindingElm, "path", null); 53 String widgetId = DomHelper.getAttribute(bindingElm, "id", null); 54 55 Convertor convertor = null; 56 Locale convertorLocale = Locale.US; 57 Element convertorEl = DomHelper.getChildElement(bindingElm, FormsConstants.DEFINITION_NS, "convertor"); 58 if (convertorEl != null) { 59 String datatype = DomHelper.getAttribute(convertorEl, "datatype"); 60 String localeStr = DomHelper.getAttribute(convertorEl, "locale", null); 61 if (localeStr != null) { 62 convertorLocale = I18nUtils.parseLocale(localeStr); 63 } 64 65 convertor = assistant.getDatatypeManager().createConvertor(datatype, convertorEl); 66 } 67 68 ValueJXPathBinding otherBinding = (ValueJXPathBinding)assistant.getContext().getSuperBinding(); 70 JXPathBindingBase[] existingUpdateBindings = null; 71 if(otherBinding!=null) { 72 commonAtts = JXPathBindingBuilderBase.mergeCommonAttributes(otherBinding.getCommonAtts(),commonAtts); 73 74 if(xpath==null) 75 xpath = otherBinding.getXPath(); 76 if(widgetId==null) 77 widgetId = otherBinding.getId(); 78 if(convertor==null) 79 convertor = otherBinding.getConvertor(); 80 if(convertorLocale==null) 81 convertorLocale = otherBinding.getConvertorLocale(); 82 if(convertorLocale==null) 83 convertorLocale = otherBinding.getConvertorLocale(); 84 85 existingUpdateBindings = otherBinding.getUpdateBinding().getChildBindings(); 86 } 87 88 Element updateWrapElement = 89 DomHelper.getChildElement(bindingElm, BindingManager.NAMESPACE, "on-update"); 90 JXPathBindingBase[] updateBindings = assistant.makeChildBindings(updateWrapElement,existingUpdateBindings); 91 92 ValueJXPathBinding fieldBinding = 93 new ValueJXPathBinding(commonAtts, 94 widgetId, xpath, updateBindings, convertor, convertorLocale); 95 96 return fieldBinding; 97 } catch (BindingException e) { 98 throw e; 99 } catch (Exception e) { 100 throw new BindingException("Error building binding defined at " + DomHelper.getLocation(bindingElm), e); 101 } 102 } 103 } 104 | Popular Tags |