01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.woody.acting;
18:
19: import org.apache.cocoon.acting.Action;
20: import org.apache.cocoon.environment.Redirector;
21: import org.apache.cocoon.environment.SourceResolver;
22: import org.apache.cocoon.environment.Request;
23: import org.apache.cocoon.environment.ObjectModelHelper;
24: import org.apache.cocoon.woody.FormManager;
25: import org.apache.cocoon.woody.formmodel.Form;
26: import org.apache.excalibur.source.Source;
27: import org.apache.avalon.framework.thread.ThreadSafe;
28: import org.apache.avalon.framework.parameters.Parameters;
29: import org.apache.avalon.framework.service.Serviceable;
30: import org.apache.avalon.framework.service.ServiceManager;
31: import org.apache.avalon.framework.service.ServiceException;
32:
33: import java.util.Map;
34:
35: /**
36: * An action that creates a new form instance and stores it in a request attribute.
37: *
38: * <p>Required parameters:
39: * <ul>
40: * <li><strong>form-definition</strong>: filename (URL) of the form definition file
41: * <li><strong>attribute-name</strong>: name of the request attribute in which to store the form instance
42: * </ul>
43: *
44: * @version $Id: MakeFormAction.java 433543 2006-08-22 06:22:54Z crossley $
45: */
46: public class MakeFormAction implements Action, ThreadSafe, Serviceable {
47:
48: FormManager formManager;
49:
50: public void service(ServiceManager serviceManager)
51: throws ServiceException {
52: formManager = (FormManager) serviceManager
53: .lookup(FormManager.ROLE);
54: }
55:
56: public Map act(Redirector redirector, SourceResolver resolver,
57: Map objectModel, String src, Parameters parameters)
58: throws Exception {
59: String formSource = parameters.getParameter("form-definition");
60: String formAttribute = parameters
61: .getParameter("attribute-name");
62:
63: Source source = null;
64: try {
65: source = resolver.resolveURI(formSource);
66: Form form = formManager.createForm(source);
67:
68: Request request = ObjectModelHelper.getRequest(objectModel);
69: request.setAttribute(formAttribute, form);
70: } finally {
71: resolver.release(source);
72: }
73:
74: return null;
75: }
76:
77: }
|