001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.webapps.session.acting;
018:
019: import org.apache.avalon.framework.configuration.Configuration;
020: import org.apache.avalon.framework.parameters.Parameters;
021:
022: import org.apache.cocoon.acting.FormValidatorAction;
023: import org.apache.cocoon.environment.ObjectModelHelper;
024: import org.apache.cocoon.environment.Session;
025: import org.apache.cocoon.environment.SourceResolver;
026: import org.apache.cocoon.webapps.session.SessionConstants;
027:
028: import java.util.Map;
029:
030: /**
031: * This is the action used to validate Request parameters.
032: * The validation rules are either embedded within the form
033: *
034: * <pre>
035: * <session:form name="info_form">
036: * <session:action>next_page</session:action>
037: * <session:content>
038: * <session:inputxml name="name" type="text" context="trackdemo" path="/user/name"/>
039: * </session:content>
040: * <session:validate>
041: * <root>
042: * <parameter name="name" type="string" nullable="no"/>
043: * <constraint-set name="form_a_set">
044: * <validate name="name"/>
045: * </constraint-set>
046: * </root>
047: * </session:validate>
048: * </session:form>
049: * </pre>
050: *
051: * or described via the external xml file referenced
052: * through the "src" attribute
053: * (the format is defined in AbstractValidatorAction).
054: * Then the constraint-set to be used has to be identified
055: * through the "constraint-set" element
056: *
057: * <pre>
058: * <session:form name="info_form>
059: * <session:action>next_page</session:action>
060: * <session:content>
061: * <session:inputxml name="name" type="text" context="trackdemo" path="/user/name"/>
062: * </session:content>
063: * <session:validate src="descriptor.xml">
064: * <constraint-set name="form_a_set"/>
065: * </session:validate>
066: * </session:form>
067: * </pre>
068: *
069: * Since the validation rules are contained within the form document
070: * they are read and supplied by the SessionTransformer.
071: * So this action has to be used in conjunction with the SessionTransformer.
072: * The "next_page" pipeline might look like this:
073: *
074: * <pre>
075: * <map:match pattern="next_page">
076: * <map:act type="session-form">
077: * <map:generate src="next_page.xml"/>
078: * <map:transform type="session"/>
079: * <map:transform src="simple2html.xsl"/>
080: * <map:serialize/>
081: * </map:act>
082: * <map:generate src="first_page.xml"/>
083: * <map:transform type="session"/>
084: * <map:transform src="simple2html.xsl"/>
085: * <map:serialize/>
086: * </map:match>
087: * </pre>
088: *
089: * where "session-form" is configured as SessionFormAction
090: *
091: * @see org.apache.cocoon.acting.FormValidatorAction
092: * @see org.apache.cocoon.acting.AbstractValidatorAction
093: *
094: * @author <a href="mailto:gcasper@s-und-n.de">Guido Casper</a>
095: * @author <a href="mailto:haul@apache.org">Christian Haul</a>
096: * @deprecated This block is deprecated and will be removed in future versions.
097: * @version $Id: SessionFormAction.java 433543 2006-08-22 06:22:54Z crossley $
098: */
099: public class SessionFormAction extends FormValidatorAction {
100:
101: /* (non-Javadoc)
102: * @see org.apache.cocoon.acting.AbstractValidatorAction#getDescriptor(org.apache.cocoon.environment.SourceResolver, org.apache.avalon.framework.parameters.Parameters)
103: */
104: protected Configuration getDescriptor(SourceResolver resolver,
105: Map objectModel, Parameters parameters) {
106:
107: Session session = ObjectModelHelper.getRequest(objectModel)
108: .getSession(true);
109: return (Configuration) session.getAttribute(ObjectModelHelper
110: .getRequest(objectModel).getParameter(
111: SessionConstants.SESSION_FORM_PARAMETER));
112: }
113: }
|