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 org.apache.cocoon.woody.util.DomHelper;
20: import org.w3c.dom.Element;
21:
22: /**
23: * An experimental simple repeater binding that will replace
24: * (i.e. delete then re-add all) its content.
25: * Based on SimpleRepeater code.
26: * <pre>
27: * <wb:temp-repeater
28: * id="contacts"
29: * parent-path="contacts">
30: * <<em>... child bindings ...</em>
31: * </wb:temp-repeater>
32: * </pre>
33: *
34: * @author Timothy Larson
35: * @version CVS $Id: TempRepeaterJXPathBindingBuilder.java 433543 2006-08-22 06:22:54Z crossley $
36: */
37: public class TempRepeaterJXPathBindingBuilder extends
38: JXPathBindingBuilderBase {
39:
40: public JXPathBindingBase buildBinding(Element bindingElem,
41: JXPathBindingManager.Assistant assistant)
42: throws BindingException {
43: try {
44: CommonAttributes commonAtts = JXPathBindingBuilderBase
45: .getCommonAttributes(bindingElem);
46:
47: String repeaterId = DomHelper.getAttribute(bindingElem,
48: "id");
49: String parentPath = DomHelper.getAttribute(bindingElem,
50: "parent-path");
51: String rowPath = DomHelper.getAttribute(bindingElem,
52: "row-path");
53: String rowPathInsert = DomHelper.getAttribute(bindingElem,
54: "row-path-insert", rowPath);
55: boolean virtualRows = DomHelper.getAttributeAsBoolean(
56: bindingElem, "virtual-rows", false);
57: boolean clearOnLoad = DomHelper.getAttributeAsBoolean(
58: bindingElem, "clear-before-load", true);
59: boolean deleteIfEmpty = DomHelper.getAttributeAsBoolean(
60: bindingElem, "delete-parent-if-empty", false);
61:
62: Element childWrapElement = DomHelper.getChildElement(
63: bindingElem, BindingManager.NAMESPACE, "on-bind");
64: JXPathBindingBase[] childBindings = assistant
65: .makeChildBindings(childWrapElement);
66:
67: Element insertWrapElement = DomHelper.getChildElement(
68: bindingElem, BindingManager.NAMESPACE,
69: "on-insert-row");
70: JXPathBindingBase[] insertBindings = null;
71: if (insertWrapElement != null) {
72: insertBindings = assistant
73: .makeChildBindings(insertWrapElement);
74: }
75: return new TempRepeaterJXPathBinding(
76: commonAtts,
77: repeaterId,
78: parentPath,
79: rowPath,
80: rowPathInsert,
81: virtualRows,
82: clearOnLoad,
83: deleteIfEmpty,
84: new ComposedJXPathBindingBase(
85: JXPathBindingBuilderBase.CommonAttributes.DEFAULT,
86: childBindings),
87: new ComposedJXPathBindingBase(
88: JXPathBindingBuilderBase.CommonAttributes.DEFAULT,
89: insertBindings));
90: } catch (BindingException e) {
91: throw e;
92: } catch (Exception e) {
93: throw new BindingException(
94: "Error building temp-repeater binding defined at "
95: + DomHelper.getLocation(bindingElem), e);
96: }
97: }
98: }
|