001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.forms.binding;
018:
019: import org.apache.cocoon.forms.util.DomHelper;
020:
021: import org.w3c.dom.Element;
022:
023: /**
024: * A simple repeater binding that will replace (i.e. delete then re-add all) its
025: * content.
026: * <pre>
027: * <fb:simple-repeater
028: * id="contacts"
029: * parent-path="contacts">
030: * <<em>... child bindings ...</em>>
031: * </fb:simple-repeater>
032: * </pre>
033: *
034: * @version $Id: SimpleRepeaterJXPathBindingBuilder.java 517733 2007-03-13 15:37:22Z vgritsenko $
035: */
036: public class SimpleRepeaterJXPathBindingBuilder extends
037: JXPathBindingBuilderBase {
038:
039: public JXPathBindingBase buildBinding(Element bindingElem,
040: JXPathBindingManager.Assistant assistant)
041: throws BindingException {
042: try {
043: CommonAttributes commonAtts = JXPathBindingBuilderBase
044: .getCommonAttributes(bindingElem);
045:
046: String repeaterId = DomHelper.getAttribute(bindingElem,
047: "id", null);
048: String parentPath = DomHelper.getAttribute(bindingElem,
049: "parent-path", null);
050: String rowPath = DomHelper.getAttribute(bindingElem,
051: "row-path", null);
052: boolean clearOnLoad = DomHelper.getAttributeAsBoolean(
053: bindingElem, "clear-before-load", true);
054: boolean deleteIfEmpty = DomHelper.getAttributeAsBoolean(
055: bindingElem, "delete-parent-if-empty", false);
056:
057: JXPathBindingBase[] childBindings = null;
058:
059: // do inheritance
060: SimpleRepeaterJXPathBinding otherBinding = (SimpleRepeaterJXPathBinding) assistant
061: .getContext().getSuperBinding();
062: if (otherBinding != null) {
063: childBindings = otherBinding.getChildBindings();
064: commonAtts = JXPathBindingBuilderBase
065: .mergeCommonAttributes(otherBinding
066: .getCommonAtts(), commonAtts);
067:
068: if (parentPath == null) {
069: parentPath = otherBinding.getRepeaterPath();
070: }
071: if (repeaterId == null) {
072: repeaterId = otherBinding.getId();
073: }
074: if (rowPath == null) {
075: rowPath = otherBinding.getRowPath();
076: }
077: if (!bindingElem.hasAttribute("clear-before-load")) {
078: clearOnLoad = otherBinding.getClearOnLoad();
079: }
080: if (!bindingElem.hasAttribute("delete-parent-if-empty")) {
081: deleteIfEmpty = otherBinding.getDeleteIfEmpty();
082: }
083: }
084:
085: childBindings = assistant.makeChildBindings(bindingElem,
086: childBindings);
087:
088: return new SimpleRepeaterJXPathBinding(
089: commonAtts,
090: repeaterId,
091: parentPath,
092: rowPath,
093: clearOnLoad,
094: deleteIfEmpty,
095: new ComposedJXPathBindingBase(
096: JXPathBindingBuilderBase.CommonAttributes.DEFAULT,
097: childBindings));
098: } catch (BindingException e) {
099: throw e;
100: } catch (Exception e) {
101: throw new BindingException(
102: "Error building repeater binding", e, DomHelper
103: .getLocationObject(bindingElem));
104: }
105: }
106: }
|