KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > formmodel > RepeaterActionDefinitionBuilder


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.formmodel;
17
18 import java.util.Iterator JavaDoc;
19
20 import org.apache.cocoon.woody.event.ActionListener;
21 import org.apache.cocoon.woody.util.DomHelper;
22 import org.w3c.dom.Element JavaDoc;
23
24 /**
25  * Builds a <code>&lt;wd:repeater-action/></code>
26  * <p>
27  * Two actions are defined :
28  * <ul>
29  * <li><code>&lt;wd:repeater-action id="add" action-command="add-row" repeater="repeater-id"/></code> :
30  * when activated, adds a row to the sibling repeater named "repeater-id".
31  * </li>
32  * <li><code>&lt;wd:repeater-action id="rm" action-command="delete-rows" repeater="repeater-id"
33  * select="select-id"/></code> : removes the selected rows from the sibling repeater named "repeater-id".
34  * The selected rows are identified by the boolean field "select-id" present in each row.
35  * </ul>
36  *
37  * @author <a HREF="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
38  * @version CVS $Id: RepeaterActionDefinitionBuilder.java 30932 2004-07-29 17:35:38Z vgritsenko $
39  */

40 public class RepeaterActionDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
41     
42     
43     public WidgetDefinition buildWidgetDefinition(Element JavaDoc widgetElement) throws Exception JavaDoc {
44         String JavaDoc actionCommand = DomHelper.getAttribute(widgetElement, "action-command");
45         RepeaterActionDefinition definition = createDefinition(widgetElement, actionCommand);
46         setLocation(widgetElement, definition);
47         setId(widgetElement, definition);
48         setDisplayData(widgetElement, definition);
49         setValidators(widgetElement, definition);
50
51         definition.setActionCommand(actionCommand);
52
53         Iterator JavaDoc iter = buildEventListeners(widgetElement, "on-activate", ActionListener.class).iterator();
54         while (iter.hasNext()) {
55             definition.addActionListener((ActionListener)iter.next());
56         }
57
58         return definition;
59     }
60     
61     protected RepeaterActionDefinition createDefinition(Element JavaDoc element, String JavaDoc actionCommand) throws Exception JavaDoc {
62         
63         if ("delete-rows".equals(actionCommand)) {
64             String JavaDoc repeater = DomHelper.getAttribute(element, "repeater");
65             String JavaDoc select = DomHelper.getAttribute(element, "select");
66             return new DeleteRowsActionDefinition(repeater, select);
67
68         } else if ("add-row".equals(actionCommand)) {
69             String JavaDoc repeater = DomHelper.getAttribute(element, "repeater");
70             return new AddRowActionDefinition(repeater);
71             
72         } else {
73             throw new Exception JavaDoc("Unknown repeater action '" + actionCommand + "' at " + DomHelper.getLineLocation(element));
74         }
75     }
76 }
77
Popular Tags