Emerging Technology
Fall Semester, 2004 Generators |
||
---|---|---|
© 2004, All Rights Reserved, SDSU & Roger Whitney San Diego State University -- This page last updated 28-Sep-04 |
CS 683 Emerging Technologies Fall Semester, 2004 Doc 15 Generators
Copyright ©, All rights reserved. 2004 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA. OpenContent ( http://www.opencontent.org/opl.shtml) license defines the copyright on this document.
CS 683 Fall 04 | Doc 15, Generators Slide # 2 |
Cocoon Developer’s Handbook, Moczar & Aston, Sams Publishing, 2003
CS 683 Fall 04 | Doc 15, Generators Slide # 3 |
Load the parcel XSL.pcl in parcels directory in your VW installation.
Read the XSL stylesheet processing (page 529) section of chapter 24 (XML Framework) of the VisualWorks Application Developer’s Guide
Download Xalan-Java ( http://xml.apache.org/xalan-j/ )
Read the docs and examples
CS 683 Fall 04 | Doc 15, Generators Slide # 4 |
If a server generates a file called foo to help process a request
What happens if the server gets two such requests at the same time?
CS 683 Fall 04 | Doc 15, Generators Slide # 5 |
import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; public class SimpleTransform { public static void main(String[] args) throws TransformerException, TransformerConfigurationException, FileNotFoundException, IOException { TransformerFactory tFactory = TransformerFactory.newInstance(); String xsl = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:template match=\"/\"><html> <title> <xsl:value-of select=\"greetings\"/></title> <body><h1><xsl:value-of select=\"greetings\"/></h1> </body></html></xsl:template></xsl:stylesheet>";
CS 683 Fall 04 | Doc 15, Generators Slide # 6 |
Transformer transformer = tFactory.newTransformer( new StreamSource(new StringReader(xsl))); String xml = "<?xml version=\"1.0\"?><?xml-stylesheet type=\"text/xsl\" href=\"hello.xsl\"?><greetings>Hello World</greetings>"; StringWriter result = new StringWriter(); transformer.transform( new StreamSource( new StringReader( xml)), new StreamResult(result)); System.out.println(result.toString()); } }
CS 683 Fall 04 | Doc 15, Generators Slide # 7 |
DirectoryGenerator
ErrorGenerator
HTMLGenerator
JspGenerator
RequestGenerator
ScriptGenerator
VelocityGenerator
CS 683 Fall 04 | Doc 15, Generators Slide # 8 |
Processing without the tags
http://jakarta.apache.org/velocity/
CS 683 Fall 04 | Doc 15, Generators Slide # 9 |
<?xml version="1.0"?> #set($user = $request.getParameter("user")) #set($pass = $request.getParameter("pass")) <page> <title>Login Results</title> <content> #if ($pass == 'hi') <paragraph>Your In</paragraph> #else <paragraph>You missed</paragraph> #end <h3>Parameters</h3> #foreach ($name in $request.getParameterNames()) <paragraph> $name = $request.getParameter($name) </paragraph> #end </content> </page>
http://bismarck.sdsu.edu:9006/cocoon/velocity/index.html?user=foo&pass=hi&less=more
http://bismarck.sdsu.edu:9006/cocoon/velocity/index.html?pass=no
CS 683 Fall 04 | Doc 15, Generators Slide # 10 |
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="page"> <html> <head> <title> <xsl:value-of select="title"/> </title> </head> <body> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="title"> <h2><xsl:apply-templates/></h2> </xsl:template> <xsl:template match="paragraph"> <p><xsl:apply-templates/></p> </xsl:template> </xsl:stylesheet>
CS 683 Fall 04 | Doc 15, Generators Slide # 11 |
<?xml version="1.0"?> <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0"> <map:components> <map:generators default="file" /> <map:transformers default="xslt" /> <map:readers default="resources" /> <map:serializers default="html" /> <map:selectors default="browser" /> <map:matchers default="wildcard" /> </map:components> <map:pipelines> <map:pipeline> <map:match pattern="index.html"> <map:generate type="velocity" src="templates/login.vm" /> <map:transform type="xslt" src="style/main.xsl" /> <map:serialize type="html" /> </map:match> </map:pipeline> </map:pipelines> </map:sitemap>
CS 683 Fall 04 | Doc 15, Generators Slide # 12 |
<map:pipeline> <map:match pattern="velocity/**"> <map:mount uri-prefix="velocity" src="velocity/sitemap.xmap" check-reload="yes" reload-method="synchron"/> </map:match> </map:pipeline>
Copyright ©, All rights reserved.
2004 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.