stefano 2003/02/20 11:59:06 Added: src/samples/org/apache/cocoon/acting/modular TestAction.java src/samples/org/apache/cocoon/samples/flow User.java UserRegistry.java src/samples/org/apache/cocoon/samples/parentcm Configurator.java Generator.java ParentComponentManager.java Time.java TimeComponent.java src/samples/org/apache/cocoon/samples/xmlform UsageFeedbackAction.java UserBean.java WizardAction.java Log: moving code used in samples in their own location Revision Changes Path 1.1 xml-cocoon2/src/samples/org/apache/cocoon/acting/modular/TestAction.java Index: TestAction.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.acting.modular; import org.apache.avalon.framework.component.ComponentSelector; 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.parameters.Parameters; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.acting.ComposerAction; import org.apache.cocoon.components.modules.input.InputModule; import org.apache.cocoon.components.modules.output.OutputModule; import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.environment.SourceResolver; import java.util.Iterator; import java.util.Map; /** Demo action that uses componentized input / output layer. In order * to stop combinatorial explosion of actions, matchers, and selectors * they should instead use components to access their inputs and * outputs. Available components include request parameters, * attributes, headers, and session attributes. Which component to use * can be specified upon setup via "input-module" and * "output-module" tags through the name attribute. * * This particular action copies all available parameters obtained * from the input component to the output component or, if a specific * parameter is specified through parameter-name, just one parameter. */ public class TestAction extends ComposerAction implements Configurable, ThreadSafe { String INPUT_MODULE_ROLE = InputModule.ROLE; String OUTPUT_MODULE_ROLE = OutputModule.ROLE; String INPUT_MODULE_SELECTOR = INPUT_MODULE_ROLE+"Selector"; String OUTPUT_MODULE_SELECTOR = OUTPUT_MODULE_ROLE+"Selector"; Configuration inputConf = null; Configuration outputConf = null; String inputName = null; String outputName = null; String defaultParameterName = null; boolean useGetValues = false; String inputHint = "request-param"; // default to request parameters String outputHint = "request-attr"; // default to request attributes public void configure(Configuration config) throws ConfigurationException { this.inputConf = config.getChild("input-module"); this.inputName = this.inputConf.getAttribute("name", this.inputHint); this.outputConf = config.getChild("output-module"); this.outputName = this.outputConf.getAttribute("name", this.outputHint); this.defaultParameterName = config.getChild("parameter-name").getValue(null); this.useGetValues = config.getChild("use-getValues").getValueAsBoolean(this.useGetValues); } public Map act( Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters param ) throws Exception { // general setup String parameterName = param.getParameter("parameter-name",this.defaultParameterName); boolean useGetValues = param.getParameterAsBoolean("use-getValues",this.useGetValues); InputModule input = null; OutputModule output = null; ComponentSelector inputSelector = null; ComponentSelector outputSelector = null; try { if (getLogger().isDebugEnabled()) getLogger().debug("start..."); // obtain input and output components inputSelector=(ComponentSelector) this.manager.lookup(INPUT_MODULE_SELECTOR); if (inputName != null && inputSelector != null && inputSelector.hasComponent(inputName)){ input = (InputModule) inputSelector.select(inputName); } outputSelector=(ComponentSelector) this.manager.lookup(OUTPUT_MODULE_SELECTOR); if (outputName != null && outputSelector != null && outputSelector.hasComponent(outputName)){ output = (OutputModule) outputSelector.select(outputName); } if (input != null && output != null) { if (getLogger().isDebugEnabled()) getLogger().debug("got input and output modules"); // do something if (parameterName == null) { if (getLogger().isDebugEnabled()) getLogger().debug("reading all parameter values"); // for a test, read all parameters from input and write them to outout // get names first, then (one) value per name Iterator iter = input.getAttributeNames(this.inputConf,objectModel); while (iter.hasNext()) { parameterName = (String) iter.next(); Object value = input.getAttribute(parameterName, this.inputConf, objectModel); output.setAttribute(this.outputConf, objectModel, parameterName, value); if (getLogger().isDebugEnabled()) getLogger().debug("["+parameterName+"] = ["+value+"]"); } // ------------------------------------------------------------------------ } else { if (useGetValues) { // get all existing values Object[] value = input.getAttributeValues(parameterName, this.inputConf, objectModel); output.setAttribute(this.outputConf, objectModel, parameterName, value); if (getLogger().isDebugEnabled()) for (int i=0; i<value.length; i++) getLogger().debug("["+parameterName+"["+i+"]] = ["+value[i]+"]"); // ------------------------------------------------------------------------ } else { // get just one parameter value if (getLogger().isDebugEnabled()) getLogger().debug("reading parameter values for "+parameterName); Object value = input.getAttribute(parameterName, this.inputConf, objectModel); output.setAttribute(this.outputConf, objectModel, parameterName, value); if (getLogger().isDebugEnabled()) getLogger().debug("["+parameterName+"] = ["+value+"]"); // ------------------------------------------------------------------------ } } output.commit(this.outputConf,objectModel); if (getLogger().isDebugEnabled()) getLogger().debug("done commit"); // done } } catch (Exception e) { throw e; } finally { // release components if (getLogger().isDebugEnabled()) getLogger().debug("releasing components"); if (outputSelector != null) { if (output != null) outputSelector.release(output); this.manager.release(outputSelector); } if (inputSelector != null) { if (input != null) inputSelector.release(input); this.manager.release(inputSelector); } if (getLogger().isDebugEnabled()) getLogger().debug("... end"); } return EMPTY_MAP; } } 1.1 xml-cocoon2/src/samples/org/apache/cocoon/samples/flow/User.java Index: User.java =================================================================== /* User.java Representation of a user. Author: Ovidiu Predescu <[EMAIL PROTECTED]> Date: August 28, 2002 */ package org.apache.cocoon.samples.flow.prefs; public class User { String login; String password; String firstName; String lastName; String email; public User(String login, String password, String firstName, String lastName, String email) { this.login = login; this.password = password; this.firstName = firstName; this.lastName = lastName; this.email = email; } public int hashCode() { return login.hashCode(); } public boolean equals(Object obj) { User anotherUser = (User)obj; return anotherUser.login.equals(login); } /** * Sets the value of login * * @param argLogin Value to assign to this.login */ public void setLogin(String argLogin) { this.login = argLogin; } /** * Gets the value of login * * @return the value of login */ public String getLogin() { return this.login; } /** * Gets the value of password * * @return the value of password */ public String getPassword() { return this.password; } /** * Sets the value of password * * @param argPassword Value to assign to this.password */ public void setPassword(String argPassword) { this.password = argPassword; } /** * Gets the value of firstName * * @return the value of firstName */ public String getFirstName() { return this.firstName; } /** * Sets the value of firstName * * @param argFirstName Value to assign to this.firstName */ public void setFirstName(String argFirstName) { this.firstName = argFirstName; } /** * Gets the value of lastName * * @return the value of lastName */ public String getLastName() { return this.lastName; } /** * Sets the value of lastName * * @param argLastName Value to assign to this.lastName */ public void setLastName(String argLastName) { this.lastName = argLastName; } /** * Gets the value of email * * @return the value of email */ public String getEmail() { return this.email; } /** * Sets the value of email * * @param argEmail Value to assign to this.email */ public void setEmail(String argEmail) { this.email = argEmail; } } 1.1 xml-cocoon2/src/samples/org/apache/cocoon/samples/flow/UserRegistry.java Index: UserRegistry.java =================================================================== /* UserRegistry.java Maintains a list of registered users. Author: Ovidiu Predescu <[EMAIL PROTECTED]> Date: August 28, 2002 */ package org.apache.cocoon.samples.flow.prefs; import java.util.HashMap; import java.util.Map; /** * Maintains a list of registered users. This is a very simple class, * there is no persistence of the users, but such thing should be easy * to add. * * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a> * @since August 28, 2002 */ public class UserRegistry { static UserRegistry userRegistry = new UserRegistry(); Map registeredUsers = new HashMap(); public static UserRegistry getUserRegistry() { return userRegistry; } protected UserRegistry() { } public synchronized boolean addUser(User user) { if (registeredUsers.containsKey(user.getLogin())) return false; registeredUsers.put(user.getLogin(), user); return true; } public boolean removeUser(User user) { return registeredUsers.remove(user) != null; } /** * Checks is a particular login name is taken or not. * * @param loginName a <code>String</code> value * @return true if <code>loginName</code> is taken, false otherwise */ public boolean isLoginNameTaken(String loginName) { return registeredUsers.get(loginName) != null; } /** * Returns the {@link User} object which represents an user. Note that * we require a password to be present, to avoid presenting private * information to anyone. * * @param loginName a <code>String</code> value * @param password a <code>String</code> value * @return an <code>User</code> value */ public User getUserWithLogin(String loginName, String password) { User user = (User)registeredUsers.get(loginName); if (user == null) return null; return password.equals(user.getPassword()) ? user : null; } } 1.1 xml-cocoon2/src/samples/org/apache/cocoon/samples/parentcm/Configurator.java Index: Configurator.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.samples.parentcm; import org.apache.avalon.excalibur.naming.memory.MemoryInitialContextFactory; import org.apache.avalon.framework.configuration.DefaultConfiguration; import javax.naming.Context; import javax.naming.InitialContext; import java.util.Hashtable; /** * This class sets up the configuration used by the ParentComponentManager sample. * The class also holds a reference to the initial context in which the configuration * is available. * <p> * The configuration is bound to <code>org/apache/cocoon/samples/parentcm/ParentCMConfiguration</code>. * * @author <a href="mailto:[EMAIL PROTECTED]">Leo Sutic</a> * @version CVS $Id: Configurator.java,v 1.1 2003/02/20 19:59:06 stefano Exp $ */ public class Configurator { /** * The Excalibur in-memory JNDI directory. Since the directory doesn't * provide any persistence we must keep a reference to the initial context * as a static member to avoid passing it around. */ public static Context initialContext = null; static { try { // // Create a new role. // DefaultConfiguration config = new DefaultConfiguration("roles", ""); DefaultConfiguration timeComponent = new DefaultConfiguration("role", "roles"); timeComponent.addAttribute("name", Time.ROLE); timeComponent.addAttribute("default-class", TimeComponent.class.getName()); timeComponent.addAttribute("shorthand", "samples-parentcm-time"); config.addChild(timeComponent); // // Bind it - get an initial context. // Hashtable environment = new Hashtable(); environment.put(Context.INITIAL_CONTEXT_FACTORY, MemoryInitialContextFactory.class.getName()); initialContext = new InitialContext(environment); // // Create subcontexts and bind the configuration. // Context ctx = initialContext.createSubcontext("org"); ctx = ctx.createSubcontext("apache"); ctx = ctx.createSubcontext("cocoon"); ctx = ctx.createSubcontext("samples"); ctx = ctx.createSubcontext("parentcm"); ctx.rebind("ParentCMConfiguration", config); } catch (Exception e) { e.printStackTrace(System.err); } } } 1.1 xml-cocoon2/src/samples/org/apache/cocoon/samples/parentcm/Generator.java Index: Generator.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.samples.parentcm; import org.apache.avalon.excalibur.pool.Poolable; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.generation.ComposerGenerator; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; import java.io.IOException; import java.util.Date; import java.util.Map; /** * Generator for the parent component manager sample. The generator outputs * a single tag <code><time><i>current time</i></time></code>. * Where <code><i>current time</i></code> is the current time as obtained from the * <code>Time</code> component. * * @author <a href="mailto:[EMAIL PROTECTED]">Leo Sutic</a> * @version CVS $Id: Generator.java,v 1.1 2003/02/20 19:59:06 stefano Exp $ */ public class Generator extends ComposerGenerator implements Poolable { /** * Current time. */ private Date time; /** * Looks up a <code>Time</code> component and obtains the current time. */ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException { Time timeGiver = null; try { timeGiver = (Time) manager.lookup(Time.ROLE); this.time = timeGiver.getTime (); } catch (ComponentException ce) { throw new ProcessingException ("Could not obtain current time.", ce); } finally { manager.release(timeGiver); } } /** * Generate XML data. */ public void generate() throws SAXException, ProcessingException { AttributesImpl emptyAttributes = new AttributesImpl(); contentHandler.startDocument(); contentHandler.startElement("", "time", "time", emptyAttributes); char[] text = this.time.toString().toCharArray(); contentHandler.characters(text, 0, text.length); contentHandler.endElement("", "time", "time"); contentHandler.endDocument(); } /** * Prepare this object for another cycle. */ public void recycle () { this.time = null; } } 1.1 xml-cocoon2/src/samples/org/apache/cocoon/samples/parentcm/ParentComponentManager.java Index: ParentComponentManager.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.samples.parentcm; import org.apache.avalon.excalibur.component.ExcaliburComponentManager; import org.apache.avalon.excalibur.naming.memory.MemoryInitialContextFactory; import org.apache.avalon.framework.activity.Initializable; 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.context.DefaultContext; import org.apache.avalon.framework.logger.LogEnabled; import org.apache.avalon.framework.logger.Logger; import javax.naming.Context; import java.util.Hashtable; /** * A sample parent component manager. This manager will lookup the configuration object * given by the initialization parameter in JNDI, use it to configure an ExcaliburComponentManager * and delegate any requests to it. * * @author <a href="mailto:[EMAIL PROTECTED]">Leo Sutic</a> * @version CVS $Id: ParentComponentManager.java,v 1.1 2003/02/20 19:59:06 stefano Exp $ */ public class ParentComponentManager implements ComponentManager, LogEnabled, Initializable { /** * Our logger. */ private Logger logger; /** * The JNDI name where the component manager configuration can be found. */ private final String jndiName; /** * The delegate that will be configured and provide the * functionality for this component manager. */ private final ExcaliburComponentManager delegate; public ParentComponentManager(final String jndiName) { this.jndiName = jndiName; // Initialize it here so we can let it be final. this.delegate = new ExcaliburComponentManager(); } public boolean hasComponent(final String role) { return delegate.hasComponent(role); } /** * Initializes the CM by looking up the configuration object and using it to * configure the delegate. */ public void initialize() throws Exception { this.logger.debug("Looking up component manager configuration at : " + this.jndiName); Hashtable environment = new Hashtable(); environment.put(Context.INITIAL_CONTEXT_FACTORY, MemoryInitialContextFactory.class.getName()); // // Yes, this is cheating, but the Excalibur in-memory naming provider // is transient. That is, it doesn't store objects persistently and // is more like a HashMap. // // Should be: // Context initialContext = new InitialContext(environment); // Context initialContext = Configurator.initialContext; Configuration config = (Configuration) initialContext.lookup(this.jndiName); // We ignore the setRoleManager call, as ExcaliburComponentManager handles that // in configure(). this.delegate.enableLogging(logger); this.delegate.contextualize(new DefaultContext()); this.delegate.configure(config); this.delegate.initialize(); this.logger.debug("Component manager successfully initialized."); } public Component lookup(final String role) throws ComponentException { return this.delegate.lookup(role); } public void release(final Component component) { this.delegate.release(component); } /** * Provide component with a logger. * * @param logger the logger */ public void enableLogging(Logger logger) { this.logger = logger; } } 1.1 xml-cocoon2/src/samples/org/apache/cocoon/samples/parentcm/Time.java Index: Time.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.samples.parentcm; import org.apache.avalon.framework.component.Component; import java.util.Date; /** * Interface for a simple time-keeping component. * @author ? * @version CVS $Id: Time.java,v 1.1 2003/02/20 19:59:06 stefano Exp $ */ public interface Time extends Component { String ROLE = Time.class.getName(); /** * Gets the current time. */ Date getTime (); } 1.1 xml-cocoon2/src/samples/org/apache/cocoon/samples/parentcm/TimeComponent.java Index: TimeComponent.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.samples.parentcm; import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.thread.ThreadSafe; import java.util.Date; /** * Implementing class for the parent component manager sample's * <code>org.apache.cocoon.samples.parentcm.Time</code> component. * @author ? * @version CVS $Id: TimeComponent.java,v 1.1 2003/02/20 19:59:06 stefano Exp $ */ public class TimeComponent implements Component, Time, ThreadSafe { public Date getTime () { return new Date(); } } 1.1 xml-cocoon2/src/samples/org/apache/cocoon/samples/xmlform/UsageFeedbackAction.java Index: UsageFeedbackAction.java =================================================================== /* * $Header: /home/cvs/xml-cocoon2/src/samples/org/apache/cocoon/samples/xmlform/UsageFeedbackAction.java,v 1.1 2003/02/20 19:59:06 stefano Exp $ * $Revision: 1.1 $ * $Date: 2003/02/20 19:59:06 $ * * ==================================================================== * The Apache Software License, Version 1.1 * * * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, 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 acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", 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 names without prior written * permission of the Apache Group. * * 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 (INCLUDING, 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 based on software copyright (c) 2001, Plotnix, Inc, * <http://www.plotnix.com/>. * For more information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.cocoon.samples.xmlform; import java.util.Map; import org.apache.cocoon.acting.AbstractXMLFormAction; /** * This action implements a REST web service * * @author Ivelin Ivanov <[EMAIL PROTECTED]> */ public class UsageFeedbackAction extends AbstractXMLFormAction { // Web Service Response names final String SERVICE_RESPONSE_OK = "ok"; final String SERVICE_RESPONSE_ERROR = "error"; public Map perform () { // When form-view is not provided, // only data format validation is performed during population // but not consequetive data content validation (i.e. no Schematron validation) // Therefore, we will validate "manually" getForm().validate(); if ( getForm().getViolations () != null ) { return page( SERVICE_RESPONSE_ERROR ); } else { return page( SERVICE_RESPONSE_OK ); } } } 1.1 xml-cocoon2/src/samples/org/apache/cocoon/samples/xmlform/UserBean.java Index: UserBean.java =================================================================== package org.apache.cocoon.samples.xmlform; import org.apache.avalon.framework.CascadingRuntimeException; import org.w3c.dom.*; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Set; /** * * A sample domain object used as a Form model. * Notice that it has mixed content: * JavaBean properties and * DOM Nodes, which are handled correctly by the * framework when referenced via XPath. * */ public class UserBean { private String fname = "Donald"; private String lname = "Duck"; private String email = "[EMAIL PROTECTED]"; private int age = 5; private int count = 1; private short numInstalls = 1; private String liveUrl = "http://"; private boolean publish = true; private List favorites = new ArrayList(); private List roles = new ArrayList(); private String hobbies[]; private HashMap allHobbies; private String notes = "<your notes here>"; private boolean hidden = false; private Node system; public UserBean () { initDomNode(); initRoles(); initFavorites(); initHobbies(); } public String getFirstName() { return fname; } public void setFirstName(String newName) { fname = newName; } public String getLastName() { return lname; } public void setLastName(String newName) { lname = newName; } public String getEmail() { return email; } public void setEmail(String newEmail) { email = newEmail; } public String getLiveUrl() { return liveUrl; } public void setLiveUrl( String newUrl ) { liveUrl = newUrl; } public int getAge() { return age; } public void setAge( int newAge ) { age = newAge; } public short getNumber() { return numInstalls; } public void setNumber( short num ) { numInstalls = num; } public boolean getPublish() { return publish; } public void setPublish( boolean newPublish ) { publish = newPublish; } public Node getSystem() { return system; } public void setSystem( Node newSystem ) { system = newSystem; } public boolean getHidden() { return hidden; } public void setHidden( boolean newHidden ) { hidden = newHidden; } public int getCount() { return count; } public void incrementCount() { count++; } public void initDomNode() { DOMImplementation impl; try { // Find the implementation DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(false); factory.setValidating ( false ); DocumentBuilder builder = factory.newDocumentBuilder(); impl = builder.getDOMImplementation(); } catch (Exception ex) { throw new CascadingRuntimeException("Failed to initialize DOM factory.", ex); } // initialize system as dom node Document doc = impl.createDocument( null, "XMLForm_Wizard_System_Node", null); Node rootElement = doc.getDocumentElement(); Node os = doc.createElement ( "os" ); Text text = doc.createTextNode( "Linux" ); os.appendChild(text); rootElement.appendChild( os ); Node processor = doc.createElement ( "processor" ); text = doc.createTextNode( "p4" ); processor.appendChild(text); rootElement.appendChild( processor ); Attr ram = doc.createAttribute ( "ram" ); ram.setValue ( "512" ); NamedNodeMap nmap = rootElement.getAttributes(); nmap.setNamedItem ( ram ); Node servletEngine = doc.createElement ( "servletEngine" ); text = doc.createTextNode( "Tomcat" ); servletEngine.appendChild(text); rootElement.appendChild( servletEngine ); Node javaVersion = doc.createElement ( "javaVersion" ); text = doc.createTextNode( "1.3" ); javaVersion.appendChild(text); rootElement.appendChild( javaVersion ); system = rootElement; } public List getRole() { return roles; } public void setRole( List newRoles ) { roles = newRoles; } public String[] getHobby() { return hobbies; } public void setHobby( String[] newHobbies ) { hobbies = newHobbies; } public Set getAllHobbies() { return allHobbies.entrySet(); } public List getFavorite() { return favorites; } public void setFavorite( List newFavorites ) { favorites = newFavorites; } public String getNotes() { return notes; } public void setNotes( String newNotes ) { notes = newNotes; } public void initRoles() { roles = new ArrayList(); } public void initHobbies() { hobbies = new String[] {"swim", "movies", "ski", "gym", "soccer"}; // initialize the reference list of all hobbies allHobbies = new HashMap(); allHobbies.put( "swim", "Swimming" ); allHobbies.put( "gym", "Body Building" ); allHobbies.put( "ski", "Skiing" ); allHobbies.put( "run", "Running" ); allHobbies.put( "football", "Football" ); allHobbies.put( "read", "Reading" ); allHobbies.put( "write", "Writing" ); allHobbies.put( "soccer", "Soccer" ); allHobbies.put( "blog", "Blogging" ); } public void initFavorites() { favorites.add( "http://xml.apache.org/cocoon" ); favorites.add( "http://jakarta.apache.org" ); favorites.add( "http://www.google.com" ); favorites.add( "http://www.slashdot.org" ); favorites.add( "http://www.yahoo.com" ); } } 1.1 xml-cocoon2/src/samples/org/apache/cocoon/samples/xmlform/WizardAction.java Index: WizardAction.java =================================================================== /* * $Header: /home/cvs/xml-cocoon2/src/samples/org/apache/cocoon/samples/xmlform/WizardAction.java,v 1.1 2003/02/20 19:59:06 stefano Exp $ * $Revision: 1.1 $ * $Date: 2003/02/20 19:59:06 $ * * ==================================================================== * The Apache Software License, Version 1.1 * * * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, 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 acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", 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 names without prior written * permission of the Apache Group. * * 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 (INCLUDING, 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 based on software copyright (c) 2001, Plotnix, Inc, * <http://www.plotnix.com/>. * For more information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.cocoon.samples.xmlform; import org.apache.cocoon.acting.AbstractXMLFormAction; import org.apache.cocoon.components.xmlform.Form; import org.apache.cocoon.components.xmlform.FormListener; import java.util.Map; /** * This action demonstrates * a relatively complex form handling scenario. * * @author Ivelin Ivanov <[EMAIL PROTECTED]> */ public class WizardAction extends AbstractXMLFormAction implements FormListener { // different form views // participating in the wizard final String VIEW_START = "start"; final String VIEW_USERID = "userIdentity"; final String VIEW_DEPLOYMENT = "deployment"; final String VIEW_SYSTEM = "system"; final String VIEW_CONFIRM = "confirm"; final String VIEW_END = "end"; // action commands used in the wizard final String CMD_START = "start"; final String CMD_NEXT = "next"; final String CMD_PREV = "prev"; /** * The first callback method which is called * when an action is invoked. * * It is called before population and validation. * * * @return null if the Action is prepared to continue - the normal case. * an objectModel map which will be immediately returned by the action. * * This method is a good place to handle buttons with Cancel * kind of semantics. For example * <pre>if getCommand().equals("Cancel") return page("input");</pre> * */ protected Map prepare() { // following is navigation logic for the GUI version if ( getCommand() == null ) { // initial link return page( VIEW_START ); } else if ( getCommand().equals( CMD_START ) ) { // reset workflow state if necessary // remove old form Form.remove( getObjectModel(), getFormId() ); // create new form getForm(); return page( VIEW_USERID ); } // safe lookup, side effects free else if ( Form.lookup ( getObjectModel(), getFormId() ) == null) { // session expired return page( VIEW_START ); } // nothing special // continue with form population; return super.PREPARE_RESULT_CONTINUE; } /** * Invoked after form population * * Responsible for implementing the state machine * of the flow control processing * a single form page or a form wizard. * * Semanticly similar to Struts Action.perform() * * Take appropriate action based on the command * */ public Map perform () { // get the actual model which this Form encapsulates // and apply additional buziness logic to the model UserBean jBean = (UserBean) getForm().getModel(); jBean.incrementCount(); // set the page flow control parameter // according to the validation result if ( getCommand().equals( CMD_NEXT ) && getForm().getViolations () != null ) { // errors, back to the same page return page( getFormView() ); } else { // validation passed // continue with flow control // clear validation left overs in case the user // did not press the Next button getForm().clearViolations(); // get the user submitted command (through a submit button) String command = getCommand(); // get the form view which was submitted String formView = getFormView(); // apply state machine (flow control) rules if ( formView.equals ( VIEW_USERID ) ) { if ( command.equals( CMD_NEXT ) ) { return page( VIEW_DEPLOYMENT ); } } else if ( formView.equals ( VIEW_DEPLOYMENT ) ) { if ( command.equals( CMD_NEXT ) ) { return page( VIEW_SYSTEM ); } else if( command.equals( CMD_PREV ) ) return page( VIEW_USERID ); } else if ( formView.equals ( VIEW_SYSTEM ) ) { if ( command.equals( CMD_NEXT ) ) { return page( VIEW_CONFIRM ); } else if( command.equals( CMD_PREV ) ) return page( VIEW_DEPLOYMENT ); } else if ( formView.equals ( VIEW_CONFIRM ) ) { if ( command.equals( CMD_NEXT ) ) { Form.remove( getObjectModel(), getFormId() ); return page( VIEW_END ); } else if( command.equals( CMD_PREV ) ) return page( VIEW_SYSTEM ); } } // should never reach this statement return page( VIEW_START ); } /** * * FormListener callback * called in the beginning of Form.populate() * before population starts. * * This is the place to intialize the model for this request. * * This method should not handle unchecked check boxes * when the form is session scope, which is the most common case. * It should only do so, if the form is request scoped. * */ public void reset( Form form ) { // nothing to do in this case // unchecked check boxes are handled by the framework ! return; } /** * FormListener callback * * Invoked during Form.populate(); * * It is invoked before a request parameter is mapped to * an attribute of the form model. * * It is appropriate to use this method for filtering * custom request parameters which do not reference * the model. * * Another appropriate use of this method is for graceful filtering of invalid * values, in case that knowledge of the system state or * other circumstainces make the standard validation * insufficient. For example if a registering user choses a username which * is already taken - the check requires database transaction, which is * beyond the scope of document validating schemas. * Of course customized Validators can be implemented to do * this kind of domain specific validation * instead of using this method. * * * @return false if the request parameter should not be filtered. * true otherwise. */ public boolean filterRequestParameter (Form form, String parameterName) { // in this example we do not expect "custom" parameters return false; } }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]