Emerging Technology
Fall Semester, 2004 More Cocoon Flow |
||
---|---|---|
© 2004, All Rights Reserved, SDSU & Roger Whitney San Diego State University -- This page last updated 05-Oct-04 |
CS 683 Emerging Technologies Fall Semester, 2004 Doc 17 More Cocoon Flow
Hello World With Main Sitemap Changed
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 17, More Cocoon Flow Slide # 2 |
Cocoon Flow Documentation
http://cocoon.apache.org/2.1/userdocs/flow/index.html
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 3 |
Cocoon Flow requires Cocoon 2.1.x
All the examples in this document use Cocoon 2.1
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 4 |
No additions to cocoon main sitemap are needed
As directory structure and url to sitemap match
http://bismarck.sdsu.edu:9006/cocoon/hello2/hello.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Hello</title> </head> <body> Hello World </body> </html>
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 5 |
<?xml version="1.0" encoding="UTF-8"?> <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0"> <map:components> <map:generators default="file" /> <map:transformers default="xslt"/> <map:serializers default="html"/> <map:matchers default="wildcard"/> <map:selectors default="browser" /> <map:pipes default="caching"/> </map:components> <map:pipelines> <map:pipeline> <map:match pattern="hello.html"> <map:read type="resource" mime-type="text/html" src="documents/hello.html" /> </map:match> </map:pipeline> </map:pipelines> </map:sitemap>
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 6 |
http://bismarck.sdsu.edu:9006/cocoon/goofy/hello.html
The new pipeline must be placed before the main pipeline
<map:pipeline> <map:match pattern="goofy/**"> <map:mount uri-prefix="goofy" src="hello2/sitemap.xmap" check-reload="yes" reload-method="synchron"/> </map:match> </map:pipeline> <!-- main pipeline --> <map:pipeline>
<!-- main pipeline --> <map:pipeline> <map:match pattern="goofy/**"> <map:mount uri-prefix="goofy" src="hello2/sitemap.xmap" check-reload="yes" reload-method="synchron"/> </map:match>
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 7 |
They will map the url to the file structure using default matching
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 8 |
Files
http://bismarck.sdsu.edu:9006/cocoon/javaNoXslt/simpleJava.html
function simpleJava() { var text = ""; var encoded = ""; var upperCase = ""; while (true) { cocoon.sendPageAndWait( "simpleJava.vm", {text: text, encoded: encoded, upperCase: upperCase}); text = cocoon.request.get("input"); var javaString = new java.lang.String( text); encoded = javaString.replaceAll( "<", "<"); upperCase = encoded.toUpperCase(); } }
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 9 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Sample Java</title> </head> <body> <p>No XSLT, Html is ok</p> #set( $kont = ".kont") <form action="$continuation.id$kont" method="post"> <textarea name="input" rows="15" cols="35">$text </textarea> <input type="submit" /> </form> <hr /> You entered: <pre>$encoded </pre> <hr /> Text as html:$text <hr /> Text as Uppercase: $upperCase </body> </html>
Warning: make sure that there is an space between a variable ($encoded) and a tag (</pre>)
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 10 |
This simplified sitemap works for this example
<?xml version="1.0" encoding="UTF-8"?> <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0"> <map:components> <map:generators default="file"/> <map:transformers default="xslt"/> <map:serializers default="html"/> <map:matchers default="wildcard"/> <map:selectors default="browser" /> <map:actions/> <map:pipes default="caching"/> </map:components> <map:flow language="javascript"> <map:script src="flow/main.js"/> </map:flow> <map:pipelines> <map:component-configurations> <global-variables/> </map:component-configurations> <map:pipeline> <map:match pattern="*.html"> <map:call function="{1}"/> </map:match>
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 11 |
<map:match pattern="*.vm"> <map:generate type="velocity" src="documents/{1}.vm"/> <map:serialize type="html"/> </map:match> <map:match pattern="*.kont"> <map:call continuation="{1}"/> </map:match> </map:pipeline> </map:pipelines> </map:sitemap>
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 12 |
Files
http://bismarck.sdsu.edu:9006/cocoon/javaXslt/simpleJava.html
function simpleJava() { var text = ""; var encoded = ""; var upperCase = ""; while (true) { cocoon.sendPageAndWait( "simpleJava.vm", { encoded: encoded}); text = cocoon.request.get("input"); var javaString = new java.lang.String( text); encoded = javaString.replaceAll( "<", "<"); } }
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 13 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Sample Java</title> </head> <body> <p>XSLT is ok</p> #set( $kont = ".kont") <form action="$continuation.id$kont" method="post"> <textarea name="input" rows="15" cols="35">$encoded </textarea> <input type="submit" /> </form> <hr /> You entered: <pre>$encoded </pre> <hr /> Can't display XSLT as html tags. What would it mean if one could? </body> </html>
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 14 |
Same as on slides 8 & 9
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 15 |
Files
http://bismarck.sdsu.edu:9006/cocoon/sequentialLogin/login.html
User must login
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 16 |
function login() { var invalidName; var name; while (true) { cocoon.sendPageAndWait( "login.vm", { name: name, notValid: invalidName}); name = cocoon.request.get("name"); if (name == "sam") break; invalidName = true; } var encoded = ""; while (true) { cocoon.sendPageAndWait( "main.vm", { encoded: encoded, name: name}); var text = cocoon.request.get("input"); var javaString = new java.lang.String( text); encoded = javaString.replaceAll( "<", "<"); } }
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 17 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Login</title> </head> <body> <p>Enter your name</p> #set( $kont = ".kont") <form action="$continuation.id$kont" method="post"> <input type="text" name="name" size="40" /> <input type="submit" /> </form> #if ( $notValid ) <p>Sorry but $name is not authorized to continue.</p> #end </body> </html>
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 18 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Main Page for $name </title> </head> <body> <p>Hello $name. Please enter some text.</p> #set( $kont = ".kont") <form action="$continuation.id$kont" method="post"> <textarea name="input" rows="15" cols="35">$encoded </textarea> <input type="submit" /> </form> <hr /> <p>You entered:</p> <pre>$encoded </pre> <hr /> </body> </html>
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 19 |
Files
http://bismarck.sdsu.edu:9006/cocoon/login/main.html
User can login to get more functionality
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 20 |
function main() { var name = ""; while (true) { var action = cocoon.request.get("action"); if (action == null) action = "text"; if (action == "login") name = login(); else displayTextPage(name); } } function displayTextPage(name ) { var text = cocoon.request.get("input"); if (text == null) text ="cat"; var javaString = new java.lang.String( text); var encoded = javaString.replaceAll( "<", "<"); cocoon.sendPageAndWait( "main.vm", { encoded: encoded, name: name}); }
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 21 |
function login() { var invalidName; while (true) { cocoon.sendPageAndWait( "login.vm", { name: name, notValid: invalidName}); var action = cocoon.request.get("action"); if (action == "Cancel" ) return ""; var name = cocoon.request.get("name"); if (name == "sam") return name; invalidName = true; } }
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 22 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> #if ($name == "") <title>Main Page</title> #else <title>Main Page for $name </title> #end </head> <body> #if ($name == "") <p>Please enter some text.</p> #else <p>Hello $name. Please enter some text.</p> #end #set( $kont = ".kont") <form action="$continuation.id$kont" method="post"> <textarea name="input" rows="15" cols="35">$encoded </textarea> <input type="hidden" name="action" value="text" /> <input type="submit" /> </form>
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 23 |
<form action="$continuation.id$kont" method="post"> <input type="submit" value="Login"/> <input type="hidden" name="action" value="login" /> </form> <hr /> <p>You entered:</p> <pre>$encoded </pre> <hr /> </body> </html>
CS 683 Fall 04 | Doc 17, More Cocoon Flow Slide # 24 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Login</title> </head> <body> <p>Enter your name</p> #set( $kont = ".kont") <form action="$continuation.id$kont" method="post"> <input type="text" name="name" size="40" /> <input type="submit" /> <input type="submit" name="action" value="Cancel" /> </form> #if( $notValid ) <p>Sorry but $name is not authorized.</p> #end </body> </html>
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.