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: * An experimental simple repeater binding that will replace
025: * (i.e. delete then re-add all) its content.
026: * Based on SimpleRepeater code.
027: * <pre>
028: * <fb:temp-repeater
029: * id="contacts"
030: * parent-path="contacts">
031: * <<em>... child bindings ...</em>>
032: * </fb:temp-repeater>
033: * </pre>
034: *
035: * @version $Id: TempRepeaterJXPathBindingBuilder.java 517733 2007-03-13 15:37:22Z vgritsenko $
036: */
037: public class TempRepeaterJXPathBindingBuilder extends
038: JXPathBindingBuilderBase {
039:
040: public JXPathBindingBase buildBinding(Element bindingElem,
041: JXPathBindingManager.Assistant assistant)
042: throws BindingException {
043: try {
044: CommonAttributes commonAtts = JXPathBindingBuilderBase
045: .getCommonAttributes(bindingElem);
046:
047: String repeaterId = DomHelper.getAttribute(bindingElem,
048: "id", null);
049: String parentPath = DomHelper.getAttribute(bindingElem,
050: "parent-path", null);
051: String rowPath = DomHelper.getAttribute(bindingElem,
052: "row-path", null);
053: String rowPathInsert = DomHelper.getAttribute(bindingElem,
054: "row-path-insert", rowPath);
055: boolean virtualRows = DomHelper.getAttributeAsBoolean(
056: bindingElem, "virtual-rows", false);
057: boolean clearOnLoad = DomHelper.getAttributeAsBoolean(
058: bindingElem, "clear-before-load", true);
059: boolean deleteIfEmpty = DomHelper.getAttributeAsBoolean(
060: bindingElem, "delete-parent-if-empty", false);
061:
062: JXPathBindingBase[] insertBindings = null;
063: JXPathBindingBase[] childBindings = null;
064:
065: // do inheritance
066: TempRepeaterJXPathBinding otherBinding = (TempRepeaterJXPathBinding) assistant
067: .getContext().getSuperBinding();
068: if (otherBinding != null) {
069: childBindings = otherBinding.getChildBindings();
070: insertBindings = otherBinding.getInsertChildBindings();
071: commonAtts = JXPathBindingBuilderBase
072: .mergeCommonAttributes(otherBinding
073: .getCommonAtts(), commonAtts);
074:
075: if (parentPath == null) {
076: parentPath = otherBinding.getRepeaterPath();
077: }
078: if (repeaterId == null) {
079: repeaterId = otherBinding.getId();
080: }
081: if (rowPath == null) {
082: rowPath = otherBinding.getRowPath();
083: }
084: if (rowPathInsert == null) {
085: rowPathInsert = otherBinding.getRowPathInsert();
086: }
087: if (!bindingElem.hasAttribute("virtual-rows")) {
088: clearOnLoad = otherBinding.getVirtualRows();
089: }
090: if (!bindingElem.hasAttribute("clear-before-load")) {
091: clearOnLoad = otherBinding.getClearOnLoad();
092: }
093: if (!bindingElem.hasAttribute("delete-parent-if-empty")) {
094: deleteIfEmpty = otherBinding.getDeleteIfEmpty();
095: }
096: }
097:
098: Element childWrapElement = DomHelper.getChildElement(
099: bindingElem, BindingManager.NAMESPACE, "on-bind");
100: childBindings = assistant.makeChildBindings(
101: childWrapElement, childBindings);
102:
103: Element insertWrapElement = DomHelper.getChildElement(
104: bindingElem, BindingManager.NAMESPACE,
105: "on-insert-row");
106:
107: if (insertWrapElement != null) {
108: insertBindings = assistant.makeChildBindings(
109: insertWrapElement, insertBindings);
110: }
111: return new TempRepeaterJXPathBinding(
112: commonAtts,
113: repeaterId,
114: parentPath,
115: rowPath,
116: rowPathInsert,
117: virtualRows,
118: clearOnLoad,
119: deleteIfEmpty,
120: new ComposedJXPathBindingBase(
121: JXPathBindingBuilderBase.CommonAttributes.DEFAULT,
122: childBindings),
123: new ComposedJXPathBindingBase(
124: JXPathBindingBuilderBase.CommonAttributes.DEFAULT,
125: insertBindings));
126: } catch (BindingException e) {
127: throw e;
128: } catch (Exception e) {
129: throw new BindingException(
130: "Error building temp-repeater binding", e,
131: DomHelper.getLocationObject(bindingElem));
132: }
133: }
134: }
|