haul 2003/01/09 09:04:18 Modified: src/java/org/apache/cocoon/components/modules modules.xconf src/java/org/apache/cocoon/components/modules/output AbstractOutputModule.java OutputModule.java RequestAttributeMap.java RequestAttributeOutputModule.java SessionAttributeOutputModule.java src/java/org/apache/cocoon/components/modules/input AbstractJXPathModule.java JXPathMetaModule.java Added: src/java/org/apache/cocoon/components/modules/input XMLFormInput.java Log: <action dev="CH" type="add"> InputModule to access XMLForm instances. </action> <action dev="CH" type="add"> Created additional isolation level for some OutputModules. <action> Revision Changes Path 1.14 +26 -11 xml-cocoon2/src/java/org/apache/cocoon/components/modules/modules.xconf Index: modules.xconf =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/modules.xconf,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- modules.xconf 16 Dec 2002 10:53:01 -0000 1.13 +++ modules.xconf 9 Jan 2003 17:04:17 -0000 1.14 @@ -19,24 +19,39 @@ <component-instance logger="core.modules.input" name="nullinput" class="org.apache.cocoon.components.modules.input.NullInputModule"/> <component-instance logger="core.modules.input" name="xmlmeta" class="org.apache.cocoon.components.modules.input.XMLMetaModule"/> <component-instance logger="core.modules.input" name="mapmeta" class="org.apache.cocoon.components.modules.input.MapMetaModule"/> - <component-instance logger="core.modules.input" name="defaults" class="org.apache.cocoon.components.modules.input.DefaultsMetaModule"> - <values> - <skin>defaultSkin</skin> - <base-url>http://localhost:8080/cocoon</base-url> - </values> - </component-instance> + <component-instance logger="core.modules.input" name="datemeta" class="org.apache.cocoon.components.modules.input.DateMetaInputModule"/> + <component-instance logger="core.modules.input" name="xmlform" class="org.apache.cocoon.components.modules.input.XMLFormInput"/> <component-instance logger="core.modules.input" name="chain" class="org.apache.cocoon.components.modules.input.ChainMetaModule"> <input-module name="request-param"/> <input-module name="request-attr"/> <input-module name="session-attr"/> <input-module name="defaults"/> </component-instance> - <component-instance class="org.apache.cocoon.components.modules.input.XMLFileModule" logger="core.modules.xml" name="myxml"> - <file src="context:///samples/modules/forrestconf.xml"/> - </component-instance> - <component-instance class="org.apache.cocoon.components.modules.input.XMLFileModule" logger="core.modules.xml" name="slashdot"> - <file src="http://slashdot.org/slashdot.rss"/> + <!-- sample --> + <!-- + <component-instance logger="core.modules.input" name="defaults" class="org.apache.cocoon.components.modules.input.DefaultsMetaModule"> + <values> + <skin>defaultSkin</skin> + <base-url>http://localhost:8080/cocoon</base-url> + </values> + </component-instance> + --> + <!-- LinkRewritingTransformer Sample --> + <component-instance + class="org.apache.cocoon.components.modules.input.XMLFileModule" + logger="core.modules.xml" name="linkmap"> + <file src="cocoon://samples/link/linkmap"/> + <!-- Shouldn't this be the default? --> + <reloadable>true</reloadable> </component-instance> + <component-instance + class="org.apache.cocoon.components.modules.input.SimpleMappingMetaModule" + logger="core.modules.mapper" name="site"> + <input-module name="linkmap"/> + <prefix>/site/</prefix> + <suffix>/@href</suffix> + </component-instance> + <!-- end LinkRewritingTransformer Sample --> </input-modules> <output-modules> 1.3 +78 -2 xml-cocoon2/src/java/org/apache/cocoon/components/modules/output/AbstractOutputModule.java Index: AbstractOutputModule.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/output/AbstractOutputModule.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AbstractOutputModule.java 31 Jul 2002 13:13:24 -0000 1.2 +++ AbstractOutputModule.java 9 Jan 2003 17:04:17 -0000 1.3 @@ -51,12 +51,15 @@ package org.apache.cocoon.components.modules.output; +import java.util.Map; + import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.logger.AbstractLogEnabled; - +import org.apache.cocoon.environment.ObjectModelHelper; +import org.apache.cocoon.environment.Request; import org.apache.cocoon.util.HashMap; /** @@ -109,4 +112,77 @@ // Purposely empty so that we don't need to implement it in every // class. } + + /** + * Utility method to store parameters in a map as request attribute until + * either {@link #rollback rollback} or {@link #prepareCommit prepareCommit} + * is called. + * @param objectModel - the objectModel + * @param trans_place - request attribute name used for the transient data + * @param name - name of the attribute to set + * @param value - attribute value + */ + protected void transientSetAttribute( Map objectModel, String trans_place, String name, Object value ) { + + Request request = ObjectModelHelper.getRequest(objectModel); + Object temp = request.getAttribute(trans_place); + Map aMap = null; + + if (temp == null) { + aMap = new HashMap(); + } else { + aMap = (Map) temp; + } + + aMap.put(name,value); + + request.setAttribute(trans_place, aMap); + } + + /** + * Clears all uncommitted transient attributes. + * @param objectModel - the objectModel + * @param trans_place - request attribute name used for the transient data + */ + protected void rollback( Map objectModel, String trans_place) { + ObjectModelHelper.getRequest(objectModel).setAttribute(trans_place, null); + } + + /** + * Returns a whether an transient attribute already exists. + * {@link #transientSetAttribute transientSetAttribute} since the last call to + * {@link #rollback rollback} or {@link #prepareCmmit prepareCommit} + * @param objectModel - the objectModel + * @param trans_place - request attribute name used for the transient data + */ + protected boolean attributeExists( Map objectModel, String trans_place, String name ) + { + Request request = ObjectModelHelper.getRequest(objectModel); + Object temp = request.getAttribute(trans_place); + if (temp == null) { + return false; + } else { + return ((Map) temp).containsKey(name); + } + } + + /** + * Returns a map containing all transient attributes and remove them i.e. attributes set with + * {@link #transientSetAttribute transientSetAttribute} since the last call to + * {@link #rollback rollback} or {@link #prepareCmmit prepareCommit} + * @param objectModel - the objectModel + * @param trans_place - request attribute name used for the transient data + */ + protected Map prepareCommit( Map objectModel, String trans_place ) + { + Request request = ObjectModelHelper.getRequest(objectModel); + Object temp = request.getAttribute(trans_place); + request.setAttribute(trans_place, null); + if (temp == null) { + return null; + } else { + return (Map) temp; + } + } + } 1.6 +7 -3 xml-cocoon2/src/java/org/apache/cocoon/components/modules/output/OutputModule.java Index: OutputModule.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/output/OutputModule.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- OutputModule.java 12 Aug 2002 07:50:54 -0000 1.5 +++ OutputModule.java 9 Jan 2003 17:04:17 -0000 1.6 @@ -51,9 +51,10 @@ package org.apache.cocoon.components.modules.output; +import java.util.Map; + import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.configuration.Configuration; -import java.util.Map; /** * Communicate results to other components. This could be done via @@ -70,7 +71,10 @@ String ROLE = OutputModule.class.getName(); /** - * communicate an attribute value to further processing logic. + * communicate an attribute value to further processing logic. OutputModules + * work in implicit transaction mode, thus setting an attribute starts an + * transaction and sttributes are only visible after the transaction is + * successfully completed with a call to commit * @param modeConf column's mode configuration from resource * description. This argument is optional. * @param objectModel The objectModel 1.2 +30 -48 xml-cocoon2/src/java/org/apache/cocoon/components/modules/output/RequestAttributeMap.java Index: RequestAttributeMap.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/output/RequestAttributeMap.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- RequestAttributeMap.java 16 Dec 2002 10:52:34 -0000 1.1 +++ RequestAttributeMap.java 9 Jan 2003 17:04:17 -0000 1.2 @@ -1,36 +1,36 @@ /* - + ============================================================================ The Apache Software License, Version 1.1 ============================================================================ - + Copyright (C) 1999-2002 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 [EMAIL PROTECTED] - + 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 @@ -41,23 +41,22 @@ 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 <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. - -*/ + + */ package org.apache.cocoon.components.modules.output; +import java.util.Map; + import org.apache.avalon.framework.configuration.Configuration; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Request; -import java.util.Map; -import java.util.HashMap; - /** * Abstraction layer to encapsulate different output * destinations. This module outputs to a request attribute @@ -69,10 +68,10 @@ * @version CVS $Id$ */ public class RequestAttributeMap extends AbstractOutputModule implements OutputModule { - + public final String PREFIX = "org.apache.cocoon.components.modules.output.OutputModule"; public final String TRANS_PREFIX = "org.apache.cocoon.components.modules.output.OutputModule.RequestAttributeMap.transient"; - + /** * communicate an attribute value to further processing logic. * @param modeConf column's mode configuration from resource @@ -84,22 +83,10 @@ * @param value The attriute's value. * */ public void setAttribute( Configuration modeConf, Map objectModel, String name, Object value ) { - - Request request = ObjectModelHelper.getRequest(objectModel); - Object temp = request.getAttribute(TRANS_PREFIX); - Map aMap = null; - if (temp == null) { - aMap = new HashMap(); - } else { - aMap = (Map) temp; - } - - aMap.put(name,value); - - request.setAttribute(TRANS_PREFIX, aMap); + super.transientSetAttribute(objectModel, TRANS_PREFIX, name, value ); } - - + + /** * If a database transaction needs to rollback, this is called to * inform the further processing logic about this fact. All @@ -110,28 +97,24 @@ * in data corruption!</em> * */ public void rollback( Configuration modeConf, Map objectModel, Exception e ) { - ObjectModelHelper.getRequest(objectModel).setAttribute(TRANS_PREFIX, null); + super.rollback(objectModel, TRANS_PREFIX); } - - + + /** * Signal that the database transaction completed * successfully. See notes on @link{rollback}. * */ - public void commit( Configuration modeConf, Map objectModel ) - { - Request request = ObjectModelHelper.getRequest(objectModel); - Object temp = request.getAttribute(TRANS_PREFIX); - Map aMap = null; - if (temp == null) { + public void commit( Configuration modeConf, Map objectModel ) { + Map aMap = super.prepareCommit(objectModel,TRANS_PREFIX); + if (aMap == null) { // nothing to do return; - } else { - aMap = (Map) temp; } - + String prefix = (String) this.settings.get("key-prefix", PREFIX); - temp = request.getAttribute(prefix); + Request request = ObjectModelHelper.getRequest(objectModel); + Object temp = request.getAttribute(prefix); Map old = null; if (temp == null) { old = aMap; @@ -140,7 +123,6 @@ old.putAll(aMap); } request.setAttribute(prefix, old); - request.setAttribute(TRANS_PREFIX, null); } - + } 1.6 +105 -38 xml-cocoon2/src/java/org/apache/cocoon/components/modules/output/RequestAttributeOutputModule.java Index: RequestAttributeOutputModule.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/output/RequestAttributeOutputModule.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- RequestAttributeOutputModule.java 5 Dec 2002 10:10:46 -0000 1.5 +++ RequestAttributeOutputModule.java 9 Jan 2003 17:04:17 -0000 1.6 @@ -1,36 +1,36 @@ /* - + ============================================================================ The Apache Software License, Version 1.1 ============================================================================ - + Copyright (C) 1999-2002 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 [EMAIL PROTECTED] - + 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 @@ -41,31 +41,43 @@ 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 <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. - -*/ + + */ package org.apache.cocoon.components.modules.output; +import java.util.Iterator; +import java.util.Map; + import org.apache.avalon.framework.configuration.Configuration; import org.apache.cocoon.environment.ObjectModelHelper; - -import java.util.Map; +import org.apache.cocoon.environment.Request; /** * Abstraction layer to encapsulate different output * destinations. Configuration option <key-prefix> defaults to * "org.apache.cocoon.components.modules.output.OutputModule"+":" * + * Can be used with different isolation-level: default is "0" being + * no isolation at all, values are immediately visible but are removed + * on a rollback; "1" keeps the values at a save place until either + * rollback or commit is called. Then values are either discarded or + * copied to the final destination. + * * @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a> * @version CVS $Id$ */ public class RequestAttributeOutputModule extends AbstractOutputModule implements OutputModule { - + + public final String PREFIX = "org.apache.cocoon.components.modules.output.OutputModule"; + public final String TRANS_PREFIX = "org.apache.cocoon.components.modules.output.OutputModule.RequestAttributeOutputModule.transient"; + public final String ROLLBACK_LIST = "org.apache.cocoon.components.modules.output.OutputModule.RequestAttributeOutputModule.rollback"; + /** * communicate an attribute value to further processing logic. * @param modeConf column's mode configuration from resource @@ -77,16 +89,26 @@ * @param value The attriute's value. * */ public void setAttribute( Configuration modeConf, Map objectModel, String name, Object value ) { - - String prefix = (String) this.settings.get("key-prefix", "org.apache.cocoon.components.modules.output.OutputModule" ); - if (prefix != "") { - ObjectModelHelper.getRequest(objectModel).setAttribute(prefix+":"+name, value); + if (this.settings.get("isolation-level","0").equals("1")) { + this.transientSetAttribute(objectModel, TRANS_PREFIX, name, value); } else { - ObjectModelHelper.getRequest(objectModel).setAttribute(name, value); - } - } + // use read uncommitted isolation level + + Request request = ObjectModelHelper.getRequest(objectModel); + + name = getName(name); + if (!this.attributeExists(objectModel, ROLLBACK_LIST, name)) { + Object tmp = request.getAttribute(name); + this.transientSetAttribute(objectModel, ROLLBACK_LIST, name, tmp); + } + request.setAttribute(name, value); + } + } + + + /** * If a database transaction needs to rollback, this is called to * inform the further processing logic about this fact. All @@ -97,31 +119,76 @@ * in data corruption!</em> * */ public void rollback( Configuration modeConf, Map objectModel, Exception e ) { - /* - Enumeration attributes = request.getAttributeNames(); - while ( attributes.hasMoreElements() ) { - String name = (String) attributes.nextElement(); - if ( name.startsWith("org.apache.cocoon.acting.ModularDatabaseAccess.OutputModule:") ) { - request.removeAttribute(name); - } - } - */ - String prefix = (String) this.settings.get("key-prefix", "org.apache.cocoon.components.modules.output.OutputModule" ); + if (this.settings.get("isolation-level","0").equals("1")) { + this.rollback(objectModel, TRANS_PREFIX); + } else { + + Request request = ObjectModelHelper.getRequest(objectModel); + Object tmp = this.prepareCommit(objectModel,ROLLBACK_LIST); + if (tmp != null) { + Map rollbackList = (Map) tmp; + Iterator iter = rollbackList.keySet().iterator(); + while(iter.hasNext()) { + String key = (String) iter.next(); + Object val = rollbackList.get(key); + if (val != null) { + request.setAttribute(key, val); + } else { + request.removeAttribute(key); + } + } + } + } + + String prefix = (String) this.settings.get("key-prefix", PREFIX ); if (prefix!="") { ObjectModelHelper.getRequest(objectModel).setAttribute(prefix+":",e.getMessage()); } else { ObjectModelHelper.getRequest(objectModel).setAttribute("errorMessage",e.getMessage()); } } - - + + /** * Signal that the database transaction completed * successfully. See notes on @link{rollback}. * */ - public void commit( Configuration modeConf, Map objectModel ) - { - // empty method + public void commit( Configuration modeConf, Map objectModel ) { + if (this.settings.get("isolation-level","0").equals("1")) { + Map aMap = this.prepareCommit(objectModel, TRANS_PREFIX); + if (aMap == null) { + return; + } + + Iterator iter = aMap.keySet().iterator(); + if (!iter.hasNext()){ + return; + } + + String prefix = (String) this.settings.get("key-prefix", PREFIX ); + if (prefix != "") { + prefix = prefix+":"; + } else { + prefix = null; + } + Request request = ObjectModelHelper.getRequest(objectModel); + while (iter.hasNext()) { + String key = (String) iter.next(); + Object value = aMap.get(key); + if (prefix != null) { key = prefix + key; } + request.setAttribute(key, value); + } + + } else { + this.prepareCommit(objectModel, ROLLBACK_LIST); + } + + } + protected String getName( String name ) { + String prefix = (String) this.settings.get("key-prefix", PREFIX ); + return (prefix == "" ? name : prefix+":"+name); + } + } 1.5 +105 -48 xml-cocoon2/src/java/org/apache/cocoon/components/modules/output/SessionAttributeOutputModule.java Index: SessionAttributeOutputModule.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/output/SessionAttributeOutputModule.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- SessionAttributeOutputModule.java 9 Aug 2002 08:32:10 -0000 1.4 +++ SessionAttributeOutputModule.java 9 Jan 2003 17:04:17 -0000 1.5 @@ -1,36 +1,36 @@ /* - + ============================================================================ The Apache Software License, Version 1.1 ============================================================================ - + Copyright (C) 1999-2002 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 [EMAIL PROTECTED] - + 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 @@ -41,35 +41,45 @@ 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 <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. - -*/ + + */ package org.apache.cocoon.components.modules.output; -import java.util.Enumeration; +import java.util.Iterator; import java.util.Map; -import org.apache.cocoon.environment.Request; -import org.apache.cocoon.environment.Session; -import org.apache.cocoon.environment.ObjectModelHelper; + import org.apache.avalon.framework.configuration.Configuration; +import org.apache.cocoon.environment.ObjectModelHelper; +import org.apache.cocoon.environment.Session; /** * Abstraction layer to encapsulate different output * destinations. Configuration option <key-prefix> defaults to * "org.apache.cocoon.components.modules.output.OutputModule"+":" * + * Can be used with different isolation-level: default is "0" being + * no isolation at all, values are immediately visible but are removed + * on a rollback; "1" keeps the values at a save place until either + * rollback or commit is called. Then values are either discarded or + * copied to the final destination. + * * @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a> * @version CVS $Id$ - * */ + */ public class SessionAttributeOutputModule extends AbstractOutputModule implements OutputModule { + public final String PREFIX = "org.apache.cocoon.components.modules.output.OutputModule"; + public final String TRANS_PREFIX = "org.apache.cocoon.components.modules.output.OutputModule.SessionAttributeOutputModule.transient"; + public final String ROLLBACK_LIST = "org.apache.cocoon.components.modules.output.OutputModule.SessionAttributeOutputModule.rollback"; + /** - * communicate an attribute value to further processing logic. + * communicate an attribute value to further processing logic. * @param modeConf column's mode configuration from resource * description. This argument is optional. * @param request The request object @@ -79,19 +89,27 @@ * @param value The attriute's value. * */ public void setAttribute( Configuration modeConf, Map objectModel, String name, Object value ) { - - String prefix = (String) this.settings.get("key-prefix", "org.apache.cocoon.components.modules.output.OutputModule" ); - Request req = ObjectModelHelper.getRequest(objectModel); - Session ses = req.getSession(); - if (ses == null || !req.isRequestedSessionIdValid()) ses = req.getSession(true); - if (prefix!="") { - ses.setAttribute(prefix + ":" + name, value); + if (this.settings.get("isolation-level","0").equals("1")) { + this.transientSetAttribute(objectModel, TRANS_PREFIX, name, value); } else { - ses.setAttribute(name, value); - } - } + // use read uncommitted isolation level + + Session session = ObjectModelHelper.getRequest(objectModel).getSession(); + name = getName(name); + if (!this.attributeExists(objectModel, ROLLBACK_LIST, name)) { + Object tmp = session.getAttribute(name); + this.transientSetAttribute(objectModel, ROLLBACK_LIST, name, tmp); + } + + session.setAttribute(name, value); + } + + } + + + /** * If a database transaction needs to rollback, this is called to * inform the further processing logic about this fact. All @@ -102,36 +120,75 @@ * in data corruption!</em> * */ public void rollback( Configuration modeConf, Map objectModel, Exception e ) { + if (this.settings.get("isolation-level","0").equals("1")) { + this.rollback(objectModel, TRANS_PREFIX); + } else { - Request request = ObjectModelHelper.getRequest(objectModel); - Enumeration attributes = request.getSession().getAttributeNames(); - String prefix = (String) this.settings.get("key-prefix", - "org.apache.cocoon.components.modules.output.OutputModule"); - while ( attributes.hasMoreElements() ) { - String name = (String) attributes.nextElement(); - if ( name.startsWith(prefix) ) { - request.getSession().removeAttribute(name); + Session session = ObjectModelHelper.getRequest(objectModel).getSession(); + Object tmp = this.prepareCommit(objectModel,ROLLBACK_LIST); + if (tmp != null) { + Map rollbackList = (Map) tmp; + Iterator iter = rollbackList.keySet().iterator(); + while(iter.hasNext()) { + String key = (String) iter.next(); + Object val = rollbackList.get(key); + if (val != null) { + session.setAttribute(key, val); + } else { + session.removeAttribute(key); + } + } } } + + String prefix = (String) this.settings.get("key-prefix", PREFIX ); if (prefix!="") { - request - .getSession() - .setAttribute(prefix + ":", e.getMessage()); + ObjectModelHelper.getRequest(objectModel).getSession().setAttribute(prefix+":",e.getMessage()); } else { - request - .getSession() - .setAttribute("errorMessage", e.getMessage()); + ObjectModelHelper.getRequest(objectModel).getSession().setAttribute("errorMessage",e.getMessage()); } } - - + + /** * Signal that the database transaction completed * successfully. See notes on @link{rollback}. * */ - public void commit( Configuration modeConf, Map objectModel ) - { - // empty method + public void commit( Configuration modeConf, Map objectModel ) { + if (this.settings.get("isolation-level","0").equals("1")) { + Map aMap = this.prepareCommit(objectModel, TRANS_PREFIX); + if (aMap == null) { + return; + } + + Iterator iter = aMap.keySet().iterator(); + if (!iter.hasNext()){ + return; + } + + String prefix = (String) this.settings.get("key-prefix", PREFIX ); + if (prefix != "") { + prefix = prefix+":"; + } else { + prefix = null; + } + Session session = ObjectModelHelper.getRequest(objectModel).getSession(); + while (iter.hasNext()) { + String key = (String) iter.next(); + Object value = aMap.get(key); + if (prefix != null) { key = prefix + key; } + session.setAttribute(key, value); + } + + } else { + this.prepareCommit(objectModel, ROLLBACK_LIST); + } + + } + + protected String getName( String name ) { + String prefix = (String) this.settings.get("key-prefix", PREFIX ); + return (prefix == "" ? name : prefix+":"+name); } } 1.8 +5 -3 xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/AbstractJXPathModule.java Index: AbstractJXPathModule.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/AbstractJXPathModule.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- AbstractJXPathModule.java 16 Dec 2002 10:37:33 -0000 1.7 +++ AbstractJXPathModule.java 9 Jan 2003 17:04:18 -0000 1.8 @@ -215,11 +215,11 @@ } - public Object getAttribute(String name, Configuration modeConf, - Map objectModel) + public Object getAttribute(String name, Configuration modeConf, Map objectModel) throws ConfigurationException { Object contextObj = getContextObject(modeConf, objectModel); + if (contextObj == null) return null; try { JXPathContext jxContext = JXPathContext.newContext(contextObj); setupExtensions(jxContext, modeConf); @@ -238,6 +238,7 @@ throws ConfigurationException { Object contextObj = getContextObject(modeConf, objectModel); + if (contextObj == null) return null; try { JXPathBeanInfo info = JXPathIntrospector.getBeanInfo( contextObj.getClass()); @@ -261,6 +262,7 @@ throws ConfigurationException { Object contextObj = getContextObject(modeConf, objectModel); + if (contextObj == null) return null; try { JXPathContext jxContext = JXPathContext.newContext(contextObj); List values = new LinkedList(); 1.6 +4 -1 xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/JXPathMetaModule.java Index: JXPathMetaModule.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/JXPathMetaModule.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- JXPathMetaModule.java 17 Dec 2002 14:53:16 -0000 1.5 +++ JXPathMetaModule.java 9 Jan 2003 17:04:18 -0000 1.6 @@ -238,6 +238,7 @@ throws ConfigurationException { Object contextObj = getContextObject(modeConf, objectModel); + if (contextObj == null) return null; try { JXPathContext jxContext = JXPathContext.newContext(contextObj); setupExtensions(jxContext, modeConf); @@ -258,6 +259,7 @@ throws ConfigurationException { Object contextObj = getContextObject(modeConf, objectModel); + if (contextObj == null) return null; try { JXPathBeanInfo info = JXPathIntrospector.getBeanInfo( contextObj.getClass()); @@ -281,6 +283,7 @@ throws ConfigurationException { Object contextObj = getContextObject(modeConf, objectModel); + if (contextObj == null) return null; try { JXPathContext jxContext = JXPathContext.newContext(contextObj); List values = new LinkedList(); 1.1 xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/XMLFormInput.java Index: XMLFormInput.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 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 [EMAIL PROTECTED] 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 <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.components.modules.input; import java.util.Map; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.components.xmlform.Form; /** * Accesses the form model of an * {@link org.apache.cocoon.components.xmlform.Form XMLForm Instance}. * The xmlform-id needs to be passed with the configuration. Additionally supports * all configuration options from {@link AbstractJXPathModule AbstractJXPathModule}. * This can be used for example to let the * {@link org.apache.cocoon.acting.modular.DatabaseAction database actions} access * form data. * * <p>Configuration example:</p> * <table> * <tr><td><code><xmlform-id>form-feedback</xmlform-id></td> * <td>XMLForm ID to use.</td> * </tr></table> * * @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a> * @version $Id: XMLFormInput.java,v 1.1 2003/01/09 17:04:18 haul Exp $ */ public class XMLFormInput extends AbstractJXPathModule implements ThreadSafe { String formId = null; /** * Configure component. Preprocess list of packages and functions * to add to JXPath context later. * * @param conf a <code>Configuration</code> value * @exception ConfigurationException if an error occurs */ public void configure(Configuration config) throws ConfigurationException { this.formId = config.getChild("xmlform-id").getValue(null); super.configure(config); } /** Returns the object which should be used as JXPath context. * Descendants should override this method to return a specific object * that is requried by the implementing class. * Examples are: request, session and application context objects. * */ protected Object getContextObject(Configuration modeConf, Map objectModel) throws ConfigurationException { String id = this.formId; if (modeConf != null) { id = modeConf.getAttribute("xmlform-id", this.formId); } Form form = Form.lookup(objectModel,id); Object tmp = null; if (form != null) { tmp = form.getModel(); } return tmp; } }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]