KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > acting > MakeFormAction


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.forms.acting;
17
18 import org.apache.cocoon.acting.Action;
19 import org.apache.cocoon.environment.Redirector;
20 import org.apache.cocoon.environment.SourceResolver;
21 import org.apache.cocoon.environment.Request;
22 import org.apache.cocoon.environment.ObjectModelHelper;
23 import org.apache.cocoon.forms.FormManager;
24 import org.apache.cocoon.forms.formmodel.Form;
25 import org.apache.excalibur.source.Source;
26 import org.apache.avalon.framework.thread.ThreadSafe;
27 import org.apache.avalon.framework.parameters.Parameters;
28 import org.apache.avalon.framework.service.Serviceable;
29 import org.apache.avalon.framework.service.ServiceManager;
30 import org.apache.avalon.framework.service.ServiceException;
31
32 import java.util.Map JavaDoc;
33
34 /**
35  * An action that creates a new form instance and stores it in a request attribute.
36  *
37  * <p>Required parameters:
38  * <ul>
39  * <li><strong>form-definition</strong>: filename (URL) of the form definition file
40  * <li><strong>attribute-name</strong>: name of the request attribute in which to store the form instance
41  * </ul>
42  *
43  * @version $Id: MakeFormAction.java 56582 2004-11-04 10:16:22Z sylvain $
44  */

45 public class MakeFormAction implements Action, ThreadSafe, Serviceable {
46
47     FormManager formManager;
48
49     public void service(ServiceManager serviceManager) throws ServiceException {
50         formManager = (FormManager)serviceManager.lookup(FormManager.ROLE);
51     }
52
53     public Map JavaDoc act(Redirector redirector, SourceResolver resolver, Map JavaDoc objectModel, String JavaDoc src, Parameters parameters)
54             throws Exception JavaDoc {
55         String JavaDoc formSource = parameters.getParameter("form-definition");
56         String JavaDoc formAttribute = parameters.getParameter("attribute-name");
57
58         Source source = null;
59         try {
60             source = resolver.resolveURI(formSource);
61             Form form = formManager.createForm(source);
62
63             Request request = ObjectModelHelper.getRequest(objectModel);
64             request.setAttribute(formAttribute, form);
65         } finally {
66             resolver.release(source);
67         }
68
69         return null;
70     }
71
72 }
73
Popular Tags