nicolaken 2002/12/13 07:46:03 Modified: . changes.xml module.xml Added: src/blocks/samples/java/org/apache/cocoon/samples/parentcm Configurator.java Generator.java ParentComponentManager.java Time.java TimeComponent.java src/blocks/samples/samples notyet.txt src/blocks/samples/conf samples.xmap samples.xpipe src/blocks/samples/java/org/apache/cocoon/samples/xmlform UsageFeedbackAction.java UserBean.java WizardAction.java Log: Moved the sample classes and confs to the samples block. Revision Changes Path 1.304 +4 -1 xml-cocoon2/changes.xml Index: changes.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/changes.xml,v retrieving revision 1.303 retrieving revision 1.304 diff -u -r1.303 -r1.304 --- changes.xml 6 Dec 2002 14:50:15 -0000 1.303 +++ changes.xml 13 Dec 2002 15:46:02 -0000 1.304 @@ -40,6 +40,9 @@ </devs> <release version="@version@" date="@date@"> + <action dev="NKB" type="update"> + Moved the sample classes and confs to the samples block. + </action> <action dev="TC" type="update"> Cleaned up the esql logicsheet and helper classes. Created classes for db specific stuff. 1.20 +19 -0 xml-cocoon2/module.xml Index: module.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/module.xml,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- module.xml 3 Dec 2002 17:08:35 -0000 1.19 +++ module.xml 13 Dec 2002 15:46:02 -0000 1.20 @@ -371,6 +371,25 @@ </project> + <project name="samples-block"> + <package>org.apache.cocoon</package> + + <ant target="block"> + <property name="block-name" value="samples"/> + </ant> + + <depend project="xml-cocoon2"/> + + <work nested="tools/anttasks"/> + <home nested="build/cocoon"/> + + <jar name="samples-block.jar"/> + + <nag from="Nicola Ken Barozzi <[EMAIL PROTECTED]>" + to="[EMAIL PROTECTED]"/> + + </project> + <!-- ******************************************** ******** COCOON SUPPLIED PROJECTS ******** 1.1 xml-cocoon2/src/blocks/samples/java/org/apache/cocoon/samples/parentcm/Configurator.java Index: Configurator.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.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 2002/12/13 15:46:02 nicolaken 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/blocks/samples/java/org/apache/cocoon/samples/parentcm/Generator.java Index: Generator.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.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 2002/12/13 15:46:02 nicolaken 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/blocks/samples/java/org/apache/cocoon/samples/parentcm/ParentComponentManager.java Index: ParentComponentManager.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.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 2002/12/13 15:46:02 nicolaken 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/blocks/samples/java/org/apache/cocoon/samples/parentcm/Time.java Index: Time.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.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 2002/12/13 15:46:02 nicolaken Exp $ */ public interface Time extends Component { String ROLE = Time.class.getName(); /** * Gets the current time. */ Date getTime (); } 1.1 xml-cocoon2/src/blocks/samples/java/org/apache/cocoon/samples/parentcm/TimeComponent.java Index: TimeComponent.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.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 2002/12/13 15:46:02 nicolaken Exp $ */ public class TimeComponent implements Component, Time, ThreadSafe { public Date getTime () { return new Date(); } } 1.1 xml-cocoon2/src/blocks/samples/samples/notyet.txt <<Binary file>> 1.1 xml-cocoon2/src/blocks/samples/conf/samples.xmap Index: samples.xmap =================================================================== <?xml version="1.0"?> <xmap xpath="/sitemap/components/generators" unless="generator[@name='parentcm']"> <map:generator name="parentcm" src="org.apache.cocoon.samples.parentcm.Generator"/> </xmap> 1.1 xml-cocoon2/src/blocks/samples/conf/samples.xpipe Index: samples.xpipe =================================================================== <?xml version="1.0"?> <samplesxpipe xpath="/sitemap/pipelines/pipeline[@id='optional']" unless="match[@pattern='parentcm']"> <!-- =============== Parent Component Manager ====================== --> <map:match pattern="parentcm"> <map:generate type="parentcm" src="{1}"/> <map:transform src="stylesheets/parentcm/time.xsl"/> <map:serialize/> </map:match> </samplesxpipe> 1.1 xml-cocoon2/src/blocks/samples/java/org/apache/cocoon/samples/xmlform/UsageFeedbackAction.java Index: UsageFeedbackAction.java =================================================================== /* * $Header: /home/cvs/xml-cocoon2/src/blocks/samples/java/org/apache/cocoon/samples/xmlform/UsageFeedbackAction.java,v 1.1 2002/12/13 15:46:02 nicolaken Exp $ * $Revision: 1.1 $ * $Date: 2002/12/13 15:46:02 $ * * ==================================================================== * 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/blocks/samples/java/org/apache/cocoon/samples/xmlform/UserBean.java Index: UserBean.java =================================================================== package org.apache.cocoon.samples.xmlform; import java.util.Set; import java.util.HashSet; import java.util.Map; import java.util.HashMap; import java.util.List; import java.util.ArrayList; import org.apache.avalon.framework.CascadingRuntimeException; import org.w3c.dom.*; import javax.xml.parsers.*; import javax.xml.transform.*; /** * * 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/blocks/samples/java/org/apache/cocoon/samples/xmlform/WizardAction.java Index: WizardAction.java =================================================================== /* * $Header: /home/cvs/xml-cocoon2/src/blocks/samples/java/org/apache/cocoon/samples/xmlform/WizardAction.java,v 1.1 2002/12/13 15:46:03 nicolaken Exp $ * $Revision: 1.1 $ * $Date: 2002/12/13 15:46:03 $ * * ==================================================================== * 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; // Java classes import java.util.Map; // Framework classes import org.apache.excalibur.source.Source; // Cocoon Form import org.apache.cocoon.acting.AbstractXMLFormAction; import org.apache.cocoon.components.xmlform.Form; import org.apache.cocoon.components.xmlform.FormListener; /** * 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]