01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.woody.binding;
18:
19: import java.util.Locale;
20:
21: import org.apache.cocoon.woody.Constants;
22: import org.apache.cocoon.woody.util.DomHelper;
23: import org.apache.cocoon.woody.datatype.convertor.Convertor;
24: import org.apache.cocoon.i18n.I18nUtils;
25: import org.w3c.dom.Element;
26:
27: /**
28: * A simple multi field binding that will replace (i.e. delete then re-add all) its
29: * content.
30: * <pre><code>
31: * <wb:multi-value id="<i>widget-id</i>"
32: * parent-path="<i>xpath-expression</i>"
33: * row-path="<i>xpath-expression</i>">
34: * <!-- optional child binding to be executed upon 'save' of changed value -->
35: * <wb:on-update>
36: * <!-- any childbinding -->
37: * </wb:on-update>
38: * </wb:multi-value>
39: * </code></pre>
40: *
41: * @version CVS $Id: MultiValueJXPathBindingBuilder.java 433543 2006-08-22 06:22:54Z crossley $
42: */
43: public class MultiValueJXPathBindingBuilder extends
44: JXPathBindingBuilderBase {
45:
46: public JXPathBindingBase buildBinding(Element bindingElem,
47: JXPathBindingManager.Assistant assistant)
48: throws BindingException {
49:
50: try {
51: CommonAttributes commonAtts = JXPathBindingBuilderBase
52: .getCommonAttributes(bindingElem);
53:
54: String multiValueId = DomHelper.getAttribute(bindingElem,
55: "id");
56: String parentPath = DomHelper.getAttribute(bindingElem,
57: "parent-path");
58: String rowPath = DomHelper.getAttribute(bindingElem,
59: "row-path");
60:
61: Element updateWrapElement = DomHelper.getChildElement(
62: bindingElem, BindingManager.NAMESPACE, "on-update");
63: JXPathBindingBase[] updateBindings = assistant
64: .makeChildBindings(updateWrapElement);
65:
66: Convertor convertor = null;
67: Locale convertorLocale = Locale.US;
68: Element convertorEl = DomHelper.getChildElement(
69: bindingElem, Constants.WD_NS, "convertor");
70: if (convertorEl != null) {
71: String datatype = DomHelper.getAttribute(convertorEl,
72: "datatype");
73: String localeStr = convertorEl.getAttribute("datatype");
74: if (!localeStr.equals("")) {
75: convertorLocale = I18nUtils.parseLocale(localeStr);
76: }
77:
78: convertor = assistant.getDatatypeManager()
79: .createConvertor(datatype, convertorEl);
80: }
81:
82: return new MultiValueJXPathBinding(commonAtts,
83: multiValueId, parentPath, rowPath, updateBindings,
84: convertor, convertorLocale);
85: } catch (BindingException e) {
86: throw e;
87: } catch (Exception e) {
88: throw new BindingException(
89: "Error building multi value binding defined at "
90: + DomHelper.getLocation(bindingElem), e);
91: }
92: }
93: }
|