You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2003/05/06 19:08:26 UTC
cvs commit: cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/components DefaultFormManager.java
cziegeler 2003/05/06 10:08:26
Modified: src/blocks/session-fw/java/org/apache/cocoon/webapps/session
FormManager.java
src/blocks/session-fw/conf session-act.xmap
src/blocks/session-fw/java/org/apache/cocoon/webapps/session/components
DefaultFormManager.java
Added: src/blocks/session-fw/java/org/apache/cocoon/webapps/session/acting
FormManagerAction.java
Log:
Adding new action for form manager
Revision Changes Path
1.1 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/acting/FormManagerAction.java
Index: FormManagerAction.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.webapps.session.acting;
import java.util.Map;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.acting.ComposerAction;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.webapps.session.FormManager;
/**
* This action invokes the form manager to process incomming form values
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
* @version CVS $Id: FormManagerAction.java,v 1.1 2003/05/06 17:08:25 cziegeler Exp $
*/
public final class FormManagerAction
extends ComposerAction
implements ThreadSafe {
public Map act(Redirector redirector,
SourceResolver resolver,
Map objectModel,
String source,
Parameters par)
throws ProcessingException {
FormManager formManager = null;
try {
formManager = (FormManager)this.manager.lookup(FormManager.ROLE);
formManager.processInputFields();
} catch (ComponentException ce) {
throw new ProcessingException("Error during lookup of formManager component.", ce);
} finally {
this.manager.release( (Component)formManager );
}
return EMPTY_MAP;
}
}
1.2 +7 -2 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/FormManager.java
Index: FormManager.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/FormManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FormManager.java 4 May 2003 20:19:41 -0000 1.1
+++ FormManager.java 6 May 2003 17:08:26 -0000 1.2
@@ -66,7 +66,6 @@
/**
* Register input field and return the current value of the field.
- * This is a private method and should not be invoked directly.
*/
DocumentFragment registerInputField(String contextName,
String path,
@@ -74,4 +73,10 @@
String formName)
throws ProcessingException;
+ /**
+ * Process the request.
+ * The incoming parameters are evaluated, if they contain information
+ * for a previously registered input field.
+ */
+ void processInputFields();
}
1.3 +3 -0 cocoon-2.1/src/blocks/session-fw/conf/session-act.xmap
Index: session-act.xmap
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/session-fw/conf/session-act.xmap,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- session-act.xmap 6 May 2003 14:12:57 -0000 1.2
+++ session-act.xmap 6 May 2003 17:08:26 -0000 1.3
@@ -8,4 +8,7 @@
<map:action name="session-form"
src="org.apache.cocoon.webapps.session.acting.SessionFormAction"/>
+
+ <map:action name="session-form-manager"
+ src="org.apache.cocoon.webapps.session.acting.FormManagerAction"/>
</xmap>
1.2 +46 -77 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/components/DefaultFormManager.java
Index: DefaultFormManager.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/components/DefaultFormManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultFormManager.java 4 May 2003 20:19:41 -0000 1.1
+++ DefaultFormManager.java 6 May 2003 17:08:26 -0000 1.2
@@ -50,32 +50,27 @@
*/
package org.apache.cocoon.webapps.session.components;
-import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
-import org.apache.avalon.excalibur.pool.Recyclable;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Composable;
-import org.apache.avalon.framework.component.Recomposable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.components.RequestLifecycleComponent;
+import org.apache.cocoon.components.CocoonComponentManager;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
-import org.apache.cocoon.environment.Response;
import org.apache.cocoon.environment.Session;
-import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.webapps.session.ContextManager;
import org.apache.cocoon.webapps.session.FormManager;
import org.apache.cocoon.webapps.session.SessionConstants;
import org.apache.cocoon.webapps.session.SessionManager;
import org.apache.cocoon.webapps.session.context.SessionContext;
import org.w3c.dom.DocumentFragment;
-import org.xml.sax.SAXException;
/**
* Form handling
@@ -85,7 +80,8 @@
*/
public final class DefaultFormManager
extends AbstractLogEnabled
-implements Composable, Component, Recomposable, Recyclable, FormManager, RequestLifecycleComponent {
+implements Composable, Component, FormManager, ThreadSafe
+ /*,RequestProcessingListener, SitemapProcessingListener*/ {
/** This session attribute is used to store the information for the inputxml tags */
private static final String ATTRIBUTE_INPUTXML_STORAGE = "org.apache.cocoon.webapps.session.InputXMLStorage";
@@ -93,15 +89,6 @@
/** The <code>ComponentManager</code> */
private ComponentManager manager;
- /** The request */
- private Request request;
- /** The response */
- private Response response;
- /** The object model */
- private Map objectModel;
- /** The resolver */
- private SourceResolver resolver;
-
/**
* Avalon Composer Interface
*/
@@ -110,51 +97,6 @@
}
/**
- * Recomposable
- */
- public void recompose( ComponentManager componentManager )
- throws ComponentException {
- this.manager = componentManager;
- }
-
- /**
- * Set the <code>SourceResolver</code>, objectModel <code>Map</code>,
- * used to process the request.
- * Set up the SessionManager.
- * This method is automatically called for each request. Do not invoke
- * this method by hand.
- */
- public void setup(SourceResolver resolver, Map objectModel)
- throws ProcessingException, SAXException, IOException {
- // no sync required
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("BEGIN setup objectModel=" + objectModel);
- }
- this.objectModel = objectModel;
- this.request = ObjectModelHelper.getRequest(objectModel);
- this.response = ObjectModelHelper.getResponse(objectModel);
- this.resolver = resolver;
-
- this.processInputFields();
-
- if (this.getLogger().isDebugEnabled() ) {
- this.getLogger().debug("END setup");
- }
- }
-
- /**
- * Recycling the SessionManager.
- * This method is automatically called after each request. Do not invoke
- * this method by hand.
- */
- public void recycle() {
- this.objectModel = null;
- this.request = null;
- this.response = null;
- this.resolver = null;
- }
-
- /**
* Get the context
*/
private SessionContext getContext(String name)
@@ -184,8 +126,7 @@
}
/**
- * Register input field and return the current value of the field.
- * This is a private method and should not be invoked directly.
+ * @see FormManager.registerInputField(String, String, String, String)
*/
public DocumentFragment registerInputField(String contextName,
String path,
@@ -216,7 +157,9 @@
if (context == null) {
throw new ProcessingException("SessionManager.registerInputField: Context not found " + contextName);
}
- Session session = this.request.getSession(false);
+ final Map objectModel = CocoonComponentManager.getCurrentEnvironment().getObjectModel();
+ final Request request = ObjectModelHelper.getRequest( objectModel );
+ Session session = request.getSession(false);
if (session == null) {
throw new ProcessingException("SessionManager.registerInputField: Session is required for context " + contextName);
}
@@ -243,41 +186,50 @@
* any values.
* This is a private method and should not be invoked directly.
*/
- private void processInputFields()
- throws ProcessingException {
+ private void processInputFields(Map objectModel) {
+ // we only want to invoke the testing once per request
+ if (objectModel.containsKey(this.getClass().getName())) {
+ return;
+ }
+ objectModel.put(this.getClass().getName(), "done");
+
// synchronized
if (this.getLogger().isDebugEnabled() ) {
this.getLogger().debug("BEGIN processInputFields");
}
- final String formName = this.request.getParameter(SessionConstants.SESSION_FORM_PARAMETER);
+ final Request request = ObjectModelHelper.getRequest( objectModel );
+ final String formName = request.getParameter(SessionConstants.SESSION_FORM_PARAMETER);
if ( null != formName ) {
- final Session session = this.request.getSession(false);
+ final Session session = request.getSession(false);
if (session != null) {
synchronized(session) {
final Map inputFields = (Map)session.getAttribute(ATTRIBUTE_INPUTXML_STORAGE);
if (inputFields != null) {
- final Enumeration keys = this.request.getParameterNames();
+ final Enumeration keys = request.getParameterNames();
String currentKey;
Object[] contextAndPath;
- while (keys.hasMoreElements() == true) {
+ while (keys.hasMoreElements()) {
currentKey = (String)keys.nextElement();
- if (inputFields.containsKey(currentKey) == true) {
+ if (inputFields.containsKey(currentKey)) {
contextAndPath = (Object[])inputFields.get(currentKey);
inputFields.remove(currentKey);
SessionContext context = (SessionContext)contextAndPath[0];
String path = (String)contextAndPath[1];
- if (formName.equals(contextAndPath[2]) == true) {
- context.setXML(path,
- this.getContextFragment(SessionConstants.REQUEST_CONTEXT, "/parameter/"+currentKey));
+ if (formName.equals(contextAndPath[2])) {
+ try {
+ context.setXML(path,
+ this.getContextFragment(SessionConstants.REQUEST_CONTEXT, "/parameter/"+currentKey));
+ } catch (ProcessingException ignore) {
+ this.getLogger().warn("Exception during processing of input fields.", ignore);
+ }
}
}
}
}
- // inputFields.clear();
}
}
}
@@ -287,5 +239,22 @@
}
}
+ public void processInputFields() {
+ final Map objectModel = CocoonComponentManager.getCurrentEnvironment().getObjectModel();
+ this.processInputFields( objectModel ) ;
+ }
+
+ public void sitemapProcessingStarted(Map objectModel) {
+ this.processInputFields( objectModel );
+ }
+
+ public void sitemapProcessingEnded(Map objectModel) {
+ }
+
+ public void requestProcessingStarted(Map objectModel) {
+ this.processInputFields( objectModel );
+ }
+ public void requestProcessingEnded(Map objectModel) {
+ }
}