org.apache.cocoon.transformation
Class SimpleFormTransformer

java.lang.Object
  |
  +--org.apache.avalon.framework.logger.AbstractLoggable
        |
        +--org.apache.cocoon.xml.AbstractXMLProducer
              |
              +--org.apache.cocoon.xml.AbstractXMLPipe
                    |
                    +--org.apache.cocoon.transformation.AbstractTransformer
                          |
                          +--org.apache.cocoon.transformation.SimpleFormTransformer
All Implemented Interfaces:
org.apache.avalon.framework.component.Component, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.configuration.Configurable, org.xml.sax.ContentHandler, org.xml.sax.ext.LexicalHandler, org.apache.avalon.framework.logger.Loggable, org.apache.avalon.excalibur.pool.Poolable, org.apache.avalon.excalibur.pool.Recyclable, SitemapModelComponent, Transformer, XMLConsumer, XMLPipe, XMLProducer

public class SimpleFormTransformer
extends AbstractTransformer
implements org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.excalibur.pool.Recyclable

Eliminates the need for XSP to use FormValidatorAction. Caveat: Select options need a value attribute to work correctly.

This transformer fills all HTML 4 form elements with values from an InputModule, e.g. request, with the same name. It handles select boxes, textareas, checkboxes, radio buttons, password and text fields, and buttons.

In addition, it handles FormValidatorAction results by selectively omitting <error/> elements. These elements need a "name" attribute corresponding to the name of the form element, and either a "when" or a "when-ge" attribute.

An error element is send down the pipeline if validation results are available and either the results equals the "when" attribute or the result is greater or equal to the "when-ge" attribute.

Names for validation results are "ok", "not-present", "error", "is-null", "too-small", "too-large", and "no-match" for the similar named values from ValidatorActionResult.

There need not to be an "error" element for every form element, multiple error elements for the same form element may be present.

To use this transformer, add the following to your transformation pipeline:

   <map:transform type="simple-form"/>
 

Configuration elements:
input-module(String) InputModule configuration, defaults to an empty configuration and the "request-param" module

Sitemap parameters:
fixed(boolean) Do not change values
prefix(String) Added to the input element's name
suffix(String) Added to the input element's name
input(String) InputModule name

Example:

     <input name="user.name" size="50" maxlength="60"/>
     <error name="user.name" when-ge="error">required</error>
 

Version:
CVS $Id: SimpleFormTransformer.java,v 1.1.2.3 2002/11/30 10:22:06 haul Exp $
Author:
Christian Haul

Field Summary
protected  org.xml.sax.helpers.AttributesImpl emptyAttributes
          Empty attributes (for performance).
protected  int ignoreCount
          nesting level of ignored elements
protected  boolean ignoreThis
          ignored element needs closing tag
protected static java.lang.String INPUT_MODULE_ROLE
           
protected static java.lang.String INPUT_MODULE_SELECTOR
           
protected  org.apache.avalon.framework.component.ComponentManager manager
          The Avalon ComponentManager for getting Components
protected  java.util.Map objectModel
          The current objectModel of the environment
protected  org.apache.avalon.framework.parameters.Parameters parameters
          The parameters specified in the sitemap
protected  Request request
          The current Request object
protected  java.util.Stack stack
          stack of ignored element names
protected  java.util.Map validationResults
          current request's validation results (all validated elements)
protected  java.lang.Object[] values
          current element's request parameter values
 
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer
contentHandler, lexicalHandler, xmlConsumer
 
Fields inherited from interface org.apache.cocoon.transformation.Transformer
ROLE
 
Constructor Summary
SimpleFormTransformer()
           
 
Method Summary
 void characters(char[] c, int start, int len)
          Receive notification of character data.
 void compose(org.apache.avalon.framework.component.ComponentManager manager)
          Avalon Composable Interface
 void configure(org.apache.avalon.framework.configuration.Configuration config)
          Avalon Configurable Interface
 void endElement(java.lang.String uri, java.lang.String name, java.lang.String raw)
          Start processing elements of our namespace.
 void ignorableWhitespace(char[] c, int start, int len)
          Receive notification of ignorable whitespace in element content.
protected  java.lang.String printAttributes(org.xml.sax.Attributes attr)
          Generate string representation of attributes.
 void processingInstruction(java.lang.String target, java.lang.String data)
          Receive notification of a processing instruction.
 void recycle()
          Recycle this component.
 void setup(SourceResolver resolver, java.util.Map objectModel, java.lang.String src, org.apache.avalon.framework.parameters.Parameters par)
          Setup the next round.
 void skippedEntity(java.lang.String name)
          Receive notification of a skipped entity.
