1 16 package org.apache.cocoon.woody.formmodel; 17 18 import org.apache.cocoon.environment.Request; 19 import org.apache.cocoon.woody.FormContext; 20 import org.apache.cocoon.woody.Constants; 21 import org.apache.cocoon.woody.event.ActionEvent; 22 import org.apache.cocoon.woody.event.WidgetEvent; 23 import org.apache.cocoon.xml.AttributesImpl; 24 import org.xml.sax.ContentHandler ; 25 import org.xml.sax.SAXException ; 26 27 import java.util.Locale ; 28 29 40 public class Action extends AbstractWidget { 41 protected ActionDefinition definition; 42 43 public Action(ActionDefinition definition) { 44 this.definition = definition; 45 setLocation(definition.getLocation()); 46 } 47 48 public String getId() { 49 return definition.getId(); 50 } 51 52 public void readFromRequest(final FormContext formContext) { 53 Form form = getForm(); 54 55 String fullId = getFullyQualifiedId(); 57 Request request = formContext.getRequest(); 58 59 String value = request.getParameter(fullId); 60 if (value != null && value.length() > 0) { 61 form.setSubmitWidget(this); 62 63 } else { 64 value = request.getParameter(fullId + ".x"); 71 if ((value != null) && value.length() > 0) { 72 form.setSubmitWidget(this); 73 } 74 } 75 76 if (form.getSubmitWidget() == this) { 77 form.addWidgetEvent(new ActionEvent(this, definition.getActionCommand())); 78 79 handleActivate(); 80 } 81 } 82 83 88 protected void handleActivate() { 89 getForm().endProcessing(true); 90 } 91 92 97 public boolean validate(FormContext formContext) { 98 return true; 99 } 100 101 private static final String ACTION_EL = "action"; 102 103 public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { 104 AttributesImpl buttonAttrs = new AttributesImpl(); 105 buttonAttrs.addCDATAAttribute("id", getFullyQualifiedId()); 106 contentHandler.startElement(Constants.WI_NS, ACTION_EL, Constants.WI_PREFIX_COLON + ACTION_EL, buttonAttrs); 107 definition.generateDisplayData(contentHandler); 109 contentHandler.endElement(Constants.WI_NS, ACTION_EL, Constants.WI_PREFIX_COLON + ACTION_EL); 110 } 111 112 public void generateLabel(ContentHandler contentHandler) throws SAXException { 113 definition.generateLabel(contentHandler); 114 } 115 116 public void broadcastEvent(WidgetEvent event) { 117 this.definition.fireActionEvent((ActionEvent)event); 118 } 119 } 120 | Popular Tags |