1 16 package org.apache.cocoon.forms.formmodel; 17 18 import java.util.Iterator ; 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 ; 25 26 31 public class RowActionDefinitionBuilder extends AbstractWidgetDefinitionBuilder { 32 33 34 public WidgetDefinition buildWidgetDefinition(Element widgetElement) throws Exception { 35 String actionCommand = DomHelper.getAttribute(widgetElement, "command", null); 37 38 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 ("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 Element buggyOnActivate = DomHelper.getChildElement(widgetElement, FormsConstants.DEFINITION_NS, "on-activate", false); 58 if (buggyOnActivate != null) { 59 throw new Exception ("Use 'on-action' instead of 'on-activate' on row-action at " + 60 DomHelper.getLocation(buggyOnActivate)); 61 } 62 63 Iterator 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 element, String actionCommand) throws Exception { 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 ("Unknown repeater row action '" + actionCommand + "' at " + DomHelper.getLineLocation(element)); 88 } 89 } 90 } 91 92 | Popular Tags |