vgritsenko 2003/01/30 18:49:56
Modified: src/java/org/apache/cocoon/acting AbstractXMLFormAction.java
Action.java ValidatorActionHelper.java
ValidatorActionResult.java
Log:
Small javadoc fixes and cosmetics
Revision Changes Path
1.10 +321 -378
xml-cocoon2/src/java/org/apache/cocoon/acting/AbstractXMLFormAction.java
Index: AbstractXMLFormAction.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/AbstractXMLFormAction.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- AbstractXMLFormAction.java 5 Dec 2002 09:23:35 -0000 1.9
+++ AbstractXMLFormAction.java 31 Jan 2003 02:49:56 -0000 1.10
@@ -109,207 +109,194 @@
* @author Ivelin Ivanov <[EMAIL PROTECTED]>
*/
public abstract class AbstractXMLFormAction
- extends ConfigurableComposerAction
- implements Poolable, Recyclable,
- FormListener
-
+ extends ConfigurableComposerAction
+ implements Poolable, Recyclable,
+ FormListener
{
- public static final String OBJECT_MAP_NEXT_PAGE = "page";
-
- protected static final Map PREPARE_RESULT_CONTINUE = null;
-
-
- /**
- * The first method which is called
- * when an action is invoked.
- *
- * It is called before population.
- *
- *
- * @return null if the Action is prepared to continue.
- * an objectModel map which will be immediately returned by the action.
- *
- * This method is a good place to handle buttons with Cancel
- * kind of semantics. For example
- * <pre>return page("input")</pre>
- *
- */
- protected Map prepare()
- {
- // by default, assume that there is
- // no preparation needed
- return PREPARE_RESULT_CONTINUE;
- }
-
-
- /**
- *
- * FormListener callback
- * called in the beginning of Form.populate()
- * before population starts.
- *
- * This is the place to intialize the model for this request.
- *
- * This method should not handle unchecked check boxes
- * when the form is session scope, which is the most common case.
- * It should only do so, if the form is request scoped.
- *
- */
-
-public void reset( Form form )
- {
- // Do Nothing by default
- return;
- }
-
-
- /**
- * FormListener callback
- *
- * Invoked during Form.populate();
- *
- * It is invoked before a request parameter is mapped to
- * an attribute of the form model.
- *
- * It is appropriate to use this method for filtering
- * custom request parameters which do not reference
- * the model.
- *
- * Another appropriate use of this method is for graceful filtering of invalid
- * values, in case that knowledge of the system state or
- * other circumstainces make the standard validation
- * insufficient. For example if a registering user choses a username which
- * is already taken - the check requires database transaction, which is
- * beyond the scope of document validating schemas.
- * Of course customized Validators can be implemented to do
- * this kind of domain specific validation
- * instead of using this method.
- *
- *
- * @return false if the request parameter should not be filtered.
- * true otherwise.
- */
- public boolean filterRequestParameter (Form form, String parameterName)
- {
- // in this example we do not expect "custom" parameters
- return false;
- }
-
-
-
- /**
- * Invoked during the form population process
- *
- * Provides default implementation, which
- * can be extended or replaced by subclasses
- *
- * Implementations of this method are responsible
- * for creating and
- * returning the Form object which the action
- * is working on.
- *
- * @return Form the form object this action works with
- *
- */
- protected Form getForm ()
- {
- Form form = Form.lookup( getObjectModel(), getFormId() );
+ public static final String OBJECT_MAP_NEXT_PAGE = "page";
- if (form != null) return form;
- else // create new form
- {
- form = new Form( getFormId(), getFormModel() );
- Validator v = getFormValidator();
- form.setValidator ( v );
- form.save ( getObjectModel(), getFormScope() );
- return form;
- }
- }
-
-
- public Map act(Redirector redirector, SourceResolver resolver, Map objectModel,
String src, Parameters params)
- throws java.lang.Exception
- {
- // populate action state objects
- redirector_ = redirector;
- resolver_ = resolver;
- objectModel_ = objectModel;
- src_ = src;
- params_ = params;
-
-
- // ensure that there is a form available
- // through the rest of the flow
- Form form = getForm();
- if (form == null)
- {
- throw new IllegalStateException( "Action could not obtain the Form" );
- }
-
-
- // find and save the action command
- findCommand();
-
- // call the subclass prepare()
- // give it a chance to get ready for action
- Map prepareResult = prepare();
- if ( prepareResult != null ) return prepareResult;
-
- // attache callback hooks to the form
- // in case the action subclasses are interested in
- // form events
- getForm().addFormListener( this );
- Map result = null;
-
- try
- {
- // populate form with request parameters
- // population is automatically followed by validation by default.
- // If this is not the desired behaviour, the Form class can be subclassed
- form.populate( objectModel );
-
- result = perform();
- }
- finally
- {
- // since the action may be recycled immediately after
- // the request. It is important that it's callback hooks
- // are removed from the Form.
- getForm().removeFormListener( this );
- }
-
- return result;
- }
-
-
- /**
- * Get the command which was submitted with the form.
- * It is extracted from the standard cocoon-action-* request parameter
- *
- */
- public String getCommand()
+ protected static final Map PREPARE_RESULT_CONTINUE = null;
+
+
+ // action state objects
+ private Redirector redirector_;
+ private SourceResolver resolver_;
+ private Map objectModel_;
+ private Parameters params_;
+ private String src_;
+ private String command_;
+
+
+ /**
+ * The first method which is called
+ * when an action is invoked.
+ *
+ * It is called before population.
+ *
+ *
+ * @return null if the Action is prepared to continue.
+ * an objectModel map which will be immediately returned by the action.
+ *
+ * This method is a good place to handle buttons with Cancel
+ * kind of semantics. For example
+ * <pre>return page("input")</pre>
+ *
+ */
+ protected Map prepare() {
+ // by default, assume that there is
+ // no preparation needed
+ return PREPARE_RESULT_CONTINUE;
+ }
+
+ /**
+ * FormListener callback
+ * called in the beginning of Form.populate()
+ * before population starts.
+ *
+ * This is the place to intialize the model for this request.
+ *
+ * This method should not handle unchecked check boxes
+ * when the form is session scope, which is the most common case.
+ * It should only do so, if the form is request scoped.
+ */
+ public void reset( Form form ) {
+ // Do Nothing by default
+ return;
+ }
+
+ /**
+ * FormListener callback
+ *
+ * Invoked during Form.populate();
+ *
+ * It is invoked before a request parameter is mapped to
+ * an attribute of the form model.
+ *
+ * It is appropriate to use this method for filtering
+ * custom request parameters which do not reference
+ * the model.
+ *
+ * Another appropriate use of this method is for graceful filtering of invalid
+ * values, in case that knowledge of the system state or
+ * other circumstainces make the standard validation
+ * insufficient. For example if a registering user choses a username which
+ * is already taken - the check requires database transaction, which is
+ * beyond the scope of document validating schemas.
+ * Of course customized Validators can be implemented to do
+ * this kind of domain specific validation
+ * instead of using this method.
+ *
+ * @return false if the request parameter should not be filtered.
+ * true otherwise.
+ */
+ public boolean filterRequestParameter (Form form, String parameterName) {
+ // in this example we do not expect "custom" parameters
+ return false;
+ }
+
+ /**
+ * Invoked during the form population process
+ *
+ * Provides default implementation, which
+ * can be extended or replaced by subclasses
+ *
+ * Implementations of this method are responsible
+ * for creating and
+ * returning the Form object which the action
+ * is working on.
+ *
+ * @return Form the form object this action works with
+ */
+ protected Form getForm () {
+ Form form = Form.lookup( getObjectModel(), getFormId() );
+
+ if (form != null) {
+ return form;
+ } else {
+ // create new form
+ form = new Form( getFormId(), getFormModel() );
+ Validator v = getFormValidator();
+ form.setValidator ( v );
+ form.save ( getObjectModel(), getFormScope() );
+ return form;
+ }
+ }
+
+ public Map act(Redirector redirector, SourceResolver resolver, Map objectModel,
String src, Parameters params)
+ throws Exception
{
- return command_;
+ // populate action state objects
+ redirector_ = redirector;
+ resolver_ = resolver;
+ objectModel_ = objectModel;
+ src_ = src;
+ params_ = params;
+
+ // ensure that there is a form available
+ // through the rest of the flow
+ Form form = getForm();
+ if (form == null) {
+ throw new IllegalStateException( "Action could not obtain the Form" );
+ }
+
+ // find and save the action command
+ findCommand();
+
+ // call the subclass prepare()
+ // give it a chance to get ready for action
+ Map prepareResult = prepare();
+ if (prepareResult != null) {
+ return prepareResult;
+ }
+
+ // attache callback hooks to the form
+ // in case the action subclasses are interested in
+ // form events
+ getForm().addFormListener( this );
+ Map result = null;
+
+ try {
+ // populate form with request parameters
+ // population is automatically followed by validation by default.
+ // If this is not the desired behaviour, the Form class can be
subclassed
+ form.populate( objectModel );
+
+ result = perform();
+ } finally {
+ // since the action may be recycled immediately after
+ // the request. It is important that it's callback hooks
+ // are removed from the Form.
+ getForm().removeFormListener( this );
+ }
+
+ return result;
}
- protected void findCommand()
+ /**
+ * Get the command which was submitted with the form.
+ * It is extracted from the standard cocoon-action-* request parameter
+ */
+ public String getCommand()
{
- command_ = null;
- Enumeration enum = getRequest().getParameterNames ();
- while (enum.hasMoreElements ())
- {
- String paramName = (String) enum.nextElement ();
- // search for the command
- if ( paramName.startsWith ( Constants.ACTION_PARAM_PREFIX ) )
- {
- command_ =
- paramName.substring ( Constants.ACTION_PARAM_PREFIX.length(),
paramName.length() );
- }
- }
+ return command_;
}
+ protected void findCommand() {
+ command_ = null;
+ Enumeration enum = getRequest().getParameterNames ();
+ while (enum.hasMoreElements ())
+ {
+ String paramName = (String) enum.nextElement ();
+ // search for the command
+ if ( paramName.startsWith ( Constants.ACTION_PARAM_PREFIX ) )
+ {
+ command_ =
+ paramName.substring (
Constants.ACTION_PARAM_PREFIX.length(), paramName.length() );
+ }
+ }
+ }
/**
* @return the @view attribute of the xmlform form tag.
@@ -318,204 +305,160 @@
* document.
*
*/
- public String getFormView()
- {
- return getForm().getFormView( getObjectModel() );
+ public String getFormView() {
+ return getForm().getFormView( getObjectModel() );
+ }
+
+
+ /**
+ * Called to determine the exit point of an action.
+ * The pageName is made available in the objectMap,
+ * which can be then referenced in the pipeline
+ * @param pageName logical name for a next page
+ * @return Map a pipeline objectMap containing the pageName
+ *
+ */
+ protected Map page( String pageName ) {
+ Map objectModel = new HashMap();
+ objectModel.put( OBJECT_MAP_NEXT_PAGE, pageName );
+ return objectModel;
+ }
+
+ /**
+ * Invoked after form population
+ * unless a Cancel button was pressed,
+ * in which case population is skipped and this method
+ * is invoked immediately
+ *
+ * Semanticly similar to Struts Action.perform()
+ *
+ * Take appropriate action based on the command
+ *
+ */
+ public abstract Map perform ();
+
+
+ protected SourceResolver getSourceResolver() {
+ return resolver_;
+ }
+
+ protected Redirector getRedirector() {
+ return redirector_;
+ }
+
+ protected Map getObjectModel() {
+ return objectModel_;
+ }
+
+
+ protected Parameters getParameters() {
+ return params_;
}
+ protected String getSrc() {
+ return src_;
+ }
+ protected Request getRequest() {
+ return (Request) ( getObjectModel().get(ObjectModelHelper.REQUEST_OBJECT) );
+ }
- /**
- * Called to determine the exit point of an action.
- * The pageName is made available in the objectMap,
- * which can be then referenced in the pipeline
- * @param pageName logical name for a next page
- * @return Map a pipeline objectMap containing the pageName
- *
- */
- protected Map page( String pageName )
- {
- Map objectModel = new HashMap();
- objectModel.put( OBJECT_MAP_NEXT_PAGE, pageName );
- return objectModel;
- }
-
- /**
- * Invoked after form population
- * unless a Cancel button was pressed,
- * in which case population is skipped and this method
- * is invoked immediately
- *
- * Semanticly similar to Struts Action.perform()
- *
- * Take appropriate action based on the command
- *
- */
- public abstract Map perform ();
-
-
- protected SourceResolver getSourceResolver()
- {
- return resolver_;
- }
-
- protected Redirector getRedirector()
- {
- return redirector_;
- }
-
- protected Map getObjectModel()
- {
- return objectModel_;
- }
-
-
- protected Parameters getParameters()
- {
- return params_;
- }
-
- protected String getSrc()
- {
- return src_;
- }
-
- protected Request getRequest()
- {
- return (Request) ( getObjectModel().get(ObjectModelHelper.REQUEST_OBJECT) );
- }
-
- protected Session getSession( boolean shouldCreateNew )
- {
- return getRequest().getSession( shouldCreateNew );
- }
-
- protected Session getSession()
- {
- return getSession( true );
- }
-
-
- /**
- * Extract action parameters and
- * instantiate a new validator based on them.
- *
- * xmlform-validator-schema-ns
- * xmlform-validator-schema
- *
- * Subclasses may override this method
- * to use custom validators
- *
- */
- protected Validator getFormValidator()
- {
- try
- {
- // initialize the Validor with a schema file
- String schNS = getParameters().getParameter("xmlform-validator-schema-ns",
null);
- String schDoc = getParameters().getParameter("xmlform-validator-schema",
null);
-
- // if validator params are not specified, then
- // there is no validation by default
- if (schNS == null || schDoc == null ) return null;
+ protected Session getSession( boolean shouldCreateNew ) {
+ return getRequest().getSession( shouldCreateNew );
+ }
- Source schemaSrc = getSourceResolver().resolveURI( schDoc );
+ protected Session getSession() {
+ return getSession( true );
+ }
+
+
+ /**
+ * Extract action parameters and
+ * instantiate a new validator based on them.
+ *
+ * xmlform-validator-schema-ns
+ * xmlform-validator-schema
+ *
+ * Subclasses may override this method
+ * to use custom validators
+ */
+ protected Validator getFormValidator() {
try {
- InputSource is = SourceUtil.getInputSource(schemaSrc);
- SchemaFactory schf = SchemaFactory.lookup ( schNS );
- Schema sch = schf.compileSchema ( is );
+ // initialize the Validor with a schema file
+ String schNS =
getParameters().getParameter("xmlform-validator-schema-ns", null);
+ String schDoc =
getParameters().getParameter("xmlform-validator-schema", null);
+
+ // if validator params are not specified, then
+ // there is no validation by default
+ if (schNS == null || schDoc == null ) return null;
+
+ Source schemaSrc = getSourceResolver().resolveURI( schDoc );
+ try {
+ InputSource is = SourceUtil.getInputSource(schemaSrc);
+ SchemaFactory schf = SchemaFactory.lookup ( schNS );
+ Schema sch = schf.compileSchema ( is );
+
+ return sch.newValidator();
+ } finally {
+ getSourceResolver().release(schemaSrc);
+ }
+ } catch ( Exception e) {
+ // couldn't load the validator
+ throw new CascadingRuntimeException( " Failed loading validating schema
", e );
+ }
+ }
- return sch.newValidator();
- } finally {
- getSourceResolver().release(schemaSrc);
+
+ /**
+ * Extract xmlform-model
+ * action parameter and
+ * instantiate a new form model it.
+ *
+ *
+ * Subclasses may override this method
+ * to use custom model instantiation technique
+ */
+ protected Object getFormModel() {
+ try {
+ String modelClassName = getParameters().getParameter("xmlform-model",
null);
+ Class modelClass = Class.forName ( modelClassName );
+ Object o = modelClass.newInstance ();
+ return o;
+ } catch ( Exception e) {
+ throw new CascadingRuntimeException( " Failed instantiating form model
", e );
}
- }
- catch ( Exception e)
- {
- // couldn't load the validator
- throw new CascadingRuntimeException( " Failed loading validating schema ",
e );
- }
- }
-
-
- /**
- * Extract xmlform-model
- * action parameter and
- * instantiate a new form model it.
- *
- *
- * Subclasses may override this method
- * to use custom model instantiation technique
- *
- */
- protected Object getFormModel()
- {
- try
- {
- String modelClassName = getParameters().getParameter("xmlform-model", null);
- Class modelClass = Class.forName ( modelClassName );
- Object o = modelClass.newInstance ();
- return o;
- }
- catch ( Exception e)
- {
- throw new CascadingRuntimeException( " Failed instantiating form model ", e
);
- }
- }
-
-
- protected String getFormId()
- {
- String formId = getParameters().getParameter("xmlform-id", null);
- if ( formId == null )
- throw new RuntimeException( " xmlform-id not specified " );
- else
- return formId;
- }
-
-
- protected String getFormScope()
- {
- String formScope = getParameters().getParameter("xmlform-scope", null);
- if ( formScope == null )
- {
- // default to request scope
- formScope = Form.SCOPE_REQUEST;
}
-
- return formScope;
- }
+ protected String getFormId() {
+ String formId = getParameters().getParameter("xmlform-id", null);
+ if (formId == null)
+ throw new RuntimeException( " xmlform-id not specified " );
+ else
+ return formId;
+ }
- /**
- * Recycle this component.
- */
- public void recycle()
- {
-
- redirector_ = null;
- resolver_ = null;
- objectModel_ = null;
- params_ = null;
- src_ = null;
- request_ = null;
- session_ = null;
- command_ = null;
-
- }
+ protected String getFormScope() {
+ String formScope = getParameters().getParameter("xmlform-scope", null);
+ if ( formScope == null ) {
+ // default to request scope
+ formScope = Form.SCOPE_REQUEST;
+ }
+ return formScope;
+ }
- // action state objects
- private Redirector redirector_;
- private SourceResolver resolver_;
- private Map objectModel_;
- private Parameters params_;
- private String src_;
- private Request request_;
- private Session session_;
- private String command_;
+ /**
+ * Recycle this component.
+ */
+ public void recycle() {
+ redirector_ = null;
+ resolver_ = null;
+ objectModel_ = null;
+ params_ = null;
+ src_ = null;
+ command_ = null;
+ }
}
-
1.7 +3 -6 xml-cocoon2/src/java/org/apache/cocoon/acting/Action.java
Index: Action.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/Action.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Action.java 12 Aug 2002 07:50:53 -0000 1.6
+++ Action.java 31 Jan 2003 02:49:56 -0000 1.7
@@ -92,9 +92,6 @@
* be skipped.
* @exception Exception Indicates something is totally wrong
*/
- Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String
source, Parameters par)
- throws Exception;
+ Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String
source, Parameters parameters)
+ throws Exception;
}
-
-
-
1.7 +13 -17
xml-cocoon2/src/java/org/apache/cocoon/acting/ValidatorActionHelper.java
Index: ValidatorActionHelper.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/ValidatorActionHelper.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ValidatorActionHelper.java 9 Aug 2002 08:27:18 -0000 1.6
+++ ValidatorActionHelper.java 31 Jan 2003 02:49:56 -0000 1.7
@@ -51,7 +51,6 @@
package org.apache.cocoon.acting;
-
/**
* Helper class to pass a the result of a validation back along with
* the validated object itself.
@@ -59,7 +58,6 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
* @version CVS $Id$
*/
-
public class ValidatorActionHelper
{
protected ValidatorActionResult result = ValidatorActionResult.OK;
@@ -71,10 +69,9 @@
*
* @param validatedObject object that has been validated
*/
-
public ValidatorActionHelper ( Object validatedObject ) {
- this.object = validatedObject;
- this.result = ValidatorActionResult.OK;
+ this.object = validatedObject;
+ this.result = ValidatorActionResult.OK;
}
/**
@@ -85,8 +82,8 @@
* @param validationResult result of the validation
*/
public ValidatorActionHelper ( Object validatedObject, ValidatorActionResult
validationResult ) {
- this.object = validatedObject;
- this.result = validationResult;
+ this.object = validatedObject;
+ this.result = validationResult;
}
/**
@@ -94,7 +91,7 @@
*
*/
public boolean isOK() {
- return (result.equals(ValidatorActionResult.OK));
+ return (result.equals(ValidatorActionResult.OK));
}
/**
@@ -103,7 +100,7 @@
*
*/
public boolean isNotPresent() {
- return (result.equals(ValidatorActionResult.NOTPRESENT));
+ return (result.equals(ValidatorActionResult.NOTPRESENT));
}
/**
@@ -112,7 +109,7 @@
*
*/
public boolean isNull() {
- return (result.equals(ValidatorActionResult.ISNULL));
+ return (result.equals(ValidatorActionResult.ISNULL));
}
/**
@@ -122,7 +119,7 @@
*
*/
public boolean isTooLarge() {
- return (result.equals(ValidatorActionResult.TOOLARGE));
+ return (result.equals(ValidatorActionResult.TOOLARGE));
}
/**
@@ -132,7 +129,7 @@
*
*/
public boolean isTooSmall() {
- return (result.equals(ValidatorActionResult.TOOSMALL));
+ return (result.equals(ValidatorActionResult.TOOSMALL));
}
/**
@@ -141,7 +138,7 @@
*
*/
public boolean doesNotMatch() {
- return (result.equals(ValidatorActionResult.NOMATCH));
+ return (result.equals(ValidatorActionResult.NOMATCH));
}
/**
@@ -149,7 +146,7 @@
*
*/
public Object getObject() {
- return object;
+ return object;
}
/**
@@ -157,7 +154,6 @@
*
*/
public ValidatorActionResult getResult() {
- return result;
+ return result;
}
-
}
1.7 +2 -6
xml-cocoon2/src/java/org/apache/cocoon/acting/ValidatorActionResult.java
Index: ValidatorActionResult.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/ValidatorActionResult.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ValidatorActionResult.java 9 Aug 2002 08:27:18 -0000 1.6
+++ ValidatorActionResult.java 31 Jan 2003 02:49:56 -0000 1.7
@@ -58,7 +58,6 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
* @version CVS $Id$
*/
-
public class ValidatorActionResult extends EnumerationFactory {
/**
@@ -119,9 +118,6 @@
* Make constructor private to inhibit creation outside.
*/
private ValidatorActionResult (String image) {
- super (image);
- }
- private ValidatorActionResult () {
- super ();
+ super (image);
}
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]