1 16 package org.apache.cocoon.woody.binding; 17 18 import java.util.Locale ; 19 20 import org.apache.cocoon.i18n.I18nUtils; 21 import org.apache.cocoon.woody.Constants; 22 import org.apache.cocoon.woody.datatype.convertor.Convertor; 23 import org.apache.cocoon.woody.util.DomHelper; 24 import org.w3c.dom.Element ; 25 26 56 public class RepeaterJXPathBindingBuilder extends JXPathBindingBuilderBase { 57 58 66 public JXPathBindingBase buildBinding(Element bindingElm, 67 JXPathBindingManager.Assistant assistant) throws BindingException { 68 69 try { 70 CommonAttributes commonAtts = 71 JXPathBindingBuilderBase.getCommonAttributes(bindingElm); 72 73 String repeaterId = DomHelper.getAttribute(bindingElm, "id"); 74 String parentPath = 75 DomHelper.getAttribute(bindingElm, "parent-path"); 76 String rowPath = DomHelper.getAttribute(bindingElm, "row-path"); 77 String rowPathForInsert = 78 DomHelper.getAttribute(bindingElm, "row-path-insert", rowPath); 79 String uniqueRowId = 80 DomHelper.getAttribute(bindingElm, "unique-row-id", null); 81 String uniqueRowIdPath = 82 DomHelper.getAttribute(bindingElm, "unique-path", null); 83 84 Convertor convertor = null; 85 Locale convertorLocale = Locale.US; 86 Element convertorEl = 87 DomHelper.getChildElement(bindingElm, 88 Constants.WD_NS, "convertor"); 89 if (convertorEl != null) { 90 String datatype = 91 DomHelper.getAttribute(convertorEl, "datatype"); 92 String localeStr = convertorEl.getAttribute("datatype"); 93 if (!localeStr.equals("")) { 94 convertorLocale = I18nUtils.parseLocale(localeStr); 95 } 96 convertor = 97 assistant.getDatatypeManager().createConvertor(datatype, 98 convertorEl); 99 } 100 101 Element childWrapElement = DomHelper.getChildElement(bindingElm, 102 BindingManager.NAMESPACE, "on-bind"); 103 if (childWrapElement == null) { 104 throw new BindingException( 105 "RepeaterBinding misses '<on-bind>' child definition. " + 106 DomHelper.getLocation(bindingElm)); 107 } 108 JXPathBindingBase[] childBindings = 109 assistant.makeChildBindings(childWrapElement); 110 111 Element deleteWrapElement = DomHelper.getChildElement(bindingElm, 112 BindingManager.NAMESPACE, "on-delete-row"); 113 JXPathBindingBase[] deleteBindings = null; 114 if (deleteWrapElement != null) { 115 deleteBindings = 116 assistant.makeChildBindings(deleteWrapElement); 117 } 118 119 Element insertWrapElement = DomHelper.getChildElement(bindingElm, 120 BindingManager.NAMESPACE, "on-insert-row"); 121 JXPathBindingBase insertBinding = null; 122 if (insertWrapElement != null) { 123 insertBinding = 124 assistant.makeChildBindings(insertWrapElement)[0]; 125 } 126 127 Element uniqueFieldWrapElement = DomHelper.getChildElement(bindingElm, 128 BindingManager.NAMESPACE, "unique-row"); 129 JXPathBindingBase[] uniqueFieldBinding = null; 130 if (uniqueFieldWrapElement != null) { 131 uniqueFieldBinding = assistant.makeChildBindings(uniqueFieldWrapElement); 132 } else if (uniqueRowId == null || uniqueRowIdPath == null) { 133 throw new BindingException( 134 "RepeaterBinding misses '<unique-row>' child definition. " + 135 DomHelper.getLocation(bindingElm)); 136 } else { 137 if (this.getLogger().isInfoEnabled()) { 138 this.getLogger().info("<wb:repeater>: The attributes 'unique-row-id' and " + 139 "'unique-path' are deprecated. Use <unique-row> child element instead." + 140 " Located at " + DomHelper.getLocation(bindingElm)); 141 } 142 } 143 144 RepeaterJXPathBinding repeaterBinding = 145 new RepeaterJXPathBinding(commonAtts, repeaterId, parentPath, 146 rowPath, rowPathForInsert, uniqueRowId, 147 uniqueRowIdPath, convertor, convertorLocale, 148 childBindings, insertBinding, deleteBindings, uniqueFieldBinding); 149 return repeaterBinding; 150 } catch (BindingException e) { 151 throw e; 152 } catch (Exception e) { 153 throw new BindingException( 154 "Error building repeater binding defined at " + 155 DomHelper.getLocation(bindingElm), e); 156 } 157 } 158 } 159 | Popular Tags |