KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > formmodel > RowActionDefinitionBuilder


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.forms.formmodel;
17
18 import java.util.Iterator JavaDoc;
19
20 import org.apache.cocoon.forms.FormsConstants;
21 import org.apache.cocoon.forms.event.ActionListener;
22 import org.apache.cocoon.forms.util.DomHelper;
23 import org.apache.cocoon.util.Deprecation;
24 import org.w3c.dom.Element JavaDoc;
25
26 /**
27  *
28  * @author <a HREF="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
29  * @version $Id: RowActionDefinitionBuilder.java 326838 2005-10-20 06:26:53Z sylvain $
30  */

31 public class RowActionDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
32     
33     
34     public WidgetDefinition buildWidgetDefinition(Element JavaDoc widgetElement) throws Exception JavaDoc {
35         // Get the "command" attribute
36
String JavaDoc actionCommand = DomHelper.getAttribute(widgetElement, "command", null);
37         
38         // If unspecified, check the deprecated "action-command" deprecated attribute
39
if (actionCommand == null) {
40             actionCommand = DomHelper.getAttribute(widgetElement, "action-command", null);
41             if (actionCommand != null) {
42                 Deprecation.logger.info("The 'action-command' attribute is deprecated and replaced by 'command', at " +
43                     DomHelper.getLocation(widgetElement));
44             }
45         }
46         if (actionCommand == null) {
47             throw new Exception JavaDoc("Missing attribute 'command' at " + DomHelper.getLocation(widgetElement));
48         }
49
50         RowActionDefinition definition = createDefinition(widgetElement, actionCommand);
51         super.setupDefinition(widgetElement, definition);
52         setDisplayData(widgetElement, definition);
53
54         definition.setActionCommand(actionCommand);
55
56         // Warn of the mis-named 'on-action' that existed initially
57
Element JavaDoc buggyOnActivate = DomHelper.getChildElement(widgetElement, FormsConstants.DEFINITION_NS, "on-activate", false);
58         if (buggyOnActivate != null) {
59             throw new Exception JavaDoc("Use 'on-action' instead of 'on-activate' on row-action at " +
60                 DomHelper.getLocation(buggyOnActivate));
61         }
62
63         Iterator JavaDoc iter = buildEventListeners(widgetElement, "on-action", ActionListener.class).iterator();
64         while (iter.hasNext()) {
65             definition.addActionListener((ActionListener)iter.next());
66         }
67
68         definition.makeImmutable();
69         return definition;
70     }
71     
72     protected RowActionDefinition createDefinition(Element JavaDoc element, String JavaDoc actionCommand) throws Exception JavaDoc {
73
74         if ("delete".equals(actionCommand)) {
75             return new RowActionDefinition.DeleteRowDefinition();
76
77         } else if ("add-after".equals(actionCommand)) {
78             return new RowActionDefinition.AddAfterDefinition();
79
80         } else if ("move-up".equals(actionCommand)) {
81             return new RowActionDefinition.MoveUpDefinition();
82
83         } else if ("move-down".equals(actionCommand)) {
84             return new RowActionDefinition.MoveDownDefinition();
85
86         } else {
87             throw new Exception JavaDoc("Unknown repeater row action '" + actionCommand + "' at " + DomHelper.getLineLocation(element));
88         }
89     }
90 }
91
92
Popular Tags