cziegeler 2003/05/04 13:19:42
Modified: src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/user UserHandler.java RequestState.java src/blocks/session-fw/java/org/apache/cocoon/webapps/session/transformation SessionPostTransformer.java AbstractSessionTransformer.java SessionPreTransformer.java src/blocks/portal-fw/java/org/apache/cocoon/webapps/portal/components PortalManager.java src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting AuthAction.java LoginAction.java LogoutAction.java LoggedInAction.java src/blocks/session-fw/conf session.xconf session.xroles src/blocks/session-fw/java/org/apache/cocoon/webapps/session/context ResponseSessionContext.java RequestSessionContext.java SimpleSessionContext.java StandardSessionContextProvider.java SessionContextProvider.java src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components Authenticator.java DefaultAuthenticationManager.java src/blocks/portal-fw/java/org/apache/cocoon/webapps/portal/context SessionContextImpl.java SessionContextProviderImpl.java src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/context AuthenticationContext.java AuthenticationContextProvider.java src/blocks/session-fw/java/org/apache/cocoon/webapps/session/components AbstractSessionComponent.java src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication AuthenticationConstants.java src/blocks/session-fw/java/org/apache/cocoon/webapps/session/acting SessionFormAction.java SessionAction.java src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/generation ConfigurationGenerator.java . status.xml src/blocks/portal-fw/java/org/apache/cocoon/webapps/portal/generation PortalGenerator.java Added: src/blocks/session-fw/conf session-sel.xmap src/blocks/session-fw/java/org/apache/cocoon/webapps/session TransactionManager.java FormManager.java ContextManager.java SessionManager.java MediaManager.java src/blocks/session-fw/java/org/apache/cocoon/webapps/session/components DefaultContextManager.java DefaultTransactionManager.java DefaultMediaManager.java DefaultSessionManager.java DefaultFormManager.java src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication AuthenticationManager.java src/blocks/session-fw/java/org/apache/cocoon/webapps/session/selection MediaSelector.java Removed: src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting NewLoginAction.java NewLoggedInAction.java NewLogoutAction.java NewAuthAction.java src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components DefaultMediaManager.java Handler.java ApplicationHandler.java AuthenticationManager.java Manager.java HandlerManager.java src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/context SessionContextImpl.java SessionContextProviderImpl.java src/blocks/session-fw/java/org/apache/cocoon/webapps/session/components SessionManager.java src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication MediaManager.java src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/selection MediaSelector.java Log: Redesign/Modularizing the session and authentication framework Revision Changes Path 1.4 +74 -1 cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/user/UserHandler.java Index: UserHandler.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/user/UserHandler.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- UserHandler.java 1 May 2003 09:49:14 -0000 1.3 +++ UserHandler.java 4 May 2003 20:19:39 -0000 1.4 @@ -50,13 +50,22 @@ */ package org.apache.cocoon.webapps.authentication.user; +import java.io.IOException; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; +import org.apache.avalon.framework.component.Component; +import org.apache.avalon.framework.component.ComponentException; +import org.apache.avalon.framework.component.ComponentManager; import org.apache.cocoon.ProcessingException; +import org.apache.cocoon.components.CocoonComponentManager; import org.apache.cocoon.webapps.authentication.configuration.ApplicationConfiguration; import org.apache.cocoon.webapps.authentication.configuration.HandlerConfiguration; import org.apache.cocoon.webapps.authentication.context.AuthenticationContext; +import org.apache.cocoon.webapps.session.ContextManager; +import org.apache.cocoon.webapps.session.context.SessionContext; +import org.xml.sax.SAXException; /** * The authentication Handler. @@ -79,6 +88,9 @@ /** Loaded List */ private List loadedApps = new ArrayList(3); + /** Application contexts */ + private List applicationContexts; + /** * Create a new handler object. */ @@ -108,6 +120,41 @@ } /** + * Create Application Context. + * This context is destroyed when the user logs out of the handler + */ + public synchronized SessionContext createApplicationContext(String name, + String loadURI, + String saveURI) + throws ProcessingException { + + SessionContext context = null; + + ComponentManager manager = CocoonComponentManager.getSitemapComponentManager(); + ContextManager contextManager = null; + try { + contextManager = (ContextManager)manager.lookup(ContextManager.ROLE); + // create new context + context = contextManager.createContext(name, loadURI, saveURI); + if ( this.applicationContexts == null) { + this.applicationContexts = new ArrayList(3); + } + this.applicationContexts.add( name ); + + } catch (ComponentException ce) { + throw new ProcessingException("Unable to create session context.", ce); + } catch (IOException ioe) { + throw new ProcessingException("Unable to create session context.", ioe); + } catch (SAXException saxe) { + throw new ProcessingException("Unable to create session context.", saxe); + } finally { + manager.release( (Component)contextManager); + } + + return context; + } + + /** * Get the handler name */ public String getHandlerName() { @@ -128,5 +175,31 @@ public void setApplicationIsLoaded(ApplicationConfiguration appConf) { this.loadedApps.add( appConf ); this.appsLoaded = (this.loadedApps.size() == this.handler.getApplications().size()); + } + + /** + * Terminate the handler + */ + public void terminate() + throws ProcessingException { + ComponentManager manager = CocoonComponentManager.getSitemapComponentManager(); + + if ( this.applicationContexts != null ) { + ContextManager contextManager = null; + + try { + contextManager = (ContextManager)manager.lookup(ContextManager.ROLE); + + Iterator i = this.applicationContexts.iterator(); + while ( i.hasNext() ) { + final String current = (String)i.next(); + contextManager.deleteContext( current ); + } + } catch (ComponentException ce) { + throw new ProcessingException("Unable to create session context.", ce); + } finally { + manager.release( (Component)contextManager); + } + } } } 1.3 +20 -2 cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/user/RequestState.java Index: RequestState.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/user/RequestState.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- RequestState.java 27 Apr 2003 14:45:03 -0000 1.2 +++ RequestState.java 4 May 2003 20:19:39 -0000 1.3 @@ -52,6 +52,7 @@ import java.util.Map; +import org.apache.avalon.framework.configuration.Configuration; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.components.CocoonComponentManager; import org.apache.cocoon.webapps.authentication.configuration.ApplicationConfiguration; @@ -101,7 +102,7 @@ if ( this.application != null && !this.handler.getApplicationsLoaded()) { ApplicationConfiguration conf = (ApplicationConfiguration) this.handler.getHandlerConfiguration().getApplications().get(this.application); if ( !this.handler.isApplicationLoaded( conf ) ) { - this.handler.createContext().loadApplicationXML( conf, resolver ); + this.handler.getContext().loadApplicationXML( conf, resolver ); } } } @@ -124,4 +125,21 @@ } return null; } + + /** + * Get the configuration if available + */ + public Configuration getModuleConfiguration(String name) + throws ProcessingException { + Configuration conf = null; + + if (this.handler != null && this.application != null) { + conf = this.getApplicationConfiguration().getConfiguration(name); + } + if (this.handler != null && conf == null) { + conf = this.handler.getHandlerConfiguration().getConfiguration(name); + } + + return conf; + } } 1.2 +8 -8 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/transformation/SessionPostTransformer.java Index: SessionPostTransformer.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/transformation/SessionPostTransformer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SessionPostTransformer.java 9 Mar 2003 00:06:11 -0000 1.1 +++ SessionPostTransformer.java 4 May 2003 20:19:39 -0000 1.2 @@ -167,7 +167,7 @@ ", name=" + name + ", raw=" + raw + ", attr=" + attr); } if (name.equals(DELETECONTEXT_ELEMENT) == true) { - this.getSessionManager().deleteContext(attr.getValue(DELETECONTEXT_NAME_ATTRIBUTE)); + this.getContextManager().deleteContext(attr.getValue(DELETECONTEXT_NAME_ATTRIBUTE)); } else if (name.equals(SETXML_ELEMENT) == true) { this.startRecording(); @@ -314,11 +314,11 @@ pars.setSingleParameterValue("contextname", contextName); pars.setSingleParameterValue("path", path); - this.getSessionManager().getContext(contextName).saveXML(path, - pars, - this.objectModel, - this.resolver, - this.manager); + this.getContextManager().getContext(contextName).saveXML(path, + pars, + this.objectModel, + this.resolver, + this.manager); // Element: inputxml } else if (name.equals(INPUTXML_ELEMENT) == true) { @@ -330,7 +330,7 @@ if (this.formName == null) { throw new ProcessingException("The inputxml must be contained inside a form."); } - DocumentFragment value = this.getSessionManager().registerInputField(contextname, path, fieldname, formName); + DocumentFragment value = this.getFormManager().registerInputField(contextname, path, fieldname, formName); if (value == null) value = defaultFragment; this.sendEvents(value); super.endTransformingElement("", name, name); 1.2 +43 -4 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/transformation/AbstractSessionTransformer.java Index: AbstractSessionTransformer.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/transformation/AbstractSessionTransformer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AbstractSessionTransformer.java 9 Mar 2003 00:06:11 -0000 1.1 +++ AbstractSessionTransformer.java 4 May 2003 20:19:39 -0000 1.2 @@ -50,11 +50,14 @@ */ package org.apache.cocoon.webapps.session.transformation; +import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.component.ComponentException; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.environment.Session; import org.apache.cocoon.transformation.AbstractSAXTransformer; -import org.apache.cocoon.webapps.session.components.SessionManager; +import org.apache.cocoon.webapps.session.ContextManager; +import org.apache.cocoon.webapps.session.FormManager; +import org.apache.cocoon.webapps.session.SessionManager; /** * This class is the basis for all session transformers. @@ -66,7 +69,9 @@ extends AbstractSAXTransformer { private SessionManager sessionManager; - + private FormManager formManager; + private ContextManager contextManager; + /** * Get the SessionManager component */ @@ -83,12 +88,46 @@ } /** + * Get the ContextManager component + */ + protected ContextManager getContextManager() + throws ProcessingException { + if (this.contextManager == null) { + try { + this.contextManager = (ContextManager)this.manager.lookup(ContextManager.ROLE); + } catch (ComponentException ce) { + throw new ProcessingException("Error during lookup of ContextManager component.", ce); + } + } + return this.contextManager; + } + + /** + * Get the FormManager component + */ + protected FormManager getFormManager() + throws ProcessingException { + if (this.formManager == null) { + try { + this.formManager = (FormManager)this.manager.lookup(FormManager.ROLE); + } catch (ComponentException ce) { + throw new ProcessingException("Error during lookup of FormManager component.", ce); + } + } + return this.formManager; + } + + /** * Recycle this component. */ public void recycle() { super.recycle(); - this.manager.release(this.sessionManager); + this.manager.release( (Component)this.sessionManager); + this.manager.release( (Component)this.formManager); + this.manager.release( (Component)this.contextManager); this.sessionManager = null; + this.formManager = null; + this.contextManager = null; } /** 1.2 +3 -3 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/transformation/SessionPreTransformer.java Index: SessionPreTransformer.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/transformation/SessionPreTransformer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SessionPreTransformer.java 9 Mar 2003 00:06:11 -0000 1.1 +++ SessionPreTransformer.java 4 May 2003 20:19:39 -0000 1.2 @@ -176,7 +176,7 @@ ", attr=" + attr); } if (name.equals(CREATECONTEXT_ELEMENT) == true) { - this.getSessionManager().createContext(attr.getValue(CREATECONTEXT_NAME_ATTRIBUTE), + this.getContextManager().createContext(attr.getValue(CREATECONTEXT_NAME_ATTRIBUTE), attr.getValue(CREATECONTEXT_LOAD_ATTRIBUTE), attr.getValue(CREATECONTEXT_SAVE_ATTRIBUTE)); @@ -237,7 +237,7 @@ pars.setSingleParameterValue("contextname", contextName); pars.setSingleParameterValue("path", path); - this.getSessionManager().getContext(contextName).loadXML(path, + this.getContextManager().getContext(contextName).loadXML(path, pars, this.objectModel, this.resolver, 1.4 +118 -81 cocoon-2.1/src/blocks/portal-fw/java/org/apache/cocoon/webapps/portal/components/PortalManager.java Index: PortalManager.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/portal-fw/java/org/apache/cocoon/webapps/portal/components/PortalManager.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- PortalManager.java 27 Apr 2003 15:04:48 -0000 1.3 +++ PortalManager.java 4 May 2003 20:19:39 -0000 1.4 @@ -58,8 +58,9 @@ import java.util.List; import java.util.Map; -import org.apache.avalon.framework.CascadingRuntimeException; +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.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.cocoon.ProcessingException; @@ -68,11 +69,13 @@ import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.environment.Session; import org.apache.cocoon.environment.SourceResolver; -import org.apache.cocoon.webapps.authentication.components.AuthenticationManager; +import org.apache.cocoon.webapps.authentication.AuthenticationManager; +import org.apache.cocoon.webapps.authentication.user.RequestState; import org.apache.cocoon.webapps.portal.PortalConstants; import org.apache.cocoon.webapps.portal.context.SessionContextProviderImpl; +import org.apache.cocoon.webapps.session.ContextManager; +import org.apache.cocoon.webapps.session.MediaManager; import org.apache.cocoon.webapps.session.components.AbstractSessionComponent; -import org.apache.cocoon.webapps.session.components.SessionManager; import org.apache.cocoon.webapps.session.context.SessionContext; import org.apache.cocoon.webapps.session.context.SessionContextProvider; import org.apache.cocoon.webapps.session.xml.XMLUtil; @@ -84,16 +87,10 @@ import org.apache.excalibur.source.SourceException; import org.apache.excalibur.source.SourceParameters; import org.apache.excalibur.store.Store; +import org.w3c.dom.*; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; -import org.w3c.dom.Node; -import org.w3c.dom.DocumentFragment; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; -import org.w3c.dom.Document; -import org.w3c.dom.Text; -import org.w3c.dom.NamedNodeMap; /** @@ -167,33 +164,41 @@ /** The authenticationManager */ private AuthenticationManager authenticationManager; - /** Init the class, - * add the provider for the portal context - */ - static { - // add the provider for the portal context - SessionContextProvider provider = new SessionContextProviderImpl(); - try { - SessionManager.addSessionContextProvider(provider, PortalConstants.SESSION_CONTEXT_NAME); - } catch (ProcessingException local) { - throw new CascadingRuntimeException("Unable to register provider for portal context.", local); - } - } - + /** The media manager */ + private MediaManager mediaManager; + /** * Avalon Recyclable Interface */ public void recycle() { if (this.manager != null) { this.manager.release(this.profileStore); - this.manager.release(this.authenticationManager); + this.manager.release( (Component)this.authenticationManager); + this.manager.release( (Component)this.mediaManager); this.profileStore = null; this.authenticationManager = null; + this.mediaManager = null; } super.recycle(); } /** + * Composable + */ + public void compose(ComponentManager manager) + throws ComponentException { + super.compose( manager ); + ContextManager contextManager = (ContextManager)manager.lookup(ContextManager.ROLE); + // add the provider for the portal context + SessionContextProvider provider = new SessionContextProviderImpl(); + try { + contextManager.addSessionContextProvider(provider, PortalConstants.SESSION_CONTEXT_NAME); + } catch (ProcessingException pe) { + // ignore this! + } + } + + /** * Get the profile store */ public Store getProfileStore() @@ -209,7 +214,7 @@ } /** - * Get the profile store + * Get the authentication manager */ public AuthenticationManager getAuthenticationManager() throws ProcessingException { @@ -224,6 +229,21 @@ } /** + * Get the media manager + */ + public MediaManager getMediaManager() + throws ProcessingException { + if (this.mediaManager == null) { + try { + this.mediaManager = (MediaManager)this.manager.lookup(MediaManager.ROLE); + } catch (ComponentException ce) { + throw new ProcessingException("Error during lookup of MediaManager.", ce); + } + } + return this.mediaManager; + } + + /** * Set the <code>SourceResolver</code>, objectModel <code>Map</code>, * used to process the request. * This method is automatically called for each request. Do not invoke @@ -273,16 +293,17 @@ final Session session = this.getSessionManager().getSession(false); if (session != null) { synchronized(session) { - String appName = this.getAuthenticationManager().getApplicationName(); + String appName = RequestState.getState().getApplicationName(); String attrName = PortalConstants.PRIVATE_SESSION_CONTEXT_NAME; if (appName != null) { attrName = attrName + ':' + appName; } - context = this.getSessionManager().getContext(attrName); + context = this.getContextManager().getContext(attrName); if (context == null && create == true) { // create new context - context = this.getAuthenticationManager().createHandlerContext(attrName, null, null); + + context = RequestState.getState().getHandler().createApplicationContext(attrName, null, null); } } // end synchronized @@ -364,7 +385,7 @@ String command = this.request.getParameter(PortalManager.REQ_PARAMETER_ADMIN_COPLETS); if (command != null && copletsFragment != null) { try { - this.getSessionManager().startWritingTransaction(context); + this.getTransactionManager().startWritingTransaction(context); // save : save coplets base // new : new coplet // delete : use id to delete coplet @@ -507,8 +528,9 @@ SourceParameters pars = new SourceParameters(); pars.setSingleParameterValue("profile", "coplet-base"); - pars.setSingleParameterValue("application", this.getAuthenticationManager().getApplicationName()); - pars.setSingleParameterValue("handler", this.getAuthenticationManager().getHandlerName()); + RequestState state = RequestState.getState(); + pars.setSingleParameterValue("application", state.getApplicationName()); + pars.setSingleParameterValue("handler", state.getHandlerName()); String saveResource = (String)configuration.get(PortalConstants.CONF_COPLETBASE_SAVE_RESOURCE); @@ -528,7 +550,7 @@ } } } finally { - this.getSessionManager().stopWritingTransaction(context); + this.getTransactionManager().stopWritingTransaction(context); } } @@ -658,7 +680,8 @@ // load the base coplets profile if (copletsFragment == null) { SourceParameters pars = new SourceParameters(); - pars.setSingleParameterValue("application", this.getAuthenticationManager().getApplicationName()); + RequestState reqstate = RequestState.getState(); + pars.setSingleParameterValue("application", reqstate.getApplicationName()); String res = (String)configuration.get(PortalConstants.CONF_COPLETBASE_RESOURCE); if (res == null) { throw new ProcessingException("No configuration for portal-coplet base profile found."); @@ -731,15 +754,16 @@ boolean adminProfile) throws SAXException, ProcessingException, IOException { // synchronized - if (this.getLogger().isDebugEnabled() == true) { + if (this.getLogger().isDebugEnabled()) { this.getLogger().debug("BEGIN showPortal consumer=" + consumer+", configMode="+ configMode+", adminProfile="+adminProfile); } + SessionContext context = this.getContext(true); String profileID = null; Map storedProfile = null; - if (this.getLogger().isDebugEnabled() == true) { + if (this.getLogger().isDebugEnabled()) { this.getLogger().debug("start portal generation"); } if (context.getAttribute(PortalManager.ATTRIBUTE_PORTAL_ROLE) != null) { @@ -750,7 +774,7 @@ } if (storedProfile == null) { - if (this.getLogger().isDebugEnabled() == true) { + if (this.getLogger().isDebugEnabled()) { this.getLogger().debug("start building profile"); } this.createProfile(context, PortalManager.BUILDTYPE_VALUE_ID, null, null, adminProfile); @@ -762,7 +786,7 @@ if (storedProfile == null) { throw new ProcessingException("portal: No portal profile found."); } - if (this.getLogger().isDebugEnabled() == true) { + if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("end building profile"); } } @@ -850,7 +874,7 @@ ", profile="+storedProfile); } try { - this.getSessionManager().startReadingTransaction(context); + this.getTransactionManager().startReadingTransaction(context); DocumentFragment profile; Map defaultCoplets; @@ -858,7 +882,7 @@ Map portalLayouts; Map copleyLayouts; Node[] miscNodes; - String mediaType = this.getAuthenticationManager().getMediaType(); + String mediaType = this.getMediaManager().getMediaType(); profile = (DocumentFragment)storedProfile.get(PortalConstants.PROFILE_PROFILE); portalLayouts = (Map)storedProfile.get(PortalConstants.PROFILE_PORTAL_LAYOUTS); @@ -1111,7 +1135,7 @@ } catch (javax.xml.transform.TransformerException local) { // end synchronized throw new ProcessingException("TransformerException: " + local, local); } finally { - this.getSessionManager().stopReadingTransaction(context); + this.getTransactionManager().stopReadingTransaction(context); } if (this.getLogger().isDebugEnabled() == true) { this.getLogger().debug("END showPortal"); @@ -1157,7 +1181,7 @@ SessionContext context = this.getContext(true); try { - this.getSessionManager().startWritingTransaction(context); + this.getTransactionManager().startWritingTransaction(context); String profileID = this.getProfileID(type, role, id, adminProfile); Map theProfile = null; @@ -1294,7 +1318,7 @@ context.setAttribute(PortalManager.ATTRIBUTE_PORTAL_ID, id); } } finally { - this.getSessionManager().stopWritingTransaction(context); + this.getTransactionManager().stopWritingTransaction(context); }// end synchronized } catch (javax.xml.transform.TransformerException local) { throw new ProcessingException("TransformerException: " + local, local); @@ -1565,9 +1589,10 @@ throws ProcessingException { // No sync required StringBuffer key = new StringBuffer((adminProfile == true ? "aprofile:" : "uprofile:")); - key.append(this.getAuthenticationManager().getHandlerName()) + RequestState reqstate = RequestState.getState(); + key.append(reqstate.getHandlerName()) .append('|') - .append(this.getAuthenticationManager().getApplicationName()) + .append(reqstate.getApplicationName()) .append(':') .append(type); @@ -1853,7 +1878,7 @@ profileMap.put(PortalConstants.PROFILE_MEDIA_COPLETS, mediaCoplets); // get AuthenticationManager instance - String[] types = this.getAuthenticationManager().getMediaTypes(); + String[] types = this.getMediaManager().getMediaTypes(); Map mediaMap; for(int i = 0; i < types.length; i++) { mediaCoplets.put(types[i], new HashMap(5, 3)); @@ -2342,7 +2367,7 @@ Element defLayout = (Element)DOMUtil.getSingleNode(baseProfile, "profile/layout-profile/portal/layouts/layout[not(@*)]"); Node currentLayout; - String[] types = this.getAuthenticationManager().getMediaTypes(); + String[] types = this.getMediaManager().getMediaTypes(); for(int i = 0; i < types.length; i++) { currentLayout = DOMUtil.getSingleNode(baseProfile, @@ -2370,7 +2395,7 @@ Element defLayout = (Element)DOMUtil.getSingleNode(baseProfile, "profile/layout-profile/coplets/layouts/layout[not(@*)]"); Node currentLayout; - String[] types = this.getAuthenticationManager().getMediaTypes(); + String[] types = this.getMediaManager().getMediaTypes(); for(int i = 0; i < types.length; i++) { currentLayout = DOMUtil.getSingleNode(baseProfile, @@ -2672,7 +2697,7 @@ boolean visible = DOMUtil.getValueAsBooleanOf(element, "status/visible"); // second: check media - String media = this.getAuthenticationManager().getMediaType(); + String media = this.getMediaManager().getMediaType(); if (visible == true && copletConf.hasAttributeNS(null, "media") == true) { String copletMedia = copletConf.getAttributeNS(null, "media"); visible = media.equals(copletMedia); @@ -2692,7 +2717,7 @@ "customization/[EMAIL PROTECTED]'"+copletID+"' and @number='"+element.getAttributeNS(null, "number")+"']"); hasConfig = (customInfo != null); } - if (showCustomizePage == true || hasConfig == false) { + if (showCustomizePage || !hasConfig ) { Node node = DOMUtil.selectSingleNode(element, "status/customize"); DOMUtil.setValueOfNode(node, "true"); } else { @@ -2874,7 +2899,7 @@ */ public String getMediaType() throws ProcessingException { - return this.getAuthenticationManager().getMediaType(); + return this.getMediaManager().getMediaType(); } /** @@ -2885,7 +2910,7 @@ Map mediaCoplets) throws ProcessingException { // calling method is synced - String media = this.getAuthenticationManager().getMediaType(); + String media = this.getMediaManager().getMediaType(); Map coplets = (Map)mediaCoplets.get(media); Element coplet = null; if (coplets != null) coplet = (Element)coplets.get(copletID); @@ -3191,7 +3216,7 @@ && (String)context.getAttribute(PortalManager.ATTRIBUTE_PORTAL_ROLE) != null) { try { - this.getSessionManager().startReadingTransaction(context); + this.getTransactionManager().startReadingTransaction(context); Map theProfile = this.retrieveProfile(this.getProfileID(PortalManager.BUILDTYPE_VALUE_ID, (String)context.getAttribute(PortalManager.ATTRIBUTE_PORTAL_ROLE), (String)context.getAttribute(PortalManager.ATTRIBUTE_PORTAL_ID), false)); @@ -3207,7 +3232,7 @@ } } } finally { - this.getSessionManager().stopReadingTransaction(context); + this.getTransactionManager().stopReadingTransaction(context); } // end synced } @@ -3244,8 +3269,9 @@ this.getLogger().debug("BEGIN getConfiguration"); } Map result = null; - String appName = this.getAuthenticationManager().getApplicationName(); - String handlerName = this.getAuthenticationManager().getHandlerName(); + RequestState reqstate = RequestState.getState(); + String appName = reqstate.getApplicationName(); + String handlerName = reqstate.getHandlerName(); Session session = this.getSessionManager().getSession(false); if (session != null && appName != null && handlerName != null) { @@ -3256,7 +3282,7 @@ try { Configuration config; - Configuration conf = this.getAuthenticationManager().getModuleConfiguration(PortalConstants.AUTHENTICATION_MODULE_NAME); + Configuration conf = reqstate.getModuleConfiguration(PortalConstants.AUTHENTICATION_MODULE_NAME); if (conf == null) { throw new ProcessingException("portal: Configuration for application '" + appName + "' not found."); } @@ -3414,19 +3440,19 @@ boolean adminProfile) throws SAXException, IOException, ProcessingException { // no sync required - if (this.getLogger().isDebugEnabled() == true) { + if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("BEGIN createProfile context="+context+ ", type="+type+ ", role="+role+ ", id="+id); } - SourceParameters pars = this.getAuthenticationManager().createParameters(null); + RequestState reqstate = RequestState.getState(); + SourceParameters pars = reqstate.getHandler().getContext().getContextInfoAsParameters(); pars.setSingleParameterValue("type", type); pars.setSingleParameterValue("admin", (adminProfile == true ? "true" : "false")); - if (type.equals(PortalManager.BUILDTYPE_VALUE_ID) == false || - role != null) { + if (!type.equals(PortalManager.BUILDTYPE_VALUE_ID) || role != null) { pars.setSingleParameterValue("ID", id); pars.setSingleParameterValue("role", role); } else { @@ -3479,8 +3505,9 @@ String res; SourceParameters pars = new SourceParameters(); - pars.setSingleParameterValue("application", this.getAuthenticationManager().getApplicationName()); - pars.setSingleParameterValue("handler", this.getAuthenticationManager().getHandlerName()); + RequestState reqstate = RequestState.getState(); + pars.setSingleParameterValue("application", reqstate.getApplicationName()); + pars.setSingleParameterValue("handler", reqstate.getHandlerName()); pars.setSingleParameterValue("profile", "coplet-base"); // First load the base profiles: copletProfile + layoutProfile @@ -3572,8 +3599,9 @@ throw new ProcessingException("No configuration for portal-role delta profile found."); } SourceParameters pars = new SourceParameters(); - pars.setSingleParameterValue("application", this.getAuthenticationManager().getApplicationName()); - pars.setSingleParameterValue("handler", this.getAuthenticationManager().getHandlerName()); + RequestState reqstate = RequestState.getState(); + pars.setSingleParameterValue("application", reqstate.getApplicationName()); + pars.setSingleParameterValue("handler", reqstate.getHandlerName()); pars.setSingleParameterValue("profile", "global-delta"); if (this.getLogger().isDebugEnabled() == true) { @@ -3623,11 +3651,12 @@ // calling method is synced DocumentFragment roleFragment; + RequestState reqstate = RequestState.getState(); SourceParameters pars; pars = new SourceParameters(); pars.setSingleParameterValue("role", role); - pars.setSingleParameterValue("application", this.getAuthenticationManager().getApplicationName()); - pars.setSingleParameterValue("handler", this.getAuthenticationManager().getHandlerName()); + pars.setSingleParameterValue("application", reqstate.getApplicationName()); + pars.setSingleParameterValue("handler", reqstate.getHandlerName()); pars.setSingleParameterValue("profile", "role-delta"); String res = (String)config.get(PortalConstants.CONF_ROLEDELTA_LOADRESOURCE); @@ -3677,12 +3706,13 @@ throws ProcessingException { // calling method is synced DocumentFragment userFragment; + RequestState reqstate = RequestState.getState(); SourceParameters pars; pars = new SourceParameters(); pars.setSingleParameterValue("ID", id); pars.setSingleParameterValue("role", role); - pars.setSingleParameterValue("application", this.getAuthenticationManager().getApplicationName()); - pars.setSingleParameterValue("handler", this.getAuthenticationManager().getHandlerName()); + pars.setSingleParameterValue("application", reqstate.getApplicationName()); + pars.setSingleParameterValue("handler", reqstate.getHandlerName()); pars.setSingleParameterValue("profile", "user-delta"); String res = (String)config.get(PortalConstants.CONF_USERDELTA_LOADRESOURCE); @@ -3742,11 +3772,12 @@ if (res != null) { DocumentFragment userFragment; SourceParameters pars; + RequestState reqstate = RequestState.getState(); pars = new SourceParameters(); pars.setSingleParameterValue("ID", id); pars.setSingleParameterValue("role", role); - pars.setSingleParameterValue("application", this.getAuthenticationManager().getApplicationName()); - pars.setSingleParameterValue("handler", this.getAuthenticationManager().getHandlerName()); + pars.setSingleParameterValue("application", reqstate.getApplicationName()); + pars.setSingleParameterValue("handler", reqstate.getHandlerName()); pars.setSingleParameterValue("profile", "user-status"); if (this.getLogger().isDebugEnabled() == true) { this.getLogger().debug("loading user status profile"); @@ -3805,12 +3836,13 @@ try { + RequestState reqstate = RequestState.getState(); SourceParameters pars; pars = new SourceParameters(); pars.setSingleParameterValue("ID", id); pars.setSingleParameterValue("role", role); - pars.setSingleParameterValue("application", this.getAuthenticationManager().getApplicationName()); - pars.setSingleParameterValue("handler", this.getAuthenticationManager().getHandlerName()); + pars.setSingleParameterValue("application", reqstate.getApplicationName()); + pars.setSingleParameterValue("handler", reqstate.getHandlerName()); pars.setSingleParameterValue("profile", "user-status"); SourceUtil.writeDOM(res, @@ -3991,14 +4023,15 @@ } // build delta + RequestState reqstate = RequestState.getState(); DocumentFragment delta; delta = this.buildProfileDelta(type, role, id, this.getIsAdminProfile(profileID)); SourceParameters pars = new SourceParameters(); pars.setSingleParameterValue("type", profileType); if (id != null) pars.setSingleParameterValue("ID", id); if (role != null) pars.setSingleParameterValue("role", role); - pars.setSingleParameterValue("application", this.getAuthenticationManager().getApplicationName()); - pars.setSingleParameterValue("handler", this.getAuthenticationManager().getHandlerName()); + pars.setSingleParameterValue("application", reqstate.getApplicationName()); + pars.setSingleParameterValue("handler", reqstate.getHandlerName()); SourceUtil.writeDOM(saveResource, null, pars, @@ -4183,8 +4216,9 @@ if (this.getLogger().isDebugEnabled() == true) { this.getLogger().debug("BEGIN getUsers role="+role+", ID="+ID); } + RequestState reqstate = RequestState.getState(); Document frag = null; - Configuration conf = this.getAuthenticationManager().getModuleConfiguration("single-role-user-management"); + Configuration conf = reqstate.getModuleConfiguration("single-role-user-management"); if (conf != null) { // get load-users resource (optional) @@ -4195,9 +4229,10 @@ if (loadUsersResource != null) { SourceParameters parameters = (loadUsersResourceParameters == null) ? new SourceParameters() + : loadUsersResourceParameters; - if (this.getAuthenticationManager().getApplicationName() != null) - parameters.setSingleParameterValue("application", this.getAuthenticationManager().getApplicationName()); + if (reqstate.getApplicationName() != null) + parameters.setSingleParameterValue("application", reqstate.getApplicationName()); if (ID != null) { parameters.setSingleParameterValue("type", "user"); parameters.setSingleParameterValue("ID", ID); @@ -4233,7 +4268,9 @@ } Document frag = null; - Configuration conf = this.getAuthenticationManager().getModuleConfiguration("single-role-user-management"); + RequestState reqstate = RequestState.getState(); + + Configuration conf = reqstate.getModuleConfiguration("single-role-user-management"); if (conf != null) { // get load-roles resource (optional) @@ -4244,8 +4281,8 @@ if (loadRolesResource != null) { SourceParameters parameters = (loadRolesResourceParameters == null) ? new SourceParameters() : loadRolesResourceParameters; - if (this.getAuthenticationManager().getApplicationName() != null) - parameters.setSingleParameterValue("application", this.getAuthenticationManager().getApplicationName()); + if (reqstate.getApplicationName() != null) + parameters.setSingleParameterValue("application", reqstate.getApplicationName()); parameters.setSingleParameterValue("type", "roles"); frag = this.loadResource(loadRolesResource, parameters); } 1.2 +10 -7 cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting/AuthAction.java Index: AuthAction.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting/AuthAction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AuthAction.java 9 Mar 2003 00:02:16 -0000 1.1 +++ AuthAction.java 4 May 2003 20:19:39 -0000 1.2 @@ -52,12 +52,14 @@ import java.util.Map; +import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.acting.ComposerAction; import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.environment.SourceResolver; -import org.apache.cocoon.webapps.authentication.components.AuthenticationManager; +import org.apache.cocoon.webapps.authentication.AuthenticationManager; +import org.apache.cocoon.webapps.authentication.user.RequestState; /** * This is the authentication action @@ -67,7 +69,7 @@ * The main task of this action is to check if the user is authenticated * using a handler. If not a redirect takes place. * - * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id$ */ public final class AuthAction @@ -80,7 +82,7 @@ String source, Parameters par) throws Exception { - if (this.getLogger().isDebugEnabled() == true) { + if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("BEGIN act resolver="+resolver+ ", objectModel="+objectModel+ ", source="+source+ @@ -102,12 +104,13 @@ // All events are ignored // the sitemap.xsl ensures that only the redirect is processed } else { - map = authManager.createMap(); + RequestState state = RequestState.getState(); + map = state.getHandler().getContext().getContextInfo(); } } finally { - this.manager.release( authManager ); + this.manager.release( (Component)authManager ); } - if (this.getLogger().isDebugEnabled() == true) { + if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("END act map="+map); } return map; 1.2 +13 -22 cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting/LoginAction.java Index: LoginAction.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting/LoginAction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- LoginAction.java 9 Mar 2003 00:02:17 -0000 1.1 +++ LoginAction.java 4 May 2003 20:19:39 -0000 1.2 @@ -52,17 +52,16 @@ import java.util.Map; +import org.apache.avalon.framework.component.Component; 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.authentication.components.AuthenticationManager; -import org.apache.cocoon.webapps.session.SessionConstants; -import org.apache.cocoon.webapps.session.components.SessionManager; +import org.apache.cocoon.webapps.authentication.AuthenticationManager; +import org.apache.cocoon.webapps.authentication.user.UserHandler; import org.apache.excalibur.source.SourceParameters; -import org.w3c.dom.DocumentFragment; /** * This action logs the current user into a given handler. If the @@ -71,7 +70,7 @@ * If the authentication is not successful, the error information is stored * into the temporary context. * - * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id$ */ public final class LoginAction @@ -84,7 +83,7 @@ String source, Parameters par) throws Exception { - if (this.getLogger().isDebugEnabled() == true) { + if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("BEGIN act resolver="+resolver+ ", objectModel="+objectModel+ ", source="+source+ @@ -116,27 +115,19 @@ AuthenticationManager authManager = null; try { authManager = (AuthenticationManager) this.manager.lookup(AuthenticationManager.ROLE); - Object o; - - o = authManager.authenticate( handlerName, - authenticationParameters); - if ( null == o) { + UserHandler handler = authManager.login( handlerName, + par.getParameter("application", null), + authenticationParameters); + if ( handler != null) { // success - map = authManager.createMap(); + map = handler.getContext().getContextInfo(); - } else { - SessionManager sessionManager = (SessionManager) this.manager.lookup(SessionManager.ROLE); - try { - sessionManager.getContext(SessionConstants.TEMPORARY_CONTEXT).appendXML("/", (DocumentFragment)o); - } finally { - this.manager.release(sessionManager); - } } } finally { - this.manager.release(authManager); + this.manager.release( (Component)authManager); } - if (this.getLogger().isDebugEnabled() == true) { + if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("END act map="+map); } 1.2 +11 -7 cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting/LogoutAction.java Index: LogoutAction.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting/LogoutAction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- LogoutAction.java 9 Mar 2003 00:02:17 -0000 1.1 +++ LogoutAction.java 4 May 2003 20:19:39 -0000 1.2 @@ -52,6 +52,7 @@ import java.util.Map; +import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.ProcessingException; @@ -59,12 +60,13 @@ import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.webapps.authentication.AuthenticationConstants; -import org.apache.cocoon.webapps.authentication.components.AuthenticationManager; +import org.apache.cocoon.webapps.authentication.AuthenticationManager; +import org.apache.cocoon.webapps.authentication.user.RequestState; /** * This action logs the current user out of a given handler * - * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id$ */ public final class LogoutAction @@ -77,7 +79,7 @@ String source, Parameters par) throws Exception { - if (this.getLogger().isDebugEnabled() == true) { + if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("BEGIN act resolver="+resolver+ ", objectModel="+objectModel+ ", source="+source+ @@ -99,17 +101,19 @@ // logout AuthenticationManager authManager = null; try { + RequestState state = RequestState.getState(); + authManager = (AuthenticationManager) this.manager.lookup(AuthenticationManager.ROLE); final String handlerName = par.getParameter("handler", - authManager.getHandlerName()); + (state == null ? null : state.getHandlerName())); if ( null == handlerName ) throw new ProcessingException("LogoutAction requires at least the handler parameter."); authManager.logout( handlerName , mode ); } finally { - this.manager.release( authManager ); + this.manager.release( (Component)authManager ); } - if (this.getLogger().isDebugEnabled() == true) { + if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("END act map={}"); } 1.2 +11 -8 cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting/LoggedInAction.java Index: LoggedInAction.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting/LoggedInAction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- LoggedInAction.java 9 Mar 2003 00:02:17 -0000 1.1 +++ LoggedInAction.java 4 May 2003 20:19:39 -0000 1.2 @@ -52,17 +52,19 @@ import java.util.Map; +import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.acting.ComposerAction; import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.environment.SourceResolver; -import org.apache.cocoon.webapps.authentication.components.AuthenticationManager; +import org.apache.cocoon.webapps.authentication.AuthenticationManager; +import org.apache.cocoon.webapps.authentication.user.UserHandler; /** * This action tests if the user is logged in for a given handler. * - * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id$ */ public final class LoggedInAction @@ -75,7 +77,7 @@ String source, Parameters par) throws Exception { - if (this.getLogger().isDebugEnabled() == true) { + if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("BEGIN act resolver="+resolver+ ", objectModel="+objectModel+ ", source="+source+ @@ -88,14 +90,15 @@ try { authManager = (AuthenticationManager) this.manager.lookup(AuthenticationManager.ROLE); - if (authManager.isAuthenticated(handlerName) == true) { - map = authManager.createMap(); + UserHandler handler = authManager.isAuthenticated(handlerName); + if ( handler != null ) { + map = handler.getContext().getContextInfo(); } } finally { - this.manager.release(authManager); + this.manager.release( (Component)authManager); } - if (this.getLogger().isDebugEnabled() == true) { + if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("END act map="+map); } 1.2 +19 -8 cocoon-2.1/src/blocks/session-fw/conf/session.xconf Index: session.xconf =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/session-fw/conf/session.xconf,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- session.xconf 9 Mar 2003 00:06:06 -0000 1.1 +++ session.xconf 4 May 2003 20:19:40 -0000 1.2 @@ -1,8 +1,19 @@ -<?xml version="1.0"?> - -<xconf xpath="/cocoon" unless="session-manager"> - - <session-manager logger="core.session-manager" - pool-max="32" pool-min="8" pool-grow="4"/> - -</xconf> +<?xml version="1.0"?> + +<xconf xpath="/cocoon" unless="session-manager"> + + <session-manager logger="core.session-manager"/> + <session-form-manager logger="core.session-manager"/> + <session-transaction-manager logger="core.session-manager"/> + <session-context-manager logger="core.session-manager"/> + + <session-media-manager logger="core.media-manager" + pool-max="32" pool-min="8" pool-grow="4"> + <mediatypes default="html"> + <media name="wap" useragent="Nokia"/> + <media name="wap" useragent="UP"/> + <media name="wap" useragent="Wapalizer"/> + </mediatypes> + </session-media-manager> + +</xconf> 1.2 +25 -9 cocoon-2.1/src/blocks/session-fw/conf/session.xroles Index: session.xroles =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/session-fw/conf/session.xroles,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- session.xroles 9 Mar 2003 00:06:06 -0000 1.1 +++ session.xroles 4 May 2003 20:19:40 -0000 1.2 @@ -1,9 +1,25 @@ -<?xml version="1.0"?> - -<xroles xpath="/role-list" unless="role [EMAIL PROTECTED]'org.apache.cocoon.webapps.session.components.SessionManager']"> - - <role name="org.apache.cocoon.webapps.session.components.SessionManager" - shorthand="session-manager" - default-class="org.apache.cocoon.webapps.session.components.SessionManager"/> - -</xroles> +<?xml version="1.0"?> + +<xroles xpath="/role-list" unless="role [EMAIL PROTECTED]'org.apache.cocoon.webapps.session.SessionManager']"> + + <role name="org.apache.cocoon.webapps.session.ContextManager" + shorthand="session-context-manager" + default-class="org.apache.cocoon.webapps.session.components.DefaultContextManager"/> + + <role name="org.apache.cocoon.webapps.session.FormManager" + shorthand="session-form-manager" + default-class="org.apache.cocoon.webapps.session.components.DefaultFormManager"/> + + <role name="org.apache.cocoon.webapps.session.MediaManager" + shorthand="session-media-manager" + default-class="org.apache.cocoon.webapps.session.components.DefaultMediaManager"/> + + <role name="org.apache.cocoon.webapps.session.SessionManager" + shorthand="session-manager" + default-class="org.apache.cocoon.webapps.session.components.DefaultSessionManager"/> + + <role name="org.apache.cocoon.webapps.session.TransactionManager" + shorthand="session-transaction-manager" + default-class="org.apache.cocoon.webapps.session.components.DefaultTransactionManager"/> + +</xroles> 1.1 cocoon-2.1/src/blocks/session-fw/conf/session-sel.xmap Index: session-sel.xmap =================================================================== <?xml version="1.0"?> <xmap xpath="/sitemap/components/selectors" unless="[EMAIL PROTECTED]'auth-media']"> <map:selector name="session-media" src="org.apache.cocoon.webapps.session.selection.MediaSelector"/> </xmap> 1.2 +7 -1 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/context/ResponseSessionContext.java Index: ResponseSessionContext.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/context/ResponseSessionContext.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ResponseSessionContext.java 9 Mar 2003 00:06:10 -0000 1.1 +++ ResponseSessionContext.java 4 May 2003 20:19:40 -0000 1.2 @@ -113,6 +113,12 @@ public String getName() { return this.name; } + /** + * Get the request object + */ + public Response getResponse() { + return this.response; + } /** * Build the cookie 1.2 +8 -1 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/context/RequestSessionContext.java Index: RequestSessionContext.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/context/RequestSessionContext.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- RequestSessionContext.java 9 Mar 2003 00:06:09 -0000 1.1 +++ RequestSessionContext.java 4 May 2003 20:19:40 -0000 1.2 @@ -208,6 +208,13 @@ } /** + * Get the request object + */ + public Request getRequest() { + return this.request; + } + + /** * Build path */ private String createPath(String path) { 1.5 +12 -6 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/context/SimpleSessionContext.java Index: SimpleSessionContext.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/context/SimpleSessionContext.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- SimpleSessionContext.java 1 May 2003 09:37:30 -0000 1.4 +++ SimpleSessionContext.java 4 May 2003 20:19:40 -0000 1.5 @@ -270,9 +270,9 @@ */ private String createPath(String path) { if (path == null) path ="/"; - if (path.startsWith("/") == false) path = "/" + path; + if (!path.startsWith("/") ) path = "/" + path; path = "context" + path; - if (path.endsWith("/") == true) path = path.substring(0, path.length() - 1); + if (path.endsWith("/")) path = path.substring(0, path.length() - 1); return path; } @@ -357,9 +357,15 @@ */ public synchronized void setNode(String path, Node node) throws ProcessingException { - path = this.createPath(path); - Node removeNode = DOMUtil.selectSingleNode(data, path); - removeNode.getParentNode().replaceChild(data.importNode(node, true), removeNode); + if ( path == null || path.equals("/")) { + data = DOMUtil.createDocument(); + data.appendChild(data.createElementNS(null, "context")); + data.getFirstChild().appendChild(data.importNode(node, true)); + } else { + path = this.createPath(path); + Node removeNode = DOMUtil.selectSingleNode(data, path); + removeNode.getParentNode().replaceChild(data.importNode(node, true), removeNode); + } } 1.2 +51 -21 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/context/StandardSessionContextProvider.java Index: StandardSessionContextProvider.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/context/StandardSessionContextProvider.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- StandardSessionContextProvider.java 9 Mar 2003 00:06:10 -0000 1.1 +++ StandardSessionContextProvider.java 4 May 2003 20:19:40 -0000 1.2 @@ -54,7 +54,8 @@ import org.apache.avalon.framework.component.ComponentManager; import org.apache.cocoon.ProcessingException; -import org.apache.excalibur.source.SourceResolver; +import org.apache.cocoon.components.CocoonComponentManager; +import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.webapps.session.SessionConstants; /** @@ -70,31 +71,60 @@ /** * Get the context * @param name The name of the context - * @param objectModel The objectModel of the current request. - * @param resolver The source resolver - * @param componentManager manager * @return The context * @throws ProcessingException If the context is not available. */ - public SessionContext getSessionContext(String name, - Map objectModel, - SourceResolver resolver, - ComponentManager manager) + public SessionContext getSessionContext(String name) throws ProcessingException { - SessionContext context = null; - if ( name.equals(SessionConstants.TEMPORARY_CONTEXT) ) { - context = new SimpleSessionContext(); - context.setup(name, null, null); - } else if ( name.equals(SessionConstants.REQUEST_CONTEXT) ) { - context = new RequestSessionContext(); - context.setup(name, null, null); - ((RequestSessionContext)context).setup( objectModel, manager ); - } else if ( name.equals(SessionConstants.RESPONSE_CONTEXT) ) { - context = new ResponseSessionContext(); - context.setup(name, null, null); - ((ResponseSessionContext)context).setup( objectModel ); + final ComponentManager manager = CocoonComponentManager.getSitemapComponentManager(); + final Map objectModel = CocoonComponentManager.getCurrentEnvironment().getObjectModel(); + + // get the context from the object model + SessionContext context = this.getContext( objectModel, name ); + if ( context == null ) { + if ( name.equals(SessionConstants.TEMPORARY_CONTEXT) ) { + context = new SimpleSessionContext(); + context.setup(name, null, null); + } else if ( name.equals(SessionConstants.REQUEST_CONTEXT) ) { + context = new RequestSessionContext(); + context.setup(name, null, null); + ((RequestSessionContext)context).setup( objectModel, manager ); + } else if ( name.equals(SessionConstants.RESPONSE_CONTEXT) ) { + context = new ResponseSessionContext(); + context.setup(name, null, null); + ((ResponseSessionContext)context).setup( objectModel ); + } + objectModel.put(this.getClass().getName()+name, context); } return context; } + /** + * Does the context exist? + */ + public boolean existsSessionContext(String name) + throws ProcessingException { + final Map objectModel = CocoonComponentManager.getCurrentEnvironment().getObjectModel(); + return (this.getContext( objectModel, name) != null); + } + + private SessionContext getContext(Map objectModel, String name) { + SessionContext context = (SessionContext) objectModel.get(this.getClass().getName()+name); + if ( context != null && !name.equals(SessionConstants.TEMPORARY_CONTEXT)) { + if ( name.equals(SessionConstants.REQUEST_CONTEXT)) { + RequestSessionContext r = (RequestSessionContext)context; + if (!(r.getRequest() == ObjectModelHelper.getRequest( objectModel))) { + context = null; + objectModel.remove(this.getClass().getName()+name); + } + } else { + ResponseSessionContext r = (ResponseSessionContext)context; + if (!(r.getResponse() == ObjectModelHelper.getResponse( objectModel))) { + context = null; + objectModel.remove(this.getClass().getName()+name); + } + } + } + return context; + } } 1.2 +13 -16 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/context/SessionContextProvider.java Index: SessionContextProvider.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/context/SessionContextProvider.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SessionContextProvider.java 9 Mar 2003 00:06:10 -0000 1.1 +++ SessionContextProvider.java 4 May 2003 20:19:40 -0000 1.2 @@ -50,17 +50,14 @@ */ package org.apache.cocoon.webapps.session.context; -import java.util.Map; - -import org.apache.avalon.framework.component.ComponentManager; import org.apache.cocoon.ProcessingException; -import org.apache.excalibur.source.SourceResolver; /** - * Interface for a context provider. - * Objects of this class provide special context, e.g. authentication or portal. - * The context is (if used) got once by the <code>SessionManager</code> component - * for each request. + * Interface for a context provider. + * Objects of this class provide special context, e.g. authentication or portal. + * The provider has to take care that the context is instantiated and managed + * correctly: for example a request context object should only created once + * per request, an authentication context once per session etc. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id$ @@ -70,16 +67,16 @@ /** * Get the context * @param name The name of the context - * @param objectModel The objectModel of the current request. - * @param resolver The source resolver - * @param componentManager manager * @return The context * @throws ProcessingException If the context is not available. */ - SessionContext getSessionContext(String name, - Map objectModel, - SourceResolver resolver, - ComponentManager manager) + SessionContext getSessionContext(String name) + throws ProcessingException; + + /** + * Does the context exist? + */ + boolean existsSessionContext(String name) throws ProcessingException; } 1.5 +7 -6 cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/Authenticator.java Index: Authenticator.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/Authenticator.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Authenticator.java 1 May 2003 09:49:14 -0000 1.4 +++ Authenticator.java 4 May 2003 20:19:40 -0000 1.5 @@ -54,19 +54,20 @@ import java.util.Iterator; import org.apache.avalon.framework.activity.Disposable; +import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.service.Serviceable; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.ProcessingException; -import org.apache.cocoon.webapps.authentication.MediaManager; import org.apache.cocoon.webapps.authentication.configuration.ApplicationConfiguration; import org.apache.cocoon.webapps.authentication.configuration.HandlerConfiguration; import org.apache.cocoon.webapps.authentication.context.AuthenticationContext; import org.apache.cocoon.webapps.authentication.user.UserHandler; +import org.apache.cocoon.webapps.session.ContextManager; +import org.apache.cocoon.webapps.session.MediaManager; import org.apache.cocoon.webapps.session.SessionConstants; -import org.apache.cocoon.webapps.session.components.SessionManager; import org.apache.cocoon.webapps.session.context.SessionContext; import org.apache.cocoon.xml.XMLUtils; import org.apache.cocoon.xml.dom.DOMUtil; @@ -304,15 +305,15 @@ } // now set this information in the temporary context - SessionManager sessionManager = null; + ContextManager sessionManager = null; try { - sessionManager = (SessionManager) this.manager.lookup( SessionManager.ROLE ); + sessionManager = (ContextManager) this.manager.lookup( ContextManager.ROLE ); SessionContext temp = sessionManager.getContext( SessionConstants.TEMPORARY_CONTEXT ); temp.appendXML("/", authenticationFragment); } catch ( ServiceException se ) { throw new ProcessingException("Unable to lookup session manager.", se); } finally { - this.manager.release( sessionManager ); + this.manager.release( (Component)sessionManager ); } } 1.8 +17 -19 cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/DefaultAuthenticationManager.java Index: DefaultAuthenticationManager.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/DefaultAuthenticationManager.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- DefaultAuthenticationManager.java 1 May 2003 09:49:14 -0000 1.7 +++ DefaultAuthenticationManager.java 4 May 2003 20:19:40 -0000 1.8 @@ -70,12 +70,14 @@ import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.Session; import org.apache.cocoon.webapps.authentication.AuthenticationConstants; +import org.apache.cocoon.webapps.authentication.AuthenticationManager; import org.apache.cocoon.webapps.authentication.configuration.HandlerConfiguration; import org.apache.cocoon.webapps.authentication.context.AuthenticationContextProvider; import org.apache.cocoon.webapps.authentication.user.RequestState; import org.apache.cocoon.webapps.authentication.user.UserHandler; import org.apache.cocoon.webapps.authentication.user.UserState; -import org.apache.cocoon.webapps.session.components.SessionManager; +import org.apache.cocoon.webapps.session.ContextManager; +import org.apache.cocoon.webapps.session.SessionManager; import org.apache.excalibur.source.SourceParameters; import org.apache.excalibur.source.SourceResolver; import org.apache.excalibur.source.SourceUtil; @@ -88,7 +90,7 @@ */ public final class DefaultAuthenticationManager extends AbstractLogEnabled -implements Manager, SitemapConfigurable, Serviceable, Disposable, ThreadSafe, Component { +implements AuthenticationManager, SitemapConfigurable, Serviceable, Disposable, ThreadSafe, Component { /** The name of the session attribute storing the user status */ public final static String SESSION_ATTRIBUTE_USER_STATUS = DefaultAuthenticationManager.class.getName() + "/UserStatus"; @@ -105,21 +107,6 @@ /** The Source Resolver */ private SourceResolver resolver; - /** Init the class, - * add the provider for the authentication context - */ - static { - // add the provider for the authentication context - AuthenticationContextProvider contextProvider = new AuthenticationContextProvider(); - // FIXME - TODO - /* try { - // FIXME - this is static!!! - SessionManager.addSessionContextProvider(contextProvider, AuthenticationConstants.SESSION_CONTEXT_NAME); - } catch (ProcessingException local) { - throw new CascadingRuntimeException("Unable to register provider for authentication context.", local); - }*/ - } - /** * Set the sitemap configuration containing the handlers */ @@ -241,7 +228,6 @@ RequestState state = new RequestState( handler, applicationName, this.resolver ); RequestState.setState( state ); - handler.getContext().setApplicationName( applicationName ); } return handler; @@ -304,6 +290,7 @@ UserHandler handler = this.getUserHandler( handlerName ); // we don't throw an exception if we are already logged out! if ( handler != null ) { + handler.terminate(); UserState status = this.getUserState(); status.removeHandler( handlerName ); this.updateUserState(); @@ -347,6 +334,17 @@ this.authenticator.enableLogging( this.getLogger() ); this.authenticator.service( this.manager ); this.resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE); + + ContextManager contextManager; + + contextManager = (ContextManager) this.manager.lookup(ContextManager.ROLE); + // add the provider for the authentication context + try { + AuthenticationContextProvider contextProvider = new AuthenticationContextProvider(); + contextManager.addSessionContextProvider(contextProvider, AuthenticationConstants.SESSION_CONTEXT_NAME); + } catch (ProcessingException local) { + throw new ServiceException("Unable to register provider for authentication context.", local); + } } /* (non-Javadoc) 1.2 +11 -1 cocoon-2.1/src/blocks/portal-fw/java/org/apache/cocoon/webapps/portal/context/SessionContextImpl.java Index: SessionContextImpl.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/portal-fw/java/org/apache/cocoon/webapps/portal/context/SessionContextImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SessionContextImpl.java 9 Mar 2003 00:05:19 -0000 1.1 +++ SessionContextImpl.java 4 May 2003 20:19:41 -0000 1.2 @@ -52,6 +52,8 @@ import org.apache.avalon.framework.component.ComponentManager; import org.apache.cocoon.ProcessingException; +import org.apache.cocoon.environment.ObjectModelHelper; +import org.apache.cocoon.environment.Request; import org.apache.cocoon.webapps.portal.PortalConstants; import org.apache.cocoon.webapps.portal.components.PortalManager; import org.apache.cocoon.webapps.session.context.SessionContext; @@ -138,6 +140,9 @@ /** The media type */ private String mediaType; + /** The current request */ + private Request request; + public SessionContextImpl(String name, Map objectModel, PortalManager portal) @@ -174,6 +179,7 @@ } } this.getConfigurationDOM(portal); + this.request = ObjectModelHelper.getRequest( objectModel ); } /** @@ -183,6 +189,10 @@ return this.name; } + public Request getRequest() { + return this.request; + } + /** * Get the layout DOM */ 1.2 +32 -10 cocoon-2.1/src/blocks/portal-fw/java/org/apache/cocoon/webapps/portal/context/SessionContextProviderImpl.java Index: SessionContextProviderImpl.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/portal-fw/java/org/apache/cocoon/webapps/portal/context/SessionContextProviderImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SessionContextProviderImpl.java 9 Mar 2003 00:05:19 -0000 1.1 +++ SessionContextProviderImpl.java 4 May 2003 20:19:41 -0000 1.2 @@ -57,6 +57,7 @@ import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentManager; import org.apache.cocoon.ProcessingException; +import org.apache.cocoon.components.CocoonComponentManager; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.Session; @@ -65,7 +66,6 @@ import org.apache.cocoon.webapps.session.context.SessionContext; import org.apache.cocoon.webapps.session.context.SessionContextProvider; import org.apache.excalibur.source.SourceParameters; -import org.apache.excalibur.source.SourceResolver; import org.xml.sax.SAXException; /** @@ -84,13 +84,13 @@ * @return The context * @throws ProcessingException If the context is not available. */ - public SessionContext getSessionContext(String name, - Map objectModel, - SourceResolver resolver, - ComponentManager manager) + public SessionContext getSessionContext(String name) throws ProcessingException { - SessionContext context = null; - if (name.equals(PortalConstants.SESSION_CONTEXT_NAME) == true) { + ComponentManager manager = CocoonComponentManager.getSitemapComponentManager(); + Map objectModel = CocoonComponentManager.getCurrentEnvironment().getObjectModel(); + + SessionContext context = this.getContext( objectModel, name ); + if (name.equals(PortalConstants.SESSION_CONTEXT_NAME) && context == null) { Request req = ObjectModelHelper.getRequest(objectModel); Session session = req.getSession(false); if (session != null) { @@ -110,7 +110,7 @@ String copletID = value.substring(sepOne+1, sepTwo); String copletNumber = value.substring(sepTwo+1); - if (copletIdentifier.equals("coplet") == true) { + if (copletIdentifier.equals("coplet")) { Map info = new HashMap(3); SessionContextImpl.copletInfo.set(info); @@ -130,8 +130,8 @@ throw new ProcessingException("Portal context not available outside a coplet."); } } - context = new SessionContextImpl(name, objectModel, portal); + objectModel.put(this.getClass().getName()+name, context); } catch (SAXException se) { throw new ProcessingException("SAXException", se); } catch (IOException ioe) { @@ -145,4 +145,26 @@ } return context; } + + /** + * Does the context exist? + */ + public boolean existsSessionContext(String name) + throws ProcessingException { + final Map objectModel = CocoonComponentManager.getCurrentEnvironment().getObjectModel(); + return (this.getContext( objectModel, name) != null); + } + + private SessionContext getContext(Map objectModel, String name) { + SessionContext context = (SessionContext) objectModel.get(this.getClass().getName()+name); + if ( context != null ) { + SessionContextImpl r = (SessionContextImpl)context; + if (!(r.getRequest() == ObjectModelHelper.getRequest( objectModel))) { + context = null; + objectModel.remove(this.getClass().getName()+name); + } + } + return context; + } + } 1.1 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/TransactionManager.java Index: TransactionManager.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 [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.webapps.session; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.webapps.session.context.SessionContext; /** * Transaction management<p> * </p> * Transactions are a series of get/set calls to a session context which must * be seen as atomic (single modification). * We distingish between reading and writing. Usually parallel reading is * allowed but if one thread wants to write, no other can read or write. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id: TransactionManager.java,v 1.1 2003/05/04 20:19:41 cziegeler Exp $ */ public interface TransactionManager { /** Avalon role */ String ROLE = TransactionManager.class.getName();; /** * Reset the transaction management state. */ void resetTransactions(SessionContext context); /** * Start a reading transaction. * This call must always be matched with a stopReadingTransaction(). * Otherwise the session context is blocked. */ void startReadingTransaction(SessionContext context) throws ProcessingException; /** * Stop a reading transaction. * This call must always be done for each startReadingTransaction(). * Otherwise the session context is blocked. */ void stopReadingTransaction(SessionContext context); /** * Start a writing transaction. * This call must always be matched with a stopWritingTransaction(). * Otherwise the session context is blocked. */ void startWritingTransaction(SessionContext context) throws ProcessingException; /** * Stop a writing transaction. * This call must always be done for each startWritingTransaction(). * Otherwise the session context is blocked. */ void stopWritingTransaction(SessionContext context); } 1.1 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/FormManager.java Index: FormManager.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 [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.webapps.session; import org.apache.cocoon.ProcessingException; import org.w3c.dom.DocumentFragment; /** * Form manager * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id: FormManager.java,v 1.1 2003/05/04 20:19:41 cziegeler Exp $ */ public interface FormManager { /** Avalon role */ String ROLE = FormManager.class.getName();; /** * 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, String name, String formName) throws ProcessingException; } 1.1 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/ContextManager.java Index: ContextManager.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 [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.webapps.session; import java.io.IOException; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.webapps.session.context.SessionContext; import org.apache.cocoon.webapps.session.context.SessionContextProvider; import org.xml.sax.SAXException; /** * This is the context manager. * * The main purpose of this component is maintaining contexts. Each * application can have one or more session contexts. * A context is a data container that can hold arbitrary information. * The contained information can either be an XML tree or custom * objects. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id: ContextManager.java,v 1.1 2003/05/04 20:19:41 cziegeler Exp $ */ public interface ContextManager { /** Avalon role */ String ROLE = ContextManager.class.getName();; /** * Add a context provider. */ void addSessionContextProvider(SessionContextProvider provider, String contextName) throws ProcessingException; /** * Create a new public context in the session. * Create a new public session context for this user. If this context * already exists no new context is created and the old one will be used * instead. */ SessionContext createContext(String name, String loadURI, String saveURI) throws IOException, SAXException, ProcessingException; /** * Delete a public context in the session. * If the context exists for this user, it and all of its information * is deleted. */ void deleteContext(String name) throws ProcessingException; /** * Get a public context. * The session context with the given name is returned. If the context does * not exist <CODE>null</CODE> is returned. */ SessionContext getContext(String name) throws ProcessingException; /** * Check if a context exists */ boolean hasSessionContext() throws ProcessingException; /** * Check if a public context exists. * If the session context with the given name exists, <CODE>true</CODE> is * returned. */ boolean existsContext(String name) throws ProcessingException; } 1.1 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/SessionManager.java Index: SessionManager.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 [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.webapps.session; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.environment.Session; import org.apache.cocoon.xml.XMLConsumer; import org.w3c.dom.DocumentFragment; import org.xml.sax.SAXException; /** * * This is the session manager component. * * The main purpose of this component is creating and termination sessions * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id: SessionManager.java,v 1.1 2003/05/04 20:19:41 cziegeler Exp $ */ public interface SessionManager { /** Avalon role */ String ROLE = SessionManager.class.getName();; /** * Create a new session for the user. * A new session is created for this user. If the user has already a session, * no new session is created and the old one is returned. */ Session createSession(); /** * Get the session for the current user. * If the user has no session right now, <CODE>null</CODE> is returned. * If createFlag is true, the session is created if it does not exist. */ Session getSession(boolean createFlag); /** * Terminate the current session. * If the user has a session, this session is terminated and all of its * data is deleted. * @param force If this is set to true the session is terminated, if * it is set to false, the session is only terminated * if no session context is available. */ void terminateSession(boolean force) throws ProcessingException; /** * Get information from the context. * A document fragment containg the xml data stored in the session context * with the given name is returned. If the information is not available, * <CODE>null</CODE> is returned. * @param contextName The name of the public context. * @param path XPath expression specifying which data to get. * @return A DocumentFragment containing the data or <CODE>null</CODE> */ DocumentFragment getContextFragment(String contextName, String path) throws ProcessingException; /** * Stream public context data. * The document fragment containing the data from a path in the * given context is streamed to the consumer. * * @param contextName The name of the public context. * @param path XPath expression specifying which data to get. * * @return If the data is available <code>true</code> is returned, * otherwise <code>false</code> is returned. */ boolean streamContextFragment(String contextName, String path, XMLConsumer consumer) throws SAXException, ProcessingException; /** * Set data in a public context. * The document fragment containing the data is set at the given path in the * public session context. * * @param contextName The name of the public context. * @param path XPath expression specifying where to set the data. * @param fragment The DocumentFragment containing the data. * */ void setContextFragment(String contextName, String path, DocumentFragment fragment) throws ProcessingException; /** * Append data in a public context. * The document fragment containing the data is appended at the given * path in the public session context. * * @param contextName The name of the public context. * @param path XPath expression specifying where to append the data. * @param fragment The DocumentFragment containing the data. * */ void appendContextFragment(String contextName, String path, DocumentFragment fragment) throws ProcessingException; /** * Merge data in a public context. * The document fragment containing the data is merged at the given * path in the public session context. * * @param contextName The name of the public context. * @param path XPath expression specifying where to merge the data. * @param fragment The DocumentFragment containing the data. * */ void mergeContextFragment(String contextName, String path, DocumentFragment fragment) throws ProcessingException; /** * Remove data in a public context. * The data specified by the path is removed from the public session context. * * @param contextName The name of the public context. * @param path XPath expression specifying where to merge the data. * */ void removeContextFragment(String contextName, String path) throws ProcessingException; } 1.1 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/MediaManager.java Index: MediaManager.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 [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.webapps.session; /** * This is the media manager. * It provides simple support for developing multi-channel applications * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id: MediaManager.java,v 1.1 2003/05/04 20:19:41 cziegeler Exp $ */ public interface MediaManager { /** The Avalon Role */ public static final String ROLE = MediaManager.class.getName(); /** * Test if the media of the current request is the given value */ boolean testMedia(String value); /** * Get all media type names */ String[] getMediaTypes(); /** * Return the current media type */ String getMediaType(); } 1.4 +59 -34 cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/context/AuthenticationContext.java Index: AuthenticationContext.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/context/AuthenticationContext.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AuthenticationContext.java 1 May 2003 09:49:14 -0000 1.3 +++ AuthenticationContext.java 4 May 2003 20:19:41 -0000 1.4 @@ -61,6 +61,7 @@ import org.apache.cocoon.components.source.SourceUtil; import org.apache.cocoon.webapps.authentication.AuthenticationConstants; import org.apache.cocoon.webapps.authentication.configuration.ApplicationConfiguration; +import org.apache.cocoon.webapps.authentication.user.RequestState; import org.apache.cocoon.webapps.authentication.user.UserHandler; import org.apache.cocoon.webapps.session.context.SessionContext; import org.apache.cocoon.webapps.session.context.SimpleSessionContext; @@ -89,7 +90,6 @@ private UserHandler handler; private SessionContext authContext; private String handlerName; - private String applicationName; private boolean initialized; public AuthenticationContext(UserHandler handler) { @@ -104,10 +104,6 @@ } } - public void setApplicationName(String name) { - this.applicationName = name; - } - public void init(Document doc) throws ProcessingException { if ( initialized ) { @@ -142,8 +138,10 @@ if (path == null) { throw new ProcessingException("getXML: Path is required"); } - if (path.startsWith("/") == false) path = '/' + path; + if (!path.startsWith("/")) path = '/' + path; + final String applicationName = RequestState.getState().getApplicationName(); + DocumentFragment frag = null; if ( path.equals("/") ) { @@ -154,7 +152,7 @@ // now add root node authentication Node root = frag.getOwnerDocument().createElementNS(null, "authentication"); Node child; - while (frag.hasChildNodes() == true) { + while (frag.hasChildNodes()) { child = frag.getFirstChild(); frag.removeChild(child); root.appendChild(child); @@ -162,9 +160,9 @@ frag.appendChild(root); } - if (this.applicationName != null) { + if (applicationName != null) { // join - DocumentFragment appFrag = this.authContext.getXML("/applications/" + this.applicationName); + DocumentFragment appFrag = this.authContext.getXML("/applications/" + applicationName); if (appFrag != null) { // now add root node application Node root = appFrag.getOwnerDocument().createElementNS(null, "application"); @@ -193,14 +191,14 @@ frag = this.authContext.getXML("/" + path); } else if (path.equals("/application") || path.startsWith("/application/") ) { - if (this.applicationName != null) { + if (applicationName != null) { String appPath; if (path.equals("/application")) { appPath ="/"; } else { appPath = path.substring("/application".length()); } - frag = this.authContext.getXML("/applications/" + this.applicationName + appPath); + frag = this.authContext.getXML("/applications/" + applicationName + appPath); } } else { frag = this.authContext.getXML("/" + path); @@ -223,6 +221,8 @@ } if (!path.startsWith("/")) path = '/' + path; + final String applicationName = RequestState.getState().getApplicationName(); + if ( path.equals("/") ) { // set all is not allowed with "/" throw new ProcessingException("Path '/' is not allowed"); @@ -235,16 +235,16 @@ } else if (path.equals("/application") || path.startsWith("/application/") ) { - if (this.applicationName == null) { + if (applicationName == null) { throw new ProcessingException("Application is required"); } String appPath; - if (path.equals("/application") == true) { + if (path.equals("/application")) { appPath = "/"; } else { appPath = path.substring("/application".length()); } - this.authContext.setXML("/applications/" + this.applicationName + appPath, fragment); + this.authContext.setXML("/applications/" + applicationName + appPath, fragment); } else { this.authContext.setXML("/" + path, fragment); @@ -266,6 +266,8 @@ } if (!path.startsWith("/") ) path = '/' + path; + final String applicationName = RequestState.getState().getApplicationName(); + if ( path.equals("/") ) { // set all is not allowed with "/" throw new ProcessingException("Path '/' is not allowed"); @@ -278,7 +280,7 @@ } else if (path.equals("/application") || path.startsWith("/application/") ) { - if (this.applicationName == null) { + if (applicationName == null) { throw new ProcessingException("Application is required"); } String appPath; @@ -287,7 +289,7 @@ } else { appPath = path.substring("/application".length()); } - this.authContext.appendXML("/applications/" + this.applicationName + appPath, fragment); + this.authContext.appendXML("/applications/" + applicationName + appPath, fragment); } else { this.authContext.appendXML("/" + path, fragment); @@ -307,6 +309,8 @@ } if (!path.startsWith("/") ) path = '/' + path; + final String applicationName = RequestState.getState().getApplicationName(); + if (path.equals("/") ) { this.cleanParametersCache(); this.authContext.removeXML("/"); @@ -318,7 +322,7 @@ } else if (path.equals("/application") || path.startsWith("/application/") ) { - if (this.applicationName == null) { + if (applicationName == null) { throw new ProcessingException("removeXML: Application is required for path " + path); } String appPath; @@ -327,7 +331,7 @@ } else { appPath = path.substring("/application".length()); } - this.authContext.removeXML("/applications/" + this.applicationName + appPath); + this.authContext.removeXML("/applications/" + applicationName + appPath); } else { this.authContext.removeXML("/" + path); } @@ -424,15 +428,17 @@ } if (!path.startsWith("/") ) path = '/' + path; + final String applicationName = RequestState.getState().getApplicationName(); + if (path.equals("/") ) { // get all: first authentication then application contentHandler.startElement(null, "authentication", "authentication", new AttributesImpl()); this.authContext.streamXML("/authentication", contentHandler, lexicalHandler); contentHandler.endElement(null, "authentication", "authentication"); - if (this.applicationName != null) { + if (applicationName != null) { contentHandler.startElement(null, "application", "application", new AttributesImpl()); - this.authContext.streamXML("/applications/" + this.applicationName, contentHandler, lexicalHandler); + this.authContext.streamXML("/applications/" + applicationName, contentHandler, lexicalHandler); contentHandler.endElement(null, "application", "application"); } return true; @@ -441,14 +447,14 @@ return this.authContext.streamXML('/' + path, contentHandler, lexicalHandler); } else if (path.equals("/application") || path.startsWith("/application/") ) { - if (this.applicationName != null) { + if (applicationName != null) { String appPath; if (path.equals("/application") ) { appPath ="/"; } else { appPath = path.substring("/application".length()); } - return this.authContext.streamXML("/applications/" + this.applicationName + appPath, contentHandler, lexicalHandler); + return this.authContext.streamXML("/applications/" + applicationName + appPath, contentHandler, lexicalHandler); } } else { return this.authContext.streamXML('/' + path, contentHandler, lexicalHandler); @@ -469,6 +475,7 @@ throws SAXException, ProcessingException, IOException { if (!path.startsWith("/") ) path = '/' + path; + final String applicationName = RequestState.getState().getApplicationName(); if (path.equals("/") ) { // load all: first authentication then application this.loadAuthenticationXML("/authentication", @@ -476,7 +483,7 @@ objectModel, resolver, manager); - if (this.applicationName != null) { + if (applicationName != null) { this.loadApplicationXML("/", parameters, objectModel, @@ -484,20 +491,20 @@ manager); } - } else if (path.startsWith("/authentication") == true) { + } else if (path.startsWith("/authentication") ) { this.loadAuthenticationXML(path, parameters, objectModel, resolver, manager); - } else if (path.equals("/application") == true && this.applicationName != null) { + } else if (path.equals("/application") && applicationName != null) { this.loadApplicationXML("/", parameters, objectModel, resolver, manager); - } else if (path.startsWith("/application/") == true && this.applicationName != null) { + } else if (path.startsWith("/application/") && applicationName != null) { this.loadApplicationXML(path.substring(12), // start path with '/' parameters, objectModel, @@ -521,6 +528,8 @@ throws SAXException, ProcessingException, IOException { if (!path.startsWith("/") ) path = '/' + path; + final String applicationName = RequestState.getState().getApplicationName(); + if (path.equals("/") ) { // save all: first authentication then application this.saveAuthenticationXML("/authentication", @@ -528,7 +537,7 @@ objectModel, resolver, manager); - if (this.applicationName != null) { + if (applicationName != null) { this.saveApplicationXML("/", parameters, objectModel, @@ -536,20 +545,20 @@ manager); } - } else if (path.startsWith("/authentication") == true) { + } else if (path.startsWith("/authentication") ) { this.saveAuthenticationXML(path, parameters, objectModel, resolver, manager); - } else if (path.equals("/application") == true && this.applicationName != null) { + } else if (path.equals("/application") && applicationName != null) { this.saveApplicationXML("/", parameters, objectModel, resolver, manager); - } else if (path.startsWith("/application/") == true && this.applicationName != null) { + } else if (path.startsWith("/application/") && applicationName != null) { this.saveApplicationXML(path.substring(12), // start path with '/' parameters, objectModel, @@ -566,6 +575,7 @@ private void cleanParametersCache() throws ProcessingException { this.authContext.setAttribute("cachedmap" , null); + this.authContext.setAttribute("cachedpar" , null); } /** @@ -656,7 +666,9 @@ SourceResolver resolver, ComponentManager manager) throws ProcessingException { - final ApplicationConfiguration conf = (ApplicationConfiguration)this.handler.getHandlerConfiguration().getApplications().get( this.applicationName ); + final String applicationName = RequestState.getState().getApplicationName(); + + final ApplicationConfiguration conf = (ApplicationConfiguration)this.handler.getHandlerConfiguration().getApplications().get( applicationName ); String loadResource = conf.getLoadResource(); SourceParameters loadResourceParameters = conf.getLoadResourceParameters(); if (loadResource == null) { @@ -694,7 +706,8 @@ SourceResolver resolver, ComponentManager manager) throws ProcessingException { - final ApplicationConfiguration conf = (ApplicationConfiguration)this.handler.getHandlerConfiguration().getApplications().get( this.applicationName ); + final String applicationName = RequestState.getState().getApplicationName(); + final ApplicationConfiguration conf = (ApplicationConfiguration)this.handler.getHandlerConfiguration().getApplications().get( applicationName ); String saveResource = conf.getSaveResource(); SourceParameters saveResourceParameters = conf.getSaveResourceParameters(); @@ -739,6 +752,8 @@ throws ProcessingException { if (parameters == null) parameters = new SourceParameters(); + final String applicationName = RequestState.getState().getApplicationName(); + // add all elements from inside the handler data this.addParametersFromAuthenticationXML("/data", parameters); @@ -750,7 +765,7 @@ // add application and path parameters.setSingleParameterValue("handler", this.handlerName); if ( appendAppInfo ) { - if (this.applicationName != null) parameters.setSingleParameterValue("application", this.applicationName); + if (applicationName != null) parameters.setSingleParameterValue("application", applicationName); } if (path != null) parameters.setSingleParameterValue("path", path); @@ -823,6 +838,16 @@ return map; } + public SourceParameters getContextInfoAsParameters() + throws ProcessingException { + SourceParameters pars = (SourceParameters)this.authContext.getAttribute( "cachedpar" ); + if (pars == null) { + pars = this.createParameters(null, null, false); + this.authContext.setAttribute("cachedpar", pars); + } + return pars; + } + /** * Load XML of an application */ 1.3 +11 -13 cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/context/AuthenticationContextProvider.java Index: AuthenticationContextProvider.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/context/AuthenticationContextProvider.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AuthenticationContextProvider.java 1 May 2003 09:49:14 -0000 1.2 +++ AuthenticationContextProvider.java 4 May 2003 20:19:41 -0000 1.3 @@ -50,15 +50,11 @@ */ package org.apache.cocoon.webapps.authentication.context; -import java.util.Map; - -import org.apache.avalon.framework.component.ComponentManager; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.webapps.authentication.user.RequestState; import org.apache.cocoon.webapps.authentication.user.UserHandler; import org.apache.cocoon.webapps.session.context.SessionContext; import org.apache.cocoon.webapps.session.context.SessionContextProvider; -import org.apache.excalibur.source.SourceResolver; /** @@ -73,16 +69,10 @@ /** * Get the context * @param name The name of the context - * @param objectModel The objectModel of the current request. - * @param resolver The source resolver - * @param componentManager manager * @return The context * @throws ProcessingException If the context is not available. */ - public SessionContext getSessionContext(String name, - Map objectModel, - SourceResolver resolver, - ComponentManager manager) + public SessionContext getSessionContext(String name) throws ProcessingException { AuthenticationContext context = null; if (name.equals(org.apache.cocoon.webapps.authentication.AuthenticationConstants.SESSION_CONTEXT_NAME) ) { @@ -91,10 +81,18 @@ UserHandler handler = state.getHandler(); if ( handler != null ) { context = handler.getContext(); - context.setApplicationName(state.getApplicationName()); } + } } } return context; + } + + /** + * Does the context exist? + */ + public boolean existsSessionContext(String name) + throws ProcessingException { + return (this.getSessionContext( name ) != null); } } 1.2 +64 -5 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/components/AbstractSessionComponent.java Index: AbstractSessionComponent.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/components/AbstractSessionComponent.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AbstractSessionComponent.java 9 Mar 2003 00:06:08 -0000 1.1 +++ AbstractSessionComponent.java 4 May 2003 20:19:41 -0000 1.2 @@ -66,6 +66,10 @@ import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.Response; 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.SessionManager; +import org.apache.cocoon.webapps.session.TransactionManager; import org.xml.sax.SAXException; /** @@ -77,8 +81,11 @@ public abstract class AbstractSessionComponent extends AbstractLogEnabled implements Component, Composable, Recomposable, Recyclable, RequestLifecycleComponent { - private SessionManager sessionManager; - + private SessionManager sessionManager; + private FormManager formManager; + private ContextManager contextManager; + private TransactionManager transactionManager; + protected ComponentManager manager; /** The current object model */ @@ -94,7 +101,8 @@ /** * Composer interface. Get the Avalon ComponentManager. */ - public void compose(ComponentManager manager) { + public void compose(ComponentManager manager) + throws ComponentException { this.manager = manager; } @@ -138,13 +146,64 @@ } /** + * Get the ContextManager component + */ + protected ContextManager getContextManager() + throws ProcessingException { + if (this.contextManager == null) { + try { + this.contextManager = (ContextManager)this.manager.lookup(ContextManager.ROLE); + } catch (ComponentException ce) { + throw new ProcessingException("Error during lookup of ContextManager component.", ce); + } + } + return this.contextManager; + } + + /** + * Get the ContextManager component + */ + protected TransactionManager getTransactionManager() + throws ProcessingException { + if (this.transactionManager == null) { + try { + this.transactionManager = (TransactionManager)this.manager.lookup(TransactionManager.ROLE); + } catch (ComponentException ce) { + throw new ProcessingException("Error during lookup of TransactionManager component.", ce); + } + } + return this.transactionManager; + } + + /** + * Get the FormManager component + */ + protected FormManager getFormManager() + throws ProcessingException { + if (this.formManager == null) { + try { + this.formManager = (FormManager)this.manager.lookup(FormManager.ROLE); + } catch (ComponentException ce) { + throw new ProcessingException("Error during lookup of FormManager component.", ce); + } + } + return this.formManager; + } + + /** * Recycle */ public void recycle() { if (this.manager != null) { - this.manager.release(this.sessionManager); + this.manager.release( (Component)this.sessionManager); + this.manager.release( (Component)this.formManager); + this.manager.release( (Component)this.contextManager); + this.manager.release( (Component)this.transactionManager); } + this.transactionManager = null; this.sessionManager = null; + this.formManager = null; + this.contextManager = null; this.objectModel = null; this.resolver = null; this.request = null; 1.1 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/components/DefaultContextManager.java Index: DefaultContextManager.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 [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.webapps.session.components; import java.io.IOException; import java.util.HashMap; import java.util.Map; 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.logger.AbstractLogEnabled; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.components.CocoonComponentManager; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.Session; import org.apache.cocoon.webapps.session.ContextManager; import org.apache.cocoon.webapps.session.SessionConstants; import org.apache.cocoon.webapps.session.context.SessionContext; import org.apache.cocoon.webapps.session.context.SessionContextProvider; import org.apache.cocoon.webapps.session.context.SimpleSessionContext; import org.apache.cocoon.webapps.session.context.StandardSessionContextProvider; import org.xml.sax.SAXException; /** * Context manager * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id: DefaultContextManager.java,v 1.1 2003/05/04 20:19:41 cziegeler Exp $ */ public final class DefaultContextManager extends AbstractLogEnabled implements Composable, ContextManager, ThreadSafe, Component { /** The <code>ComponentManager</code> */ private ComponentManager manager; /** Registered context provider */ private Map contextProvider = new HashMap(); /* The list of reserved contexts */ static private String[] reservedContextNames = {"session", "context"}; /** * Avalon Composer Interface */ public void compose(ComponentManager manager) throws ComponentException { this.manager = manager; // add standard provider SessionContextProvider provider = new StandardSessionContextProvider(); try { this.addSessionContextProvider(provider, SessionConstants.TEMPORARY_CONTEXT); this.addSessionContextProvider(provider, SessionConstants.REQUEST_CONTEXT); this.addSessionContextProvider(provider, SessionConstants.RESPONSE_CONTEXT); } catch (ProcessingException e) { throw new ComponentException("Unable to register default session context provider.", e); } } /** * Get the session */ private Session getSession(boolean create) { final Map objectModel = CocoonComponentManager.getCurrentEnvironment().getObjectModel(); final Request request = ObjectModelHelper.getRequest( objectModel ); return request.getSession( create ); } /** * Get the list of contexts */ private Map getSessionContexts(Session session) { Map contexts; contexts = (Map)session.getAttribute(SessionContext.class.getName()); if (contexts == null) { contexts = new HashMap(5, 3); session.setAttribute(SessionContext.class.getName(), contexts); } return contexts; } /** * Checks if the context name is a reserved context. */ private boolean isReservedContextName(String name) { // synchronized (not needed) int i, l; boolean found; found = false; i = 0; l = reservedContextNames.length; while (i < l && found == false) { found = reservedContextNames[i].equals(name); i++; } if (!found ) { found = (contextProvider.get(name) != null); } return found; } /** * Add a context provider. */ public synchronized void addSessionContextProvider(SessionContextProvider provider, String contextName) throws ProcessingException { if (contextName != null && provider != null) { if (this.isReservedContextName(contextName)) { throw new ProcessingException("Unable to register context '"+contextName+"' : Already registered."); } this.contextProvider.put(contextName, provider); } else { throw new ProcessingException("Unable to add new provider: Name or provider info missing."); } } /** * Get a reserved context */ private boolean existsReservedContext(String name) throws ProcessingException { // synchronized (not needed) boolean exists = false; SessionContextProvider provider = (SessionContextProvider)contextProvider.get(name); if (provider != null) { exists = provider.existsSessionContext( name ); } return exists; } /** * Get a reserved context */ private SessionContext getReservedContext(String name) throws ProcessingException { // synchronized SessionContext context = null; SessionContextProvider provider = (SessionContextProvider)contextProvider.get(name); if (provider != null) { synchronized (provider) { context = provider.getSessionContext(name); } } return context; } /** * Create a new public context in the session. * Create a new public session context for this user. If this context * already exists no new context is created and the old one will be used * instead. */ public SessionContext createContext(String name, String loadURI, String saveURI) throws IOException, SAXException, ProcessingException { // synchronized if (this.getLogger().isDebugEnabled()) { this.getLogger().debug("BEGIN createContext name=" + name + "load=" + loadURI + "save=" + saveURI); } // test arguments if (name == null) { throw new ProcessingException("CreateContext: Name is required"); } Session session = this.getSession(true); if (session == null) { throw new ProcessingException("CreateContext: Session is required"); } SessionContext context; synchronized(session) { // test for reserved context if (this.isReservedContextName(name)) { throw new ProcessingException("SessionContext with name " + name + " is reserved and cannot be created manually."); } if (this.existsContext(name)) { context = this.getContext(name); } else { Map contexts = this.getSessionContexts(session); context = new SimpleSessionContext(); context.setup(name, loadURI, saveURI); contexts.put(name, context); } } if (this.getLogger().isDebugEnabled()) { this.getLogger().debug("END createContext context="+context); } return context; } /** * Delete a public context in the session. * If the context exists for this user, it and all of its information * is deleted. */ public void deleteContext(String name) throws ProcessingException { // synchronized if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("BEGIN deleteContext name=" + name); } // test arguments if (name == null) { throw new ProcessingException("SessionManager.deleteContext: Name is required"); } if (this.isReservedContextName(name)) { throw new ProcessingException("SessionContext with name " + name + " is reserved and cannot be deleted manually."); } Session session = this.getSession(false); if (session == null) { throw new ProcessingException("SessionManager.deleteContext: Session is required"); } synchronized(session) { final Map contexts = this.getSessionContexts(session); if (contexts.containsKey(name)) { SessionContext context = (SessionContext)contexts.get(name); contexts.remove(name); } } if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("END deleteContext"); } } /** * Get a public context. * The session context with the given name is returned. If the context does * not exist <CODE>null</CODE> is returned. */ public SessionContext getContext(String name) throws ProcessingException { // synchronized if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("BEGIN getContext name=" + name); } SessionContext context; if (this.isReservedContextName(name) ) { context = this.getReservedContext(name); } else { Session session = this.getSession(false); if ( session != null) { synchronized (session) { final Map contexts = this.getSessionContexts( session ); context = (SessionContext)contexts.get(name); } } else { context = null; } } if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("END getContext context=" + context); } return context; } /** * Check if a context exists */ public boolean hasSessionContext() throws ProcessingException { Session session = this.getSession(false); if (session == null) { throw new ProcessingException("SessionManager.hasSessionContext: Session is required."); } synchronized (session) { final Map contexts = this.getSessionContexts(session); return !(contexts.isEmpty()); } } /** * Check if a public context exists. * If the session context with the given name exists, <CODE>true</CODE> is * returned. */ public boolean existsContext(String name) throws ProcessingException { Session session = this.getSession(false); if (session == null) { throw new ProcessingException("SessionManager.existsContext: Session is required."); } synchronized (session) { final Map contexts = this.getSessionContexts(session); boolean result = contexts.containsKey(name); if (!result && this.isReservedContextName(name) ) { result = this.existsReservedContext(name); } return result; } } } 1.1 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/components/DefaultTransactionManager.java Index: DefaultTransactionManager.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 [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.webapps.session.components; import java.util.HashMap; import java.util.Map; import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.components.CocoonComponentManager; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.Session; import org.apache.cocoon.webapps.session.TransactionManager; import org.apache.cocoon.webapps.session.context.SessionContext; /** * This is the default implementation for the transaction manager. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id: DefaultTransactionManager.java,v 1.1 2003/05/04 20:19:41 cziegeler Exp $ */ public final class DefaultTransactionManager extends AbstractLogEnabled implements Component, ThreadSafe, TransactionManager { /** * Get the transaction states from the current session */ private TransactionState getSessionContextsTransactionState(SessionContext context) { final Map objectModel = CocoonComponentManager.getCurrentEnvironment().getObjectModel(); final Request request = ObjectModelHelper.getRequest( objectModel ); final Session session = request.getSession(true); Map transactionStates = (Map)session.getAttribute(this.getClass().getName()); if (transactionStates == null) { transactionStates = new HashMap(5, 3); session.setAttribute(this.getClass().getName(), transactionStates); } TransactionState state = (TransactionState)transactionStates.get(context); if ( state == null ) { state = new TransactionState(); transactionStates.put(context, state); } return state; } private class TransactionState { /** number readers reading*/ public int nr=0; /** number of readers total (reading or waiting to read)*/ public int nrtotal=0; /** number writers writing, 0 or 1 */ public int nw=0; /** number of writers total (writing or waiting to write)*/ public int nwtotal=0; } /** * Reset the transaction management state. */ public void resetTransactions(SessionContext context) { TransactionState ts = (TransactionState)this.getSessionContextsTransactionState(context); ts.nr=0; ts.nrtotal=0; ts.nw=0; ts.nwtotal=0; } /** * Start a reading transaction. * This call must always be matched with a stopReadingTransaction(). * Otherwise the session context is blocked. */ public synchronized void startReadingTransaction(SessionContext context) throws ProcessingException { TransactionState ts = (TransactionState)this.getSessionContextsTransactionState(context); ts.nrtotal++; while (ts.nw!=0) { try { wait(); } catch (InterruptedException local) { throw new ProcessingException("Interrupted", local); } } ts.nr++; } /** * Stop a reading transaction. * This call must always be done for each startReadingTransaction(). * Otherwise the session context is blocked. */ public synchronized void stopReadingTransaction(SessionContext context) { TransactionState ts = (TransactionState)this.getSessionContextsTransactionState(context); ts.nr--; ts.nrtotal--; if (ts.nrtotal==0) notify(); } /** * Start a writing transaction. * This call must always be matched with a stopWritingTransaction(). * Otherwise the session context is blocked. */ public synchronized void startWritingTransaction(SessionContext context) throws ProcessingException { TransactionState ts = (TransactionState)this.getSessionContextsTransactionState(context); ts.nwtotal++; while (ts.nrtotal+ts.nw != 0) { try { wait(); } catch (InterruptedException local) { throw new ProcessingException("Interrupted", local); } } ts.nw=1; } /** * Stop a writing transaction. * This call must always be done for each startWritingTransaction(). * Otherwise the session context is blocked. */ public synchronized void stopWritingTransaction(SessionContext context) { TransactionState ts = (TransactionState)this.getSessionContextsTransactionState(context); ts.nw=0; ts.nwtotal--; notifyAll(); } } 1.1 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/components/DefaultMediaManager.java Index: DefaultMediaManager.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 [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.webapps.session.components; import java.io.IOException; import java.util.Map; import org.apache.avalon.excalibur.pool.Recyclable; import org.apache.avalon.framework.component.Component; 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.ProcessingException; import org.apache.cocoon.components.RequestLifecycleComponent; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.webapps.session.MediaManager; import org.xml.sax.SAXException; /** * This is the default implementation for the media manager * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id: DefaultMediaManager.java,v 1.1 2003/05/04 20:19:41 cziegeler Exp $ */ public final class DefaultMediaManager extends AbstractLogEnabled implements MediaManager, Configurable, RequestLifecycleComponent, Recyclable, Component { /** The media Types */ private PreparedMediaType[] allMediaTypes; /** The default media type (usually this is html) */ private String defaultMediaType; /** All media type names */ private String[] mediaTypeNames; /** tThe current media type */ private String mediaType; /** The current request */ private Request request; /** * Configurable interface. */ public void configure(Configuration myConfiguration) throws ConfigurationException { // no sync required Configuration mediaConf = myConfiguration.getChild("mediatypes", false); if (mediaConf == null) { // default configuration this.defaultMediaType = "html"; } else { this.defaultMediaType = mediaConf.getAttribute("default", "html"); } this.mediaTypeNames = new String[1]; this.mediaTypeNames[0] = this.defaultMediaType; boolean found; int i; String name; Configuration[] childs = mediaConf.getChildren("media"); PreparedMediaType[] array = new PreparedMediaType[0]; PreparedMediaType[] copy; Configuration current; if (childs != null) { for(int x = 0; x < childs.length; x++) { current = childs[x]; copy = new PreparedMediaType[array.length + 1]; System.arraycopy(array, 0, copy, 0, array.length); array = copy; name = current.getAttribute("name"); array[array.length-1] = new PreparedMediaType(name, current.getAttribute("useragent")); found = false; i = 0; while ( i < this.mediaTypeNames.length && found == false) { found = this.mediaTypeNames[i].equals(name); i++; } if (found == false) { String[] newStrings = new String[this.mediaTypeNames.length + 1]; System.arraycopy(this.mediaTypeNames, 0, newStrings, 0, this.mediaTypeNames.length); newStrings[newStrings.length-1] = name; this.mediaTypeNames = newStrings; } } } this.allMediaTypes = array; } /** * Get the current media type */ public void setup(SourceResolver resolver, Map objectModel) throws ProcessingException, SAXException, IOException { this.request = ObjectModelHelper.getRequest( objectModel ); // get the media of the current request String useragent = this.request.getHeader("User-Agent"); PreparedMediaType media = null; if (useragent != null) { int i, l; i = 0; l = this.allMediaTypes.length; while (i < l && media == null) { if (useragent.indexOf(this.allMediaTypes[i].useragent) == -1) { i++; } else { media = this.allMediaTypes[i]; } } } this.mediaType = (media == null ? this.defaultMediaType : media.name); } /** * Test if the media of the current request is the given value */ public boolean testMedia(String value) { // synchronized boolean result = false; String useragent = this.request.getHeader("User-Agent"); PreparedMediaType theMedia = null; int i, l; i = 0; l = this.allMediaTypes.length; while (i < l && theMedia == null) { if (useragent.indexOf(this.allMediaTypes[i].useragent) == -1) { i++; } else { theMedia = this.allMediaTypes[i]; } } if (theMedia != null) { result = theMedia.name.equals(value); } else { result = this.defaultMediaType.equals(value); } return result; } /** * Get all media type names */ public String[] getMediaTypes() { // synchronized return this.mediaTypeNames; } /** * Return the current media type */ public String getMediaType() { // synchronized return this.mediaType; } /** * Recyclable */ public void recycle() { this.request = null; this.mediaType = null; } } /** * This class stores the media type configuration */ final class PreparedMediaType { String name; String useragent; PreparedMediaType(String name, String useragent) { this.name = name; this.useragent = useragent; } } 1.1 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/components/DefaultSessionManager.java Index: DefaultSessionManager.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 [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.webapps.session.components; import java.util.Map; import org.apache.avalon.framework.activity.Disposable; 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.logger.AbstractLogEnabled; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.components.CocoonComponentManager; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Session; import org.apache.cocoon.webapps.session.ContextManager; import org.apache.cocoon.webapps.session.SessionConstants; import org.apache.cocoon.webapps.session.SessionManager; import org.apache.cocoon.webapps.session.context.SessionContext; import org.apache.cocoon.xml.XMLConsumer; import org.apache.cocoon.xml.XMLUtils; import org.apache.cocoon.xml.dom.DOMUtil; import org.w3c.dom.DocumentFragment; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; /** * This is the default implementation of the session manager * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id: DefaultSessionManager.java,v 1.1 2003/05/04 20:19:41 cziegeler Exp $ */ public final class DefaultSessionManager extends AbstractLogEnabled implements Composable, Component, ThreadSafe, SessionManager, Disposable { /** The <code>ComponentManager</code> */ private ComponentManager manager; /** The context manager */ private ContextManager contextManager; /** * Avalon Composable Interface */ public void compose(ComponentManager manager) throws ComponentException { this.manager = manager; this.contextManager = (ContextManager)this.manager.lookup(ContextManager.ROLE); } /** * Avalon Disposable Interface */ public void dispose() { if (this.manager != null ) { this.manager.release( (Component)this.contextManager); this.manager = null; this.contextManager = null; } } /** * Create a new session for the user. * A new session is created for this user. If the user has already a session, * no new session is created and the old one is returned. */ public Session createSession() { // synchronized if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("BEGIN createSession"); } Session session = this.getSession(true); if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("END createSession session=" + session); } return session; } /** * Get the session for the current user. * If the user has no session right now, <CODE>null</CODE> is returned. * If createFlag is true, the session is created if it does not exist. */ public Session getSession(boolean createFlag) { final Map objectModel = CocoonComponentManager.getCurrentEnvironment().getObjectModel(); // synchronized if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("BEGIN getSession create=" + createFlag); } Session session = ObjectModelHelper.getRequest(objectModel).getSession(createFlag); if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("END getSession session=" + session); } return session; } /** * Terminate the current session. * If the user has a session, this session is terminated and all of its * data is deleted. * @param force If this is set to true the session is terminated, if * it is set to false, the session is only terminated * if no session context is available. */ public void terminateSession(boolean force) throws ProcessingException { // synchronized if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("BEGIN terminateSession force="+force); } Session session = this.getSession( false ); if (session != null) { if (force || this.contextManager.hasSessionContext() ) { synchronized(session) { session.invalidate(); } } } if (this.getLogger().isDebugEnabled()) { this.getLogger().debug("END terminateSession"); } } /** * Get information from the context. * A document fragment containg the xml data stored in the session context * with the given name is returned. If the information is not available, * <CODE>null</CODE> is returned. * @param contextName The name of the public context. * @param path XPath expression specifying which data to get. * @return A DocumentFragment containing the data or <CODE>null</CODE> */ public DocumentFragment getContextFragment(String contextName, String path) throws ProcessingException { // synchronized via context if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("BEGIN getContextFragment name=" + contextName + ", path=" + path); } // test arguments if (contextName == null) { throw new ProcessingException("SessionManager.getContextFragment: Name is required"); } if (path == null) { throw new ProcessingException("SessionManager.getContextFragment: Path is required"); } SessionContext context = this.contextManager.getContext( contextName ); if (context == null) { throw new ProcessingException("SessionManager.getContextFragment: Context '" + contextName + "' not found."); } DocumentFragment frag; frag = context.getXML(path); if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("END getContextFragment documentFragment=" + (frag == null ? "null" : XMLUtils.serializeNodeToXML(frag))); } return frag; } /** * Stream public context data. * The document fragment containing the data from a path in the * given context is streamed to the consumer. * * @param contextName The name of the public context. * @param path XPath expression specifying which data to get. * * @return If the data is available <code>true</code> is returned, * otherwise <code>false</code> is returned. */ public boolean streamContextFragment(String contextName, String path, XMLConsumer consumer) throws SAXException, ProcessingException { // synchronized via context if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("BEGIN streamContextFragment name=" + contextName + ", path=" + path + ", consumer"+consumer); } boolean streamed = false; // test arguments if (contextName == null) { throw new ProcessingException("SessionManager.streamContextFragment: Name is required"); } if (path == null) { throw new ProcessingException("SessionManager.streamContextFragment: Path is required"); } SessionContext context = this.contextManager.getContext( contextName ); if (context == null) { throw new ProcessingException("SessionManager.streamContextFragment: Context '" + contextName + "' not found."); } streamed = context.streamXML(path, consumer, consumer); if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("END streamContextFragment streamed=" + streamed); } return streamed; } /** * Set data in a public context. * The document fragment containing the data is set at the given path in the * public session context. * * @param contextName The name of the public context. * @param path XPath expression specifying where to set the data. * @param fragment The DocumentFragment containing the data. * */ public void setContextFragment(String contextName, String path, DocumentFragment fragment) throws ProcessingException { // synchronized via context if (this.getLogger().isDebugEnabled()) { this.getLogger().debug("BEGIN setContextFragment name=" + contextName + ", path=" + path + ", fragment=" + (fragment == null ? "null" : XMLUtils.serializeNodeToXML(fragment))); } // test arguments if (contextName == null) { throw new ProcessingException("SessionManager.setContextFragment: Name is required"); } if (path == null) { throw new ProcessingException("SessionManager.setContextFragment: Path is required"); } if (fragment == null) { throw new ProcessingException("SessionManager.setContextFragment: Fragment is required"); } // get context SessionContext context = this.contextManager.getContext( contextName ); // check context if (context == null) { throw new ProcessingException("SessionManager.setContextFragment: Context '" + contextName + "' not found."); } context.setXML(path, fragment); if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("END setContextFragment"); } } /** * Append data in a public context. * The document fragment containing the data is appended at the given * path in the public session context. * * @param contextName The name of the public context. * @param path XPath expression specifying where to append the data. * @param fragment The DocumentFragment containing the data. * */ public void appendContextFragment(String contextName, String path, DocumentFragment fragment) throws ProcessingException { // synchronized via context if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("BEGIN appendContextFragment name=" + contextName + ", path=" + path + ", fragment=" + (fragment == null ? "null" : XMLUtils.serializeNodeToXML(fragment))); } // test arguments if (contextName == null) { throw new ProcessingException("SessionManager.appendContextFragment: Name is required"); } if (path == null) { throw new ProcessingException("SessionManager.appendContextFragment: Path is required"); } if (fragment == null) { throw new ProcessingException("SessionManager.appendContextFragment: Fragment is required"); } // get context SessionContext context = this.contextManager.getContext( contextName ); // check context if (context == null) { throw new ProcessingException("SessionManager.appendContextFragment: Context '" + contextName + "' not found."); } context.appendXML(path, fragment); if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("END appendContextFragment"); } } /** * Merge data in a public context. * The document fragment containing the data is merged at the given * path in the public session context. * * @param contextName The name of the public context. * @param path XPath expression specifying where to merge the data. * @param fragment The DocumentFragment containing the data. * */ public void mergeContextFragment(String contextName, String path, DocumentFragment fragment) throws ProcessingException { // synchronized via context if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("BEGIN mergeContextFragment name=" + contextName + ", path=" + path + ", fragment=" + (fragment == null ? "null" : XMLUtils.serializeNodeToXML(fragment))); } // test arguments if (contextName == null) { throw new ProcessingException("SessionManager.mergeContextFragment: Name is required"); } if (path == null) { throw new ProcessingException("SessionManager.mergeContextFragment: Path is required"); } if (fragment == null) { throw new ProcessingException("SessionManager.mergeContextFragment: Fragment is required"); } // get context SessionContext context = this.contextManager.getContext( contextName ); // check context if (context == null) { throw new ProcessingException("SessionManager.mergeContextFragment: Context '" + contextName + "' not found."); } Node contextNode = context.getSingleNode(path); if (contextNode == null) { // no merge required context.setXML(path, fragment); } else { this.importNode(contextNode, fragment, false); context.setNode(path, contextNode); } if (this.getLogger().isDebugEnabled()) { this.getLogger().debug("END mergeContextFragment"); } } /** * Remove data in a public context. * The data specified by the path is removed from the public session context. * * @param contextName The name of the public context. * @param path XPath expression specifying where to merge the data. * */ public void removeContextFragment(String contextName, String path) throws ProcessingException { // synchronized via context if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("BEGIN removeContextFragment name=" + contextName + ", path=" + path); } // test arguments if (contextName == null) { throw new ProcessingException("SessionManager.removeContextFragment: Name is required"); } if (path == null) { throw new ProcessingException("SessionManager.removeContextFragment: Path is required"); } // get context SessionContext context = this.contextManager.getContext( contextName ); // check context if (context == null) { throw new ProcessingException("SessionManager.removeContextFragment: Context '" + contextName + "' not found."); } context.removeXML(path); if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("END removeContextFragment"); } } /** * Import nodes. If preserve is set to true, the nodes * marked with cocoon:preserve are always imported * overwriting others! */ private void importNode(Node profile, Node delta, boolean preserve) { // no sync req NodeList profileChilds = null; NodeList deltaChilds = delta.getChildNodes(); int i, len; int m, l; boolean found; Node currentDelta = null; Node currentProfile = null; len = deltaChilds.getLength(); for(i = 0; i < len; i++) { currentDelta = deltaChilds.item(i); if (currentDelta.getNodeType() == Node.ELEMENT_NODE) { // search the delta node in the profile profileChilds = profile.getChildNodes(); l = profileChilds.getLength(); m = 0; found = false; while (found == false && m < l) { currentProfile = profileChilds.item(m); if (currentProfile.getNodeType() == Node.ELEMENT_NODE && currentProfile.getNodeName().equals(currentDelta.getNodeName()) == true) { // now we have found a node with the same name // next: the attributes must match also found = DOMUtil.compareAttributes((Element)currentProfile, (Element)currentDelta); } if (found == false) m++; } if (found == true) { // this is not new if (preserve == true && ((Element)currentDelta).hasAttributeNS(SessionConstants.SESSION_NAMESPACE_URI, "preserve") && ((Element)currentDelta).getAttributeNS(SessionConstants.SESSION_NAMESPACE_URI, "preserve").equalsIgnoreCase("true")) { // replace the original with the delta profile.replaceChild(profile.getOwnerDocument().importNode(currentDelta, true), currentProfile); } else { // do we have elements as children or text? if (currentDelta.hasChildNodes() == true) { currentDelta.normalize(); currentProfile.normalize(); // do a recursive call for sub elements this.importNode((Element)currentProfile, (Element)currentDelta, preserve); // and now the text nodes: Remove all from the profile and add all // of the delta NodeList childs = currentProfile.getChildNodes(); int index, max; max = childs.getLength(); for(index = max - 1; index >= 0; index--) { if (childs.item(index).getNodeType() == Node.TEXT_NODE) { currentProfile.removeChild(childs.item(index)); } } childs = currentDelta.getChildNodes(); max = childs.getLength(); for(index = 0; index < max; index++) { if (childs.item(index).getNodeType() == Node.TEXT_NODE) { currentProfile.appendChild(currentProfile.getOwnerDocument() .createTextNode(childs.item(index).getNodeValue())); } } } } } else { profile.appendChild(profile.getOwnerDocument().importNode(currentDelta, true)); } } } } } 1.1 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/components/DefaultFormManager.java Index: DefaultFormManager.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 [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.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.cocoon.ProcessingException; import org.apache.cocoon.components.RequestLifecycleComponent; 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 * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id: DefaultFormManager.java,v 1.1 2003/05/04 20:19:41 cziegeler Exp $ */ public final class DefaultFormManager extends AbstractLogEnabled implements Composable, Component, Recomposable, Recyclable, FormManager, RequestLifecycleComponent { /** 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"; /** 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 */ public void compose(ComponentManager manager) { this.manager = manager; } /** * 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) throws ProcessingException { ContextManager contextManager = null; try { contextManager = (ContextManager) this.manager.lookup(ContextManager.ROLE); return contextManager.getContext( name ); } catch (ComponentException ce ) { throw new ProcessingException("Unable to lookup context manager.", ce); } finally { this.manager.release( (Component) contextManager); } } private DocumentFragment getContextFragment(String context, String path) throws ProcessingException { SessionManager sessionManager = null; try { sessionManager = (SessionManager) this.manager.lookup(SessionManager.ROLE); return sessionManager.getContextFragment( context, path ); } catch (ComponentException ce ) { throw new ProcessingException("Unable to lookup session manager.", ce); } finally { this.manager.release( (Component) sessionManager); } } /** * Register input field and return the current value of the field. * This is a private method and should not be invoked directly. */ public DocumentFragment registerInputField(String contextName, String path, String name, String formName) throws ProcessingException { // synchronized if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("BEGIN registerInputField context="+contextName+", path="+path+", name="+name+", formName="+formName); } // test arguments if (contextName == null) { throw new ProcessingException("SessionManager.registerInputField: Context Name is required"); } if (path == null) { throw new ProcessingException("SessionManager.registerInputField: Path is required"); } if (name == null) { throw new ProcessingException("SessionManager.registerInputField: Name is required"); } if (formName == null) { throw new ProcessingException("SessionManager.registerInputField: Form is required"); } DocumentFragment value = null; SessionContext context = this.getContext(contextName); if (context == null) { throw new ProcessingException("SessionManager.registerInputField: Context not found " + contextName); } Session session = this.request.getSession(false); if (session == null) { throw new ProcessingException("SessionManager.registerInputField: Session is required for context " + contextName); } synchronized(session) { Map inputFields = (Map)session.getAttribute(ATTRIBUTE_INPUTXML_STORAGE); if (inputFields == null) { inputFields = new HashMap(10); session.setAttribute(ATTRIBUTE_INPUTXML_STORAGE, inputFields); } inputFields.put(name, new Object[] {context, path, formName}); value = context.getXML(path); } if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("END registerInputField value="+value); } return value; } /** * Process all input fields. * The fields are removed even if the request did not contain * any values. * This is a private method and should not be invoked directly. */ private void processInputFields() throws ProcessingException { // synchronized if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("BEGIN processInputFields"); } final String formName = this.request.getParameter(SessionConstants.SESSION_FORM_PARAMETER); if ( null != formName ) { final Session session = this.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(); String currentKey; Object[] contextAndPath; while (keys.hasMoreElements() == true) { currentKey = (String)keys.nextElement(); if (inputFields.containsKey(currentKey) == true) { 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)); } } } } // inputFields.clear(); } } } if (this.getLogger().isDebugEnabled() ) { this.getLogger().debug("END processInputFields"); } } } 1.4 +1 -5 cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/AuthenticationConstants.java Index: AuthenticationConstants.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/AuthenticationConstants.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AuthenticationConstants.java 27 Apr 2003 14:45:04 -0000 1.3 +++ AuthenticationConstants.java 4 May 2003 20:19:42 -0000 1.4 @@ -59,10 +59,6 @@ */ public interface AuthenticationConstants { - /** The name of the session attribute storing the context - * FIXME - Remove me*/ - String SESSION_ATTRIBUTE_CONTEXT_NAME = "org.apache.cocoon.webapps.authentication.SessionContext"; - /** The name of the authentication context. */ String SESSION_CONTEXT_NAME = "authentication"; 1.3 +37 -12 cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/AuthenticationManager.java 1.4 +2 -7 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/acting/SessionFormAction.java Index: SessionFormAction.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/acting/SessionFormAction.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SessionFormAction.java 27 Apr 2003 15:03:25 -0000 1.3 +++ SessionFormAction.java 4 May 2003 20:19:42 -0000 1.4 @@ -63,7 +63,6 @@ import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.environment.Session; import org.apache.cocoon.webapps.session.SessionConstants; -import org.apache.cocoon.webapps.session.components.SessionManager; import org.apache.cocoon.util.Tokenizer; import java.util.HashMap; @@ -142,12 +141,10 @@ Parameters parameters) throws Exception { Request req = ObjectModelHelper.getRequest(objectModel); - SessionManager sessionManager = null; // read local settings try { - sessionManager = (SessionManager)this.manager.lookup(SessionManager.ROLE); - Session session = sessionManager.getSession(true); + Session session = req.getSession(true); Configuration conf = (Configuration)session.getAttribute( req.getParameter(SessionConstants.SESSION_FORM_PARAMETER)); @@ -337,8 +334,6 @@ if (getLogger().isDebugEnabled()) { getLogger().debug ("exception: ", ignore); } - } finally { - this.manager.release( sessionManager ); } return null; } 1.2 +4 -3 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/acting/SessionAction.java Index: SessionAction.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/acting/SessionAction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SessionAction.java 9 Mar 2003 00:06:07 -0000 1.1 +++ SessionAction.java 4 May 2003 20:19:42 -0000 1.2 @@ -52,6 +52,7 @@ 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; @@ -59,7 +60,7 @@ import org.apache.cocoon.acting.ComposerAction; import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.environment.SourceResolver; -import org.apache.cocoon.webapps.session.components.SessionManager; +import org.apache.cocoon.webapps.session.SessionManager; /** * This action creates and terminates a session. @@ -98,7 +99,7 @@ } catch (ComponentException ce) { throw new ProcessingException("Error during lookup of sessionManager component.", ce); } finally { - this.manager.release( sessionManager ); + this.manager.release( (Component)sessionManager ); } return EMPTY_MAP; 1.2 +26 -27 cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/generation/ConfigurationGenerator.java Index: ConfigurationGenerator.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/generation/ConfigurationGenerator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ConfigurationGenerator.java 9 Mar 2003 00:02:21 -0000 1.1 +++ ConfigurationGenerator.java 4 May 2003 20:19:42 -0000 1.2 @@ -53,8 +53,8 @@ import java.io.IOException; import java.util.Enumeration; +import java.util.Map; -import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.cocoon.ProcessingException; @@ -64,7 +64,9 @@ import org.apache.cocoon.environment.Response; import org.apache.cocoon.environment.Session; import org.apache.cocoon.generation.ComposerGenerator; -import org.apache.cocoon.webapps.authentication.components.AuthenticationManager; +import org.apache.cocoon.webapps.authentication.context.AuthenticationContext; +import org.apache.cocoon.webapps.authentication.user.RequestState; +import org.apache.cocoon.webapps.authentication.user.UserHandler; import org.apache.cocoon.xml.IncludeXMLConsumer; import org.apache.cocoon.xml.XMLConsumer; import org.apache.cocoon.xml.XMLUtils; @@ -104,25 +106,22 @@ throws IOException, SAXException, ProcessingException { this.xmlConsumer.startDocument(); - AuthenticationManager authManager = null; - try { - authManager = (AuthenticationManager)this.manager.lookup(AuthenticationManager.ROLE); - - if (authManager.isAuthenticated() == true) { - Configuration conf = authManager.getModuleConfiguration("single-role-user-management"); + RequestState state = RequestState.getState(); + if ( state != null ) { + try { + UserHandler userhandler = state.getHandler(); + + Configuration conf = state.getModuleConfiguration("single-role-user-management"); if (conf == null) { throw new ProcessingException("Module configuration 'single-role-user-management' for authentication user management generator not found."); } UserManagementHandler handler = new UserManagementHandler(conf, - authManager.getApplicationName()); - this.showConfiguration(this.xmlConsumer, this.source, handler, authManager); + state.getApplicationName()); + this.showConfiguration(this.xmlConsumer, this.source, handler, userhandler.getContext()); + + } catch (ConfigurationException ex) { + throw new ProcessingException("ConfigurationException: " + ex, ex); } - } catch (ConfigurationException ex) { - throw new ProcessingException("ConfigurationException: " + ex, ex); - } catch (ComponentException ex) { - throw new ProcessingException("ComponentException: " + ex, ex); - } finally { - this.manager.release( authManager ); } this.xmlConsumer.endDocument(); @@ -138,7 +137,7 @@ public void showConfiguration(XMLConsumer consumer, String src, UserManagementHandler handler, - AuthenticationManager authManager) + AuthenticationContext context) throws ProcessingException, SAXException, IOException { // synchronized if (this.getLogger().isDebugEnabled() == true) { @@ -235,9 +234,9 @@ String user; if (isAdmin == false) { - SourceParameters pars = authManager.createParameters(null); - id = pars.getParameter("ID", null); - role = pars.getParameter("role", null); + Map pars = context.getContextInfo(); + id = (String) pars.get("ID"); + role = (String) pars.get("role"); user = "old"; } else { role = request.getParameter(REQ_PARAMETER_ROLE); @@ -292,9 +291,9 @@ String id; if (isAdmin == false) { - SourceParameters pars = authManager.createParameters(null); - id = pars.getParameter("ID", null); - role = pars.getParameter("role", null); + Map pars = context.getContextInfo(); + id = (String) pars.get("ID"); + role = (String) pars.get("role"); } else { role = request.getParameter(REQ_PARAMETER_ROLE); id = request.getParameter(REQ_PARAMETER_ID); @@ -335,9 +334,9 @@ String id; if (isAdmin == false) { - SourceParameters pars = authManager.createParameters(null); - id = pars.getParameter("ID", null); - role = pars.getParameter("role", null); + Map pars = context.getContextInfo(); + id = (String) pars.get("ID"); + role = (String) pars.get("role"); } else { role = request.getParameter(REQ_PARAMETER_ROLE); id = request.getParameter(REQ_PARAMETER_ID); 1.1 cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/selection/MediaSelector.java Index: MediaSelector.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 [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.webapps.session.selection; import java.util.Map; import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.component.Composable; import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.selection.Selector; import org.apache.cocoon.webapps.session.MediaManager; /** * This selector uses the media management. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id: MediaSelector.java,v 1.1 2003/05/04 20:19:42 cziegeler Exp $ */ public final class MediaSelector implements Composable, Selector, ThreadSafe { private ComponentManager manager; /** * Composable */ public void compose(ComponentManager manager) { this.manager = manager; } /** * Selector */ public boolean select (String expression, Map objectModel, Parameters parameters) { MediaManager mediaManager = null; boolean result; try { mediaManager = (MediaManager) this.manager.lookup( MediaManager.ROLE ); result = mediaManager.testMedia(expression); } catch (Exception local) { // ignore me result = false; } finally { this.manager.release( (Component)mediaManager ); } return result; } } 1.17 +3 -4 cocoon-2.1/status.xml Index: status.xml =================================================================== RCS file: /home/cvs/cocoon-2.1/status.xml,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- status.xml 3 May 2003 18:34:41 -0000 1.16 +++ status.xml 4 May 2003 20:19:42 -0000 1.17 @@ -55,10 +55,6 @@ Test, test, test :-) </action> - <action context="code" assigned-to="CZ"> - Redesign the SitemapConfigurable handling. - </action> - <action context="docs" assigned-to="open"> For 2.1: Attend to any high+ issues in the <link href="plan/todo-doc.html">Documentation To Do List</link> @@ -199,6 +195,9 @@ <changes> <release version="@version@" date="@date@"> + <action dev="CZ" type="update"> + Redesign/modularizing the authentication and session framework. + </action> <action dev="GR" type="add" fixes-bug="19206" due-to="Miles Elam" due-to-email="[EMAIL PROTECTED]"> Added 304 support to cacheable pipelines </action> 1.2 +12 -2 cocoon-2.1/src/blocks/portal-fw/java/org/apache/cocoon/webapps/portal/generation/PortalGenerator.java Index: PortalGenerator.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/portal-fw/java/org/apache/cocoon/webapps/portal/generation/PortalGenerator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PortalGenerator.java 9 Mar 2003 00:05:19 -0000 1.1 +++ PortalGenerator.java 4 May 2003 20:19:42 -0000 1.2 @@ -52,12 +52,14 @@ import java.io.IOException; +import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.component.ComponentException; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Request; import org.apache.cocoon.generation.ComposerGenerator; import org.apache.cocoon.webapps.portal.components.PortalManager; +import org.apache.cocoon.webapps.session.FormManager; import org.xml.sax.SAXException; /** @@ -77,8 +79,16 @@ portal = (PortalManager) this.manager.lookup(PortalManager.ROLE); this.xmlConsumer.startDocument(); - Request request = ObjectModelHelper.getRequest(this.objectModel); + final Request request = ObjectModelHelper.getRequest(this.objectModel); if (request.getSession(false) != null) { + // FIXME - workaround for form handling + FormManager formManager = null; + try { + formManager = (FormManager)this.manager.lookup(FormManager.ROLE); + // no need do to anything here :) + } finally { + this.manager.release( (Component)formManager); + } portal.showPortal(this.xmlConsumer, false, false); } this.xmlConsumer.endDocument();