protected  void startCheckableElement(java.lang.String uri, java.lang.String name, java.lang.String raw, org.xml.sax.helpers.AttributesImpl attributes)
          Handle input elements that may have a "checked" attributes, i.e. checkbox and radio.
 void startElement(java.lang.String uri, java.lang.String name, java.lang.String raw, org.xml.sax.Attributes attr)
          Start processing elements of our namespace.
protected  void startErrorElement(java.lang.String uri, java.lang.String name, java.lang.String raw, org.xml.sax.Attributes attr)
          Handle error elements.
protected  void startInputElement(java.lang.String uri, java.lang.String name, java.lang.String raw, org.xml.sax.Attributes attr)
          Handle input elements.
protected  void startNonCheckableElement(java.lang.String uri, java.lang.String name, java.lang.String raw, org.xml.sax.helpers.AttributesImpl attributes)
          Handle input elements that may don't have a "checked" attributes, e.g. text, password, button.
protected  void startOptionElement(java.lang.String uri, java.lang.String name, java.lang.String raw, org.xml.sax.Attributes attr)
          Handle option elements.
protected  void startSelectElement(java.lang.String uri, java.lang.String name, java.lang.String raw, org.xml.sax.Attributes attr)
          Handle select elements.
protected  void startTextareaElement(java.lang.String uri, java.lang.String name, java.lang.String raw, org.xml.sax.Attributes attributes)
          Handles textarea elements.
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLPipe
comment, endCDATA, endDocument, endDTD, endEntity, endPrefixMapping, setDocumentLocator, startCDATA, startDocument, startDTD, startEntity, startPrefixMapping
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer
setConsumer, setContentHandler, setLexicalHandler
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLoggable
getLogger, setLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.xml.sax.ContentHandler
endDocument, endPrefixMapping, setDocumentLocator, startDocument, startPrefixMapping
 
Methods inherited from interface org.xml.sax.ext.LexicalHandler
comment, endCDATA, endDTD, endEntity, startCDATA, startDTD, startEntity
 
Methods inherited from interface org.apache.cocoon.xml.XMLProducer
setConsumer
 

Field Detail

INPUT_MODULE_ROLE

protected static final java.lang.String INPUT_MODULE_ROLE

INPUT_MODULE_SELECTOR

protected static final java.lang.String INPUT_MODULE_SELECTOR

ignoreCount

protected int ignoreCount
nesting level of ignored elements


ignoreThis

protected boolean ignoreThis
ignored element needs closing tag


stack

protected java.util.Stack stack
stack of ignored element names


values

protected java.lang.Object[] values
current element's request parameter values


validationResults

protected java.util.Map validationResults
current request's validation results (all validated elements)


request

protected Request request
The current Request object


objectModel

protected java.util.Map objectModel
The current objectModel of the environment


parameters

protected org.apache.avalon.framework.parameters.Parameters parameters
The parameters specified in the sitemap


manager

protected org.apache.avalon.framework.component.ComponentManager manager
The Avalon ComponentManager for getting Components


emptyAttributes

protected org.xml.sax.helpers.AttributesImpl emptyAttributes
Empty attributes (for performance). This can be used do create own attributes, but make sure to clean them afterwords.

Constructor Detail

SimpleFormTransformer

public SimpleFormTransformer()
Method Detail

configure

public void configure(org.apache.avalon.framework.configuration.Configuration config)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Avalon Configurable Interface

Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
org.apache.avalon.framework.configuration.ConfigurationException

setup

public void setup(SourceResolver resolver,
                  java.util.Map objectModel,
                  java.lang.String src,
                  org.apache.avalon.framework.parameters.Parameters par)
           throws ProcessingException,
                  org.xml.sax.SAXException,
                  java.io.IOException
Setup the next round. The instance variables are initialised.

Specified by:
setup in interface SitemapModelComponent
Parameters:
resolver - The current SourceResolver
objectModel - The objectModel of the environment.
src - The value of the src attribute in the sitemap.
par - The parameters from the sitemap.
ProcessingException
org.xml.sax.SAXException
java.io.IOException

recycle

public void recycle()
Recycle this component.

Specified by:
recycle in interface org.apache.avalon.excalibur.pool.Recyclable
Overrides:
recycle in class AbstractXMLProducer

compose

public void compose(org.apache.avalon.framework.component.ComponentManager manager)
Avalon Composable Interface

Specified by:
compose in interface org.apache.avalon.framework.component.Composable
Parameters:
manager - The Avalon Component Manager

printAttributes

protected java.lang.String printAttributes(org.xml.sax.Attributes attr)
Generate string representation of attributes. For debug only.


startCheckableElement

protected void startCheckableElement(java.lang.String uri,
                                     java.lang.String name,
                                     java.lang.String raw,
                                     org.xml.sax.helpers.AttributesImpl attributes)
                              throws org.xml.sax.SAXException
