1 16 package org.apache.cocoon.woody.binding; 17 18 import org.apache.cocoon.woody.formmodel.Widget; 19 import org.apache.cocoon.woody.datatype.convertor.Convertor; 20 import org.apache.commons.jxpath.JXPathContext; 21 22 import java.util.Locale ; 23 24 34 public class UniqueFieldJXPathBinding extends JXPathBindingBase { 35 36 39 private final String xpath; 40 41 44 private final String fieldId; 45 46 51 private final Convertor convertor; 52 53 56 private final Locale convertorLocale; 57 58 63 public UniqueFieldJXPathBinding(JXPathBindingBuilderBase.CommonAttributes commonAtts, String widgetId, String xpath, 64 Convertor convertor, Locale convertorLocale) { 65 super(commonAtts); 66 this.fieldId = widgetId; 67 this.xpath = xpath; 68 this.convertor = convertor; 69 this.convertorLocale = convertorLocale; 70 } 71 72 76 public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException { 77 Widget widget = frmModel.getWidget(this.fieldId); 78 if (widget == null) { 79 throw new BindingException("The widget with the ID [" + this.fieldId 80 + "] referenced in the binding does not exist in the form definition."); 81 } 82 83 Object value = jxpc.getValue(this.xpath); 84 if (value != null && convertor != null) { 85 if (value instanceof String ) { 86 value = convertor.convertFromString((String )value, convertorLocale, null); 87 } else { 88 getLogger().warn("Convertor ignored on backend-value which isn't of type String."); 89 } 90 } 91 92 widget.setValue(value); 93 if (getLogger().isDebugEnabled()) { 94 getLogger().debug("Done loading " + toString() + " -- value= " + value); 95 } 96 } 97 98 102 public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException { 103 } 105 106 public String toString() { 107 return "UniqueFieldJXPathBinding [widget=" + this.fieldId + ", xpath=" + this.xpath + "]"; 108 } 109 110 113 116 public Convertor getConvertor() { 117 return convertor; 118 } 119 122 public Locale getConvertorLocale() { 123 return convertorLocale; 124 } 125 128 public String getFieldId() { 129 return fieldId; 130 } 131 134 public String getXpath() { 135 return xpath; 136 } 137 } 138 | Popular Tags |