01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.forms.formmodel;
18:
19: import java.util.Iterator;
20:
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;
25:
26: /**
27: * Builds {@link ActionDefinition}s.
28: *
29: * @version $Id: ActionDefinitionBuilder.java 517843 2007-03-13 20:09:32Z vgritsenko $
30: */
31: public class ActionDefinitionBuilder extends
32: AbstractWidgetDefinitionBuilder {
33:
34: public WidgetDefinition buildWidgetDefinition(Element widgetElement)
35: throws Exception {
36: ActionDefinition definition = new ActionDefinition();
37: setupDefinition(widgetElement, definition);
38: definition.makeImmutable();
39: return definition;
40: }
41:
42: protected void setupDefinition(Element widgetElement,
43: ActionDefinition definition) throws Exception {
44: super .setupDefinition(widgetElement, definition);
45:
46: setDisplayData(widgetElement, definition);
47:
48: // Get the "command" optional attribute
49: String actionCommand = DomHelper.getAttribute(widgetElement,
50: "command", null);
51:
52: // If unspecified, check the deprecated "action-command" deprecated attribute
53: if (actionCommand == null) {
54: actionCommand = DomHelper.getAttribute(widgetElement,
55: "action-command", null);
56: if (actionCommand != null) {
57: Deprecation.logger
58: .info("The 'action-command' attribute is deprecated and replaced by 'command', at "
59: + DomHelper.getLocation(widgetElement));
60: }
61: }
62:
63: definition.setActionCommand(actionCommand);
64:
65: Iterator i = buildEventListeners(widgetElement, "on-action",
66: ActionListener.class).iterator();
67: while (i.hasNext()) {
68: definition.addActionListener((ActionListener) i.next());
69: }
70: }
71: }
|