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: * A simple repeater binding that will replace (i.e. delete then re-add all) its
24: * content.
25: * <pre>
26: * <wb:simple-repeater
27: * id="contacts"
28: * parent-path="contacts">
29: * <<em>... child bindings ...</em>
30: * </wb:simple-repeater>
31: * </pre>
32: *
33: * @author <a href="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
34: * @version CVS $Id: SimpleRepeaterJXPathBindingBuilder.java 433543 2006-08-22 06:22:54Z crossley $
35: */
36: public class SimpleRepeaterJXPathBindingBuilder extends
37: JXPathBindingBuilderBase {
38:
39: public JXPathBindingBase buildBinding(Element bindingElem,
40: JXPathBindingManager.Assistant assistant)
41: throws BindingException {
42: try {
43: CommonAttributes commonAtts = JXPathBindingBuilderBase
44: .getCommonAttributes(bindingElem);
45:
46: String repeaterId = DomHelper.getAttribute(bindingElem,
47: "id");
48: String parentPath = DomHelper.getAttribute(bindingElem,
49: "parent-path");
50: String rowPath = DomHelper.getAttribute(bindingElem,
51: "row-path");
52: boolean clearOnLoad = DomHelper.getAttributeAsBoolean(
53: bindingElem, "clear-before-load", true);
54: boolean deleteIfEmpty = DomHelper.getAttributeAsBoolean(
55: bindingElem, "delete-parent-if-empty", false);
56:
57: JXPathBindingBase[] childBindings = assistant
58: .makeChildBindings(bindingElem);
59:
60: return new SimpleRepeaterJXPathBinding(
61: commonAtts,
62: repeaterId,
63: parentPath,
64: rowPath,
65: clearOnLoad,
66: deleteIfEmpty,
67: new ComposedJXPathBindingBase(
68: JXPathBindingBuilderBase.CommonAttributes.DEFAULT,
69: childBindings));
70: } catch (BindingException e) {
71: throw e;
72: } catch (Exception e) {
73: throw new BindingException(
74: "Error building repeater binding defined at "
75: + DomHelper.getLocation(bindingElem), e);
76: }
77: }
78: }
|