| <?xml version="1.0" encoding="UTF-8"?> |
| <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0"> |
| |
| <map:components> |
| |
| <!--+ |
| | In order to use simple form validation, we need to make this action |
| | available to the sitemap. Components are inherited, so this could have |
| | been done in a parent sitemap. However, to illustrate the usage, we |
| | do it here. |
| | |
| | Note, there are several different validator actions available in |
| | Cocoon. They share the same validation code but operate on different |
| | values. Here, we're interested in validating request parameters, thus |
| | the FormValidatorAction is the right choice. |
| | |
| | The action is the only component we need to declare - the logicsheet |
| | has been added to cocoon.xconf for you already. |
| +--> |
| <map:actions> |
| <map:action name="formval" |
| logger="sitemap.action.form-validator" |
| src="org.apache.cocoon.acting.FormValidatorAction"/> |
| </map:actions> |
| |
| |
| |
| <!--+ |
| | Validation should only occurr when data has been submitted. Therefore |
| | a selector is created that will be used to select upon the request method. |
| | This is optional if you don't mind to show validation results without |
| | user input. |
| | |
| +--> |
| <map:selectors> |
| <map:selector name="simple" |
| logger="sitemap.matcher.wildcard" |
| src="org.apache.cocoon.selection.SimpleSelector"/> |
| </map:selectors> |
| |
| |
| |
| <map:transformers default="xslt"> |
| |
| <!--+ |
| | the SimpleFormTransformer acts upon HTML4 form element tags and |
| | replaces their value attribute or their content in case of the |
| | textarea element with data obtained from an input module attribute |
| | with the same name. In addition, it checks the result of the |
| | FormValidatorAction when it encounters <error/> tags and includes |
| | / excludes them depending on the result. |
| | |
| +--> |
| <map:transformer name="simpleform" |
| logger="sitemap.transformer.simpleform" |
| src="org.apache.cocoon.transformation.SimpleFormTransformer"> |
| <input-module name="request-param"/> |
| </map:transformer> |
| |
| <!--+ |
| | This transformer is used to extract the form instance data from the |
| | xml document. See the javadocs of this class for more information on |
| | the default configuration and configuration options. |
| | |
| | Here, the instance data is nested inside the form element. The |
| | transformer can be configured to look for it at other places. |
| | |
| | The instance data is stored as an attribute with the same name as the |
| | form using an output module. Here we decide to use the RequestAttributeMap |
| | module. This would allows |
| | a) to store instances for several forms and |
| | b) to access a particular instance and value using JXPath syntax. |
| | |
| | Per default, the map key is the name of the form as is the root node |
| | of the new Document. |
| | |
| +--> |
| <map:transformer name="sfinstance" |
| logger="sitemap.transformer.simpleform-request" |
| src="org.apache.cocoon.transformation.SimpleFormInstanceExtractionTransformer"> |
| <output name="request-attr-map"/> |
| </map:transformer> |
| |
| <!--+ |
| | This is the other transformer to read and insert the instance data. |
| | It will be applied first in the pipeline so that the user submitted |
| | data can override the default data. |
| | |
| | Only one of the two transformers needs to check for validation errors, |
| | this instance has been instructed to ignore validation results because |
| | looking up the instance data requires to augment the element name with |
| | the form name and thus differ from the validation result names. |
| | |
| | The instance extractor places the form instances into a map with the |
| | form name as key. Furthermore, it has been instructed to create a root |
| | element wrapping the instance data with the same name as the form. |
| | Hence we need to included the form's name twice in the element name |
| | used for the lookup. |
| | |
| | In addition, we may want to be able to select from a XSP if the form |
| | data should be replaced with values from the instance or from the |
| | request. Therefore, a different attribute is used to protect element |
| | values. |
| | |
| +--> |
| <map:transformer name="simpleform-instance" |
| logger="sitemap.transformer.simpleform-instance" |
| src="org.apache.cocoon.transformation.SimpleFormTransformer"> |
| <fixed-attribute>this-is-never-used</fixed-attribute> |
| <use-form-name-twice>true</use-form-name-twice> |
| <ignore-validation>true</ignore-validation> |
| <input-module name="jxpath"> |
| <!--+ |
| | "jxpath" does not pass the attribute name to the module it |
| | obtains the value to act from. Thus an additional attribute |
| | name needs to be injected. |
| +--> |
| <from-parameter>org.apache.cocoon.components.modules.output.OutputModule</from-parameter> |
| <input-module name="request-attr"/> |
| </input-module> |
| </map:transformer> |
| |
| </map:transformers> |
| |
| </map:components> |
| |
| <!--+ |
| | This is a standard resource for rendering a XSP page. |
| +--> |
| <map:resources> |
| <map:resource name="static-page"> |
| <map:transform src="context://samples/common/style/xsl/html/simple-page2html.xsl"> |
| <map:parameter name="servletPath" value="{request:servletPath}"/> |
| <map:parameter name="sitemapURI" value="{request:sitemapURI}"/> |
| <map:parameter name="contextPath" value="{request:contextPath}"/> |
| <map:parameter name="remove" value="{/0}"/> |
| <map:parameter name="file" value="{file}.xml"/> |
| </map:transform> |
| <map:serialize/> |
| </map:resource> |
| </map:resources> |
| |
| <!--+ |
| | These views provide different 'standard' views to the samples. |
| | |
| +--> |
| |
| <map:views> |
| <map:view name="content" from-label="content"> |
| <map:serialize type="xml"/> |
| </map:view> |
| |
| <map:view from-label="content" name="pretty-content"> |
| <map:transform src="context://stylesheets/system/xml2html.xslt"/> |
| <map:serialize type="html"/> |
| </map:view> |
| |
| <map:view name="links" from-position="last"> |
| <map:serialize type="links"/> |
| </map:view> |
| |
| </map:views> |
| |
| |
| <!--+ |
| | Pipelines |
| | |
| +--> |
| |
| |
| <map:pipelines> |
| |
| <map:pipeline> |
| |
| |
| <!-- some redirections --> |
| <map:match pattern=""> |
| <map:redirect-to uri="index"/> |
| </map:match> |
| |
| |
| |
| <map:match pattern="index"> |
| <!--+ |
| | Only validate when data was submitted |
| +--> |
| <map:select type="simple"> |
| <map:parameter name="value" value="{request:method}"/> |
| <map:when test="POST"> |
| <!--+ |
| | Check the request parameters using the FormValidatorAction |
| +--> |
| <map:act type="formval"> |
| <map:parameter name="descriptor" value="descriptor.xml"/> |
| <map:parameter name="validate-set" value="car-reservation"/> |
| <!--+ |
| | this is the success case |
| | |
| +--> |
| <map:generate src="success.xml"/> |
| <map:transform type="simpleform"/> |
| <map:call resource="static-page"> |
| <map:parameter name="file" value="success"/> |
| </map:call> |
| <!-- because of the resource above the "success" pipeline ends here. --> |
| </map:act> |
| </map:when> |
| </map:select> |
| <!--+ |
| | this branch contains the failed validation. |
| | Since the "success" pipeline ends with a resource, the following is only |
| | applied if validation has not been successful. |
| | |
| +--> |
| <map:generate type="file" src="form.xml"/> |
| <!--+ |
| | extract the instance data |
| +--> |
| <map:transform type="sfinstance"/> |
| <!--+ |
| | fill in the instance data |
| +--> |
| <map:transform type="simpleform-instance"/> |
| <!--+ |
| | fill in the request parameters, and error tags |
| +--> |
| <map:transform type="simpleform"/> |
| <map:call resource="static-page"> |
| <map:parameter name="file" value="form"/> |
| </map:call> |
| </map:match> |
| |
| |
| |
| <!-- some redirections --> |
| <map:match pattern="*"> |
| <map:redirect-to uri="index"/> |
| </map:match> |
| |
| </map:pipeline> |
| </map:pipelines> |
| |
| </map:sitemap> |
| |
| <!-- end of file --> |