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 55 public class RepeaterActionDefinitionBuilder extends AbstractWidgetDefinitionBuilder { 56 57 public WidgetDefinition buildWidgetDefinition(Element widgetElement) throws Exception { 58 String actionCommand = DomHelper.getAttribute(widgetElement, "command", null); 60 61 if (actionCommand == null) { 63 actionCommand = DomHelper.getAttribute(widgetElement, "action-command", null); 64 if (actionCommand != null) { 65 Deprecation.logger.info("The 'action-command' attribute is deprecated and replaced by 'command', at " + 66 DomHelper.getLocation(widgetElement)); 67 } 68 } 69 if (actionCommand == null) { 70 throw new Exception ("Missing attribute 'command' at " + DomHelper.getLocation(widgetElement)); 71 } 72 73 74 RepeaterActionDefinition definition = createDefinition(widgetElement, actionCommand); 75 super.setupDefinition(widgetElement, definition); 76 setDisplayData(widgetElement, definition); 77 78 definition.setActionCommand(actionCommand); 79 80 Element buggyOnActivate = DomHelper.getChildElement(widgetElement, FormsConstants.DEFINITION_NS, "on-activate", false); 82 if (buggyOnActivate != null) { 83 throw new Exception ("Use 'on-action' instead of 'on-activate' on row-action at " + 84 DomHelper.getLocation(buggyOnActivate)); 85 } 86 87 Iterator iter = buildEventListeners(widgetElement, "on-action", ActionListener.class).iterator(); 88 while (iter.hasNext()) { 89 definition.addActionListener((ActionListener)iter.next()); 90 } 91 92 definition.makeImmutable(); 93 return definition; 94 } 95 96 protected RepeaterActionDefinition createDefinition(Element element, String actionCommand) throws Exception { 97 98 String repeater = DomHelper.getAttribute(element, "repeater"); 99 if ("delete-rows".equals(actionCommand)) { 100 String select = DomHelper.getAttribute(element, "select"); 101 return new RepeaterActionDefinition.DeleteRowsActionDefinition(repeater, select); 102 103 } else if ("add-row".equals(actionCommand)) { 104 return new RepeaterActionDefinition.AddRowActionDefinition(repeater); 105 106 } else if ("insert-rows".equals(actionCommand)) { 107 String select = DomHelper.getAttribute(element, "select"); 108 return new RepeaterActionDefinition.InsertRowsActionDefinition(repeater, select); 109 110 } else { 111 throw new Exception ("Unknown repeater action '" + actionCommand + "' at " + DomHelper.getLineLocation(element)); 112 } 113 } 114 } 115 | Popular Tags |