KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > binding > TempRepeaterJXPathBindingBuilder


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.woody.binding;
17
18 import org.apache.cocoon.woody.util.DomHelper;
19 import org.w3c.dom.Element JavaDoc;
20
21 /**
22  * An experimental simple repeater binding that will replace
23  * (i.e. delete then re-add all) its content.
24  * Based on SimpleRepeater code.
25  * <pre>
26  * &lt;wb:temp-repeater
27  * id="contacts"
28  * parent-path="contacts"&gt;
29  * &lt;<em>... child bindings ...</em>
30  * &lt;/wb:temp-repeater&gt;
31  * </pre>
32  *
33  * @author Timothy Larson
34  * @version CVS $Id: TempRepeaterJXPathBindingBuilder.java 30932 2004-07-29 17:35:38Z vgritsenko $
35  */

36 public class TempRepeaterJXPathBindingBuilder
37     extends JXPathBindingBuilderBase {
38
39     public JXPathBindingBase buildBinding(Element JavaDoc bindingElem,
40         JXPathBindingManager.Assistant assistant) throws BindingException {
41         try {
42             CommonAttributes commonAtts = JXPathBindingBuilderBase.getCommonAttributes(bindingElem);
43
44             String JavaDoc repeaterId = DomHelper.getAttribute(bindingElem, "id");
45             String JavaDoc parentPath = DomHelper.getAttribute(bindingElem,
46                     "parent-path");
47             String JavaDoc rowPath = DomHelper.getAttribute(bindingElem, "row-path");
48             String JavaDoc rowPathInsert = DomHelper.getAttribute(bindingElem,
49                     "row-path-insert", rowPath);
50             boolean virtualRows = DomHelper.getAttributeAsBoolean(
51                     bindingElem, "virtual-rows", false);
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             Element JavaDoc childWrapElement = DomHelper.getChildElement(
58                     bindingElem, BindingManager.NAMESPACE, "on-bind");
59             JXPathBindingBase[] childBindings =
60                     assistant.makeChildBindings(childWrapElement);
61
62             Element JavaDoc insertWrapElement = DomHelper.getChildElement(bindingElem,
63                     BindingManager.NAMESPACE, "on-insert-row");
64             JXPathBindingBase[] insertBindings = null;
65             if (insertWrapElement != null) {
66                 insertBindings =
67                     assistant.makeChildBindings(insertWrapElement);
68             }
69             return new TempRepeaterJXPathBinding(commonAtts, repeaterId,
70                     parentPath, rowPath, rowPathInsert, virtualRows,
71                     clearOnLoad, deleteIfEmpty,
72                     new ComposedJXPathBindingBase(
73                             JXPathBindingBuilderBase.CommonAttributes.DEFAULT,
74                             childBindings),
75                     new ComposedJXPathBindingBase(
76                             JXPathBindingBuilderBase.CommonAttributes.DEFAULT,
77                             insertBindings));
78         } catch (BindingException e) {
79             throw e;
80         } catch (Exception JavaDoc e) {
81             throw new BindingException(
82                     "Error building temp-repeater binding defined at " +
83                     DomHelper.getLocation(bindingElem), e);
84         }
85     }
86 }
87
Popular Tags