cziegeler 2003/06/13 03:27:38
Modified: src/targets compile-build.xml . build.properties src/scratchpad/webapp/samples scratchpad-samples.xml Added: src/scratchpad/src/org/apache/cocoon/generation JellyGenerator.java src/scratchpad/mocks/org/apache/commons/jelly JellyContext.java XMLOutput.java JellyException.java src/scratchpad/webapp/samples/jelly sitemap.xmap test2.xml test1.xml Log: - Improving build system: scratchpad source is not copied anymore before compiling - Adding mocks directory to scratchpad - Adding JellyGenerator patch [#bug 15710] by [EMAIL PROTECTED] (Amal Sirvisetti) Revision Changes Path 1.1 cocoon-2.1/src/scratchpad/src/org/apache/cocoon/generation/JellyGenerator.java Index: JellyGenerator.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.generation; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; import java.util.Enumeration; import java.util.Map; import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.ResourceNotFoundException; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.SourceResolver; import org.apache.commons.jelly.JellyContext; import org.apache.commons.jelly.XMLOutput; import org.apache.excalibur.source.Source; import org.apache.excalibur.xml.sax.SAXParser; import org.xml.sax.InputSource; import org.xml.sax.SAXException; /** * The JellyGenerator executes jelly scripts using the Jakarta Jelly engine * as a Cocoon Generator. * * @author <a href="mailto:[EMAIL PROTECTED]">Amal Sirvisetti</a> */ public class JellyGenerator extends ComposerGenerator { /** The Jelly Context */ protected JellyContext jellyContext; /** * Recycle this component. * All instance variables are set to <code>null</code>. */ public void recycle() { super.recycle(); this.jellyContext = null; } /** * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup */ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters params) throws ProcessingException,SAXException,IOException { super.setup(resolver, objectModel, src, params); // Initialize the Jelly context this.jellyContext = new JellyContext(); // Update JellyContext with sitemap parameters this.updateContext(params); } /** * Generate XML data from Jelly script. */ public void generate() throws IOException, SAXException, ProcessingException { SAXParser parser = null; int len = 0; String contentType = null; Source scriptSource = null; try { // Update JellyContext with request parameters. Variables set earlier // (from sitemap parameters) will be overriden, if same variables are // supplied through the request object. this.updateContext(); // Execute Jelly script StringWriter output = new StringWriter(); XMLOutput xmlOutput = XMLOutput.createXMLOutput(output); scriptSource = this.resolver.resolveURI(this.source); this.jellyContext.runScript(scriptSource.getURI(), xmlOutput); xmlOutput.flush(); InputSource inputSource = new InputSource(new StringReader(output.toString())); parser = (SAXParser) this.manager.lookup(SAXParser.ROLE); parser.parse(inputSource, super.xmlConsumer); } catch (IOException e) { getLogger().error("JellyGenerator.generate()", e); throw new ResourceNotFoundException("JellyGenerator could not find resource", e); } catch (SAXException e) { getLogger().error("JellyGenerator.generate()", e); throw (e); } catch (Exception e) { getLogger().error("Could not get parser", e); throw new ProcessingException("Exception in JellyGenerator.generate()", e); } finally { this.resolver.release( scriptSource ); this.manager.release((Component)parser); } } /** * Update JellyContext with variables from sitemap */ protected void updateContext(Parameters params) throws ProcessingException { try { String pArray[] = params.getNames(); for(int i=0; i<pArray.length; i++) { String var = pArray[i]; String val = (String) params.getParameter(var); this.jellyContext.setVariable( var, val ); } } catch (Exception e) { getLogger().error("Error in JellyGenerator.updateContext(Parameters params)", e); throw new ProcessingException("Exception in JellyGenerator.updateContext(Parameters params)", e); } } /** * Update JellyContext with variables from request */ protected void updateContext() throws ProcessingException { try { Request request = ObjectModelHelper.getRequest( this.objectModel ); Enumeration enum = request.getParameterNames(); while (enum.hasMoreElements()) { String var = (String) enum.nextElement(); String val = (String) request.getParameter(var); this.jellyContext.setVariable( var, val ); } } catch (Exception e) { getLogger().error("Error in JellyGenerator.updateContext()", e); throw new ProcessingException("Exception in JellyGenerator.updateContext()", e); } } } 1.1 cocoon-2.1/src/scratchpad/mocks/org/apache/commons/jelly/JellyContext.java Index: JellyContext.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.commons.jelly; /** * Mock class providing the declarations required to compile the Cocoon code when * the actual library is not present. * * @version CVS $Id: JellyContext.java,v 1.1 2003/06/13 10:27:20 cziegeler Exp $ */ public class JellyContext { public JellyContext() {} public void setVariable(String name, Object value) {} public JellyContext runScript(String uri, XMLOutput output) throws JellyException { return null; } } 1.1 cocoon-2.1/src/scratchpad/mocks/org/apache/commons/jelly/XMLOutput.java Index: XMLOutput.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.commons.jelly; import java.io.IOException; import java.io.Writer; /** * Mock class providing the declarations required to compile the Cocoon code when * the actual library is not present. * * @version CVS $Id: XMLOutput.java,v 1.1 2003/06/13 10:27:20 cziegeler Exp $ */ public class XMLOutput { public XMLOutput() { } public void flush() throws IOException { } public static XMLOutput createXMLOutput(Writer writer) { return null; } } 1.1 cocoon-2.1/src/scratchpad/mocks/org/apache/commons/jelly/JellyException.java Index: JellyException.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.commons.jelly; /** * Mock class providing the declarations required to compile the Cocoon code when * the actual library is not present. * * @version CVS $Id: JellyException.java,v 1.1 2003/06/13 10:27:20 cziegeler Exp $ */ public class JellyException extends Exception { public JellyException() { } } 1.11 +15 -7 cocoon-2.1/src/targets/compile-build.xml Index: compile-build.xml =================================================================== RCS file: /home/cvs/cocoon-2.1/src/targets/compile-build.xml,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- compile-build.xml 18 May 2003 17:03:06 -0000 1.10 +++ compile-build.xml 13 Jun 2003 10:27:25 -0000 1.11 @@ -41,22 +41,30 @@ <!-- compiles the scratchpad --> <target name="compile-scratchpad" depends="prepare" unless="unless.exclude.scratchpad"> - <mkdir dir="${build.scratchpad.src}"/> + <mkdir dir="${build.scratchpad.dest}"/> - - <copy todir="${build.scratchpad.src}" filtering="on"> - <fileset dir="${scratchpad.src}"/> - </copy> <copy todir="${build.scratchpad.dest}"> - <fileset dir="${build.scratchpad.src}"> + <fileset dir="${scratchpad.src}"> <exclude name="**/*.java"/> <exclude name="**/*.xroles"/> <exclude name="**/*.xconf"/> </fileset> </copy> - <javac srcdir="${build.scratchpad.src}" + <!-- compile mock classes --> + <mkdir dir="${build.mocks}"/> + <javac srcdir="${scratchpad.mocks}" + destdir="${build.mocks}" + debug="${compiler.debug}" + optimize="${compiler.optimize}" + deprecation="${compiler.deprecation}" + target="${target.vm}" + nowarn="${compiler.nowarn}" + compiler="${compiler}" + classpathref="classpath"/> + + <javac srcdir="${scratchpad.src}" destdir="${build.scratchpad.dest}" debug="${compiler.debug}" optimize="${compiler.optimize}" 1.1 cocoon-2.1/src/scratchpad/webapp/samples/jelly/sitemap.xmap Index: sitemap.xmap =================================================================== <?xml version="1.0"?> <!-- CVS $Id: sitemap.xmap,v 1.2 2003/03/17 13:25:07 stefano Exp $ Jelly Sample --> <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0"> <map:components> <map:generators default="file"> <map:generator name="jelly" src="org.apache.cocoon.generation.JellyGenerator"/> </map:generators> <map:transformers default="xslt"/> <map:readers default="resource"/> <map:serializers default="html"/> <map:matchers default="wildcard"/> <map:selectors default="browser"/> </map:components> <map:pipelines> <map:pipeline> <map:match pattern=""> <map:redirect-to uri="test1"/> </map:match> <map:match pattern="*"> <map:generate src="{1}.xml" type="jelly"> <map:parameter name="name" value="Cocoon Jelly"/> <map:parameter name="background" value="#003366"/> <map:parameter name="hobbies" value="Reading"/> </map:generate> <map:serialize type="xml"/> </map:match> </map:pipeline> </map:pipelines> </map:sitemap> 1.1 cocoon-2.1/src/scratchpad/webapp/samples/jelly/test2.xml Index: test2.xml =================================================================== <?xml version="1.0"?> <j:jelly trim="false" xmlns:j="jelly:core" xmlns:x="jelly:xml" xmlns:html="jelly:html"> <html> <head> <title>${name}'s Page</title> </head> <body bgcolor="${background}" text="#FFFFFF"> <h1>${name}'s Homepage</h1> <img src="${url}"/> <h2>My Hobbies</h2> <ul> <j:forEach items="${hobbies}" var="i"> <li>${i}</li> </j:forEach> </ul> </body> </html> </j:jelly> 1.1 cocoon-2.1/src/scratchpad/webapp/samples/jelly/test1.xml Index: test1.xml =================================================================== <?xml version="1.0"?> <j:jelly xmlns:j="jelly:core" xmlns:log="jelly:log"> <root> <a>Hi Cocoon! I am Jelly generating XML for you!!</a> </root> </j:jelly> 1.21 +1 -0 cocoon-2.1/build.properties Index: build.properties =================================================================== RCS file: /home/cvs/cocoon-2.1/build.properties,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- build.properties 31 May 2003 17:01:26 -0000 1.20 +++ build.properties 13 Jun 2003 10:27:38 -0000 1.21 @@ -128,6 +128,7 @@ # Scratchpad Stuff scratchpad=${src}/scratchpad scratchpad.src=${scratchpad}/src +scratchpad.mocks=${scratchpad}/mocks scratchpad.lib=${scratchpad}/lib scratchpad.samples=${scratchpad}/webapp/samples 1.7 +9 -1 cocoon-2.1/src/scratchpad/webapp/samples/scratchpad-samples.xml Index: scratchpad-samples.xml =================================================================== RCS file: /home/cvs/cocoon-2.1/src/scratchpad/webapp/samples/scratchpad-samples.xml,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- scratchpad-samples.xml 27 Apr 2003 01:57:04 -0000 1.6 +++ scratchpad-samples.xml 13 Jun 2003 10:27:38 -0000 1.7 @@ -47,4 +47,12 @@ </sample> </group> + <group name="Jelly"> + <sample name="Test 1" href="jelly/test1"> + A test of the Jelly generator - you have to download and install the jelly.jar first! + </sample> + <sample name="Test 2" href="jelly/test2"> + A test of the Jelly generator - you have to download and install the jelly.jar first! + </sample> + </group> </samples>