Handle input elements that may have a "checked" attributes, i.e. checkbox and radio.

org.xml.sax.SAXException

startNonCheckableElement

protected void startNonCheckableElement(java.lang.String uri,
                                        java.lang.String name,
                                        java.lang.String raw,
                                        org.xml.sax.helpers.AttributesImpl attributes)
                                 throws org.xml.sax.SAXException
Handle input elements that may don't have a "checked" attributes, e.g. text, password, button.

org.xml.sax.SAXException

startInputElement

protected void startInputElement(java.lang.String uri,
                                 java.lang.String name,
                                 java.lang.String raw,
                                 org.xml.sax.Attributes attr)
                          throws org.xml.sax.SAXException
Handle input elements. Calls startCheckableElement or startNonCheckableElement.

org.xml.sax.SAXException

startSelectElement

protected void startSelectElement(java.lang.String uri,
                                  java.lang.String name,
                                  java.lang.String raw,
                                  org.xml.sax.Attributes attr)
                           throws org.xml.sax.SAXException
Handle select elements. Sets up some instance variables for following option elements.

org.xml.sax.SAXException

startOptionElement

protected void startOptionElement(java.lang.String uri,
                                  java.lang.String name,
                                  java.lang.String raw,
                                  org.xml.sax.Attributes attr)
                           throws org.xml.sax.SAXException
Handle option elements. Uses instance variables set up by startSelectElement. Relies on option having a "value" attribute, i.e. does not check following characters if "value" is not present.

org.xml.sax.SAXException

startTextareaElement

protected void startTextareaElement(java.lang.String uri,
                                    java.lang.String name,
                                    java.lang.String raw,
                                    org.xml.sax.Attributes attributes)
                             throws org.xml.sax.SAXException
Handles textarea elements. Skips nested events if request parameter with same name exists.

org.xml.sax.SAXException

startErrorElement

protected void startErrorElement(java.lang.String uri,
                                 java.lang.String name,
                                 java.lang.String raw,
                                 org.xml.sax.Attributes attr)
                          throws org.xml.sax.SAXException
Handle error elements. If validation results are available, compares validation result for parameter with the same name as the "name" attribute with the result names is "when" and "when-ge". Drops element and all nested events when error condition is not met.

org.xml.sax.SAXException

startElement

public void startElement(java.lang.String uri,
                         java.lang.String name,
                         java.lang.String raw,
                         org.xml.sax.Attributes attr)
                  throws org.xml.sax.SAXException
Start processing elements of our namespace. This hook is invoked for each sax event with our namespace.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class AbstractXMLPipe
Parameters:
uri - The namespace of the element.
name - The local name of the element.
raw - The qualified name of the element.
attr - The attributes of the element.
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String uri,
                       java.lang.String name,
                       java.lang.String raw)
                throws org.xml.sax.SAXException
Start processing elements of our namespace. This hook is invoked for each sax event with our namespace.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class AbstractXMLPipe
Parameters:
uri - The namespace of the element.
name - The local name of the element.
raw - The qualified name of the element.
org.xml.sax.SAXException

characters

public void characters(char[] c,
                       int start,
                       int len)
                throws org.xml.sax.SAXException
Receive notification of character data.

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class AbstractXMLPipe
Parameters:
c - The characters from the XML document.
start - The start position in the array.
len - The number of characters to read from the array.
org.xml.sax.SAXException

ignorableWhitespace

public void ignorableWhitespace(char[] c,
                                int start,
                                int len)
                         throws org.xml.sax.SAXException
Receive notification of ignorable whitespace in element content.

Specified by:
ignorableWhitespace in interface org.xml.sax.ContentHandler
Overrides:
ignorableWhitespace in class AbstractXMLPipe
Parameters:
c - The characters from the XML document.
start - The start position in the array.
len - The number of characters to read from the array.
org.xml.sax.SAXException

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws org.xml.sax.SAXException
Receive notification of a processing instruction.

Specified by:
processingInstruction in interface org.xml.sax.ContentHandler
Overrides:
processingInstruction in class AbstractXMLPipe
Parameters:
target - The processing instruction target.
data - The processing instruction data, or null if none was supplied.
org.xml.sax.SAXException

skippedEntity

public void skippedEntity(java.lang.String name)
                   throws org.xml.sax.SAXException
Receive notification of a skipped entity.

Specified by:
skippedEntity in interface org.xml.sax.ContentHandler
Overrides:
skippedEntity in class AbstractXMLPipe
Parameters:
name - The name of the skipped entity. If it is a parameter entity, the name will begin with '%'.
org.xml.sax.SAXException


Copyright © 1999-2002 Apache Software Foundation. All Rights Reserved.