1 16 package org.apache.cocoon.woody.acting; 17 18 import org.apache.avalon.framework.thread.ThreadSafe; 19 import org.apache.avalon.framework.parameters.Parameters; 20 import org.apache.cocoon.acting.Action; 21 import org.apache.cocoon.environment.Redirector; 22 import org.apache.cocoon.environment.SourceResolver; 23 import org.apache.cocoon.environment.Request; 24 import org.apache.cocoon.environment.ObjectModelHelper; 25 import org.apache.cocoon.woody.FormContext; 26 import org.apache.cocoon.woody.event.FormHandler; 27 import org.apache.cocoon.woody.formmodel.Form; 28 import org.apache.cocoon.i18n.I18nUtils; 29 import org.apache.cocoon.components.LifecycleHelper; 30 import org.apache.excalibur.source.Source; 31 32 import java.util.Map ; 33 import java.util.Collections ; 34 import java.util.Locale ; 35 36 50 public class HandleFormSubmitAction extends AbstractWoodyAction implements Action, ThreadSafe { 51 52 public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters parameters) 53 throws Exception { 54 String formSource = parameters.getParameter("form-definition"); 55 String formAttribute = parameters.getParameter("attribute-name"); 56 String formHandlerClassName = parameters.getParameter("formhandler", null); 57 58 Locale locale = Locale.getDefault(); 59 String localeStr = parameters.getParameter("locale", null); 60 if (localeStr != null) 61 locale = I18nUtils.parseLocale(localeStr, locale); 62 63 Source source = resolver.resolveURI(formSource); 64 try { 65 Form form = formManager.createForm(source); 66 67 Request request = ObjectModelHelper.getRequest(objectModel); 68 FormHandler formHandler = null; 69 70 if (formHandlerClassName != null) { 71 Class clazz = Class.forName(formHandlerClassName); 73 formHandler = (FormHandler)clazz.newInstance(); 74 LifecycleHelper.setupComponent(formHandler, null, null, manager, null, null); 75 form.setFormHandler(formHandler); 76 } 77 78 FormContext formContext = new FormContext(request, locale); 79 80 boolean finished = form.process(formContext); 81 request.setAttribute(formAttribute, form); 82 83 if (finished) 84 return Collections.EMPTY_MAP; 85 else 86 return null; 87 } finally { 88 resolver.release(source); 89 } 90 } 91 } 92 | Popular Tags |