KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > webapps > session > acting > SessionFormAction


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.webapps.session.acting;
17
18 import org.apache.avalon.framework.configuration.Configuration;
19 import org.apache.avalon.framework.parameters.Parameters;
20 import org.apache.avalon.framework.thread.ThreadSafe;
21
22 import org.apache.cocoon.acting.FormValidatorAction;
23 import org.apache.cocoon.environment.ObjectModelHelper;
24 import org.apache.cocoon.environment.Session;
25 import org.apache.cocoon.environment.SourceResolver;
26 import org.apache.cocoon.webapps.session.SessionConstants;
27
28 import java.util.Map JavaDoc;
29
30 /**
31  * This is the action used to validate Request parameters.
32  * The validation rules are either embedded within the form
33  *
34  * <pre>
35  * &lt;session:form name="info_form"&gt;
36  * &lt;session:action&gt;next_page&lt;/session:action&gt;
37  * &lt;session:content&gt;
38  * &lt;session:inputxml name="name" type="text" context="trackdemo" path="/user/name"/&gt;
39  * &lt;/session:content&gt;
40  * &lt;session:validate&gt;
41  * &lt;root&gt;
42  * &lt;parameter name="name" type="string" nullable="no"/&gt;
43  * &lt;constraint-set name="form_a_set"&gt;
44  * &lt;validate name="name"/&gt;
45  * &lt;/constraint-set&gt;
46  * &lt;/root&gt;
47  * &lt;/session:validate&gt;
48  * &lt;/session:form&gt;
49  * </pre>
50  *
51  * or described via the external xml file referenced
52  * through the "src" attribute
53  * (the format is defined in AbstractValidatorAction).
54  * Then the constraint-set to be used has to be identified
55  * through the "constraint-set" element
56  *
57  * <pre>
58  * &lt;session:form name="info_form&gt;
59  * &lt;session:action&gt;next_page&lt;/session:action&gt;
60  * &lt;session:content&gt;
61  * &lt;session:inputxml name="name" type="text" context="trackdemo" path="/user/name"/&gt;
62  * &lt;/session:content&gt;
63  * &lt;session:validate SRC="descriptor.xml"&gt;
64  * &lt;constraint-set name="form_a_set"/&gt;
65  * &lt;/session:validate&gt;
66  * &lt;/session:form&gt;
67  * </pre>
68  *
69  * Since the validation rules are contained within the form document
70  * they are read and supplied by the SessionTransformer.
71  * So this action has to be used in conjunction with the SessionTransformer.
72  * The "next_page" pipeline might look like this:
73  *
74  * <pre>
75  * &lt;map:match pattern="next_page"&gt;
76  * &lt;map:act type="session-form"&gt;
77  * &lt;map:generate SRC="next_page.xml"/&gt;
78  * &lt;map:transform type="session"/&gt;
79  * &lt;map:transform SRC="simple2html.xsl"/&gt;
80  * &lt;map:serialize/&gt;
81  * &lt;/map:act&gt;
82  * &lt;map:generate SRC="first_page.xml"/&gt;
83  * &lt;map:transform type="session"/&gt;
84  * &lt;map:transform SRC="simple2html.xsl"/&gt;
85  * &lt;map:serialize/&gt;
86  * &lt;/map:match&gt;
87  * </pre>
88  *
89  * where "session-form" is configured as SessionFormAction
90  *
91  * @see org.apache.cocoon.acting.FormValidatorAction
92  * @see org.apache.cocoon.acting.AbstractValidatorAction
93  *
94  * @author <a HREF="mailto:gcasper@s-und-n.de">Guido Casper</a>
95  * @author <a HREF="mailto:haul@apache.org">Christian Haul</a>
96  * @version CVS $Id: SessionFormAction.java 30932 2004-07-29 17:35:38Z vgritsenko $
97 */

98 public class SessionFormAction extends FormValidatorAction implements ThreadSafe {
99
100     /* (non-Javadoc)
101      * @see org.apache.cocoon.acting.AbstractValidatorAction#getDescriptor(org.apache.cocoon.environment.SourceResolver, org.apache.avalon.framework.parameters.Parameters)
102      */

103     protected Configuration getDescriptor(
104         SourceResolver resolver,
105         Map JavaDoc objectModel,
106         Parameters parameters) {
107
108         Session session = ObjectModelHelper.getRequest(objectModel).getSession(true);
109         return (Configuration) session.getAttribute(
110             ObjectModelHelper.getRequest(objectModel).getParameter(
111                 SessionConstants.SESSION_FORM_PARAMETER));
112     }
113
114 }
115
Popular Tags