Академический Документы
Профессиональный Документы
Культура Документы
The
Power Trio
“Serious webapps can still be fun!”
Steven Noels
Managing Partner
Outerthought
What you will learn
2
About myself
Ongoing rants at
http://blogs.cocoondev.org/stevenn/
3
“We don’t spend nearly enough
time on TSS.”
4
Agenda
Introducing Cocoon
The Cocoon Sitemap
The magical trio: pipelines, flow and forms
Web continuations using Flowscripts
Cocoon Forms aka Woody
Binding to XML, beans and back-ends
Apache Cocoon: where and what
5
The big picture
6
Introducing Cocoon
9
The Cocoon Sitemap
<map:match pattern="*.html">
<map:generate src=”xdocs/{1}.xml"/>
<map:transform src=“style/xdocs2html.xsl”/>
<map:serialize/>
</map:match>
11
More sitemap niftiness
<map:match pattern="*-display-pipeline">
<map:generate src="forms/{1}_template.xml"/>
<map:transform type="woody"/>
<map:transform type="i18n">
<map:parameter name="locale" value="en-US"/>
</map:transform>
<map:call resource="simple-page2html">
<map:parameter name="file" value="forms/{1}_template.xml"/>
</map:call>
<map:transform src="resources/woody-samples-styling.xsl"/>
<map:serialize/>
</map:match>
<map:resource name="simple-page2html">
<map:transform
src="context://samples/common/style/xsl/html/simple-
page2html.xsl">
<map:parameter name="file" value="{file}"/>
</map:transform>
</map:resource>
12
Snippet explanation
13
Pipeline components
Passive Active
Generators Matchers
file, http, chaperon, request, directory, wildcard URI, regexp URI, request &
XSP, stream, JSP session parameter
Transformers Selectors
TRAX, i18n, nInclude, SourceWriting, browser (UA), host, sitemap, request &
LDAP, SQL session parameter
Serializers Actions
(X)HTML, SVG, PNG, text, ZIP, PDF, authentication, database, mail, session,
Excel
form
Input Modules
(accessing various input parameters in
the sitemap)
14
Introducing the Magical Trio
17
Web Continuations and Flowscripts
var email;
function newsletter()
creates a continuation {
+ invokes view while(email == null) {
+ “suspends” script cocoon.sendPageAndWait("email-form");
19
Continuations
Contain
Function call stack
Local variables values
Unique ID
Can be manually invalidated, or via automated
cleanup (expiration)
Support “branching” (back button, clone browser
window)
20
Business Layer: it is up to you!
21
Model, Controller, … View
JXTemplate Generator/Transformer
XML Templates interspersed with JXPath/Jexl object value
lookups
No code allowed (compared to JSP/XSP)
sendPage("checkout.html",
{"customer": user, "cart": cart});
<p>Welcome, #{customer/firstName}</p>
22
Bringing it all together
23
Cocoon Forms aka Woody
25
Demo registration form
26
Form Definition
<?xml version="1.0" encoding="ISO-8859-1"?> <wd:label>Password:</wd:label>
<wd:form <wd:datatype base="string">
xmlns:wd="http://apache.org/cocoon/woody/definition/1.0" <wd:validation>
xmlns:i18n="http://apache.org/cocoon/i18n/2.1"> <wd:length min="5" max="20"/>
<wd:widgets> </wd:validation>
<wd:field id="name" required="true"> </wd:datatype>
<wd:label>Name:</wd:label> </wd:field>
<wd:field id="confirmPassword" required="true">
<wd:datatype base="string">
<wd:label>Re-enter password:</wd:label>
<wd:validation>
<wd:datatype base="string">
<wd:length min="2"/>
<wd:validation>
</wd:validation>
<wd:assert test="password = confirmPassword">
</wd:datatype>
<wd:failmessage>The two passwords are not
</wd:field> equal.</wd:failmessage>
<wd:field id="email" required="true"> </wd:assert>
<wd:label>Email address:</wd:label> </wd:validation>
<wd:datatype base="string"> </wd:datatype>
<wd:validation> </wd:field>
<wd:email/> ...
</wd:validation>
</wd:datatype>
</wd:field>
<wd:field id="age">
<wd:label>Your age:</wd:label>
<wd:datatype base="long">
<wd:validation>
<wd:range min="0" max="150"/>
</wd:validation>
</wd:datatype>
</wd:field>
<wd:field id="password" required="true">
27
Available Widgets
Field widget
<wd:field id="..." required="true|false">
<wd:label>...</wd:label>
<wd:hint>...</wd:hint>
<wd:help>...</wd:help>
<wd:datatype base="...">
[...]
</wd:datatype>
<wd:selection-list .../>
<wd:on-value-changed>
...
</wd:on-value-changed>
</wd:field>
multivaluefield upload
booleanfield HTMLArea
repeater
output (read-only
field)
action (events)
submit
aggregatefield 29
Form Template
<?xml version="1.0"?>
<page xmlns:wt="http://apache.org/cocoon/woody/template/1.0"
xmlns:wi="http://apache.org/cocoon/woody/instance/1.0">
<title>Registration</title>
<content>
<wt:form-template action="#{$continuation/id}.continue" method="POST">
<wt:widget-label id="name"/>
<wt:widget id="name"/>
<br/>
<wt:widget-label id="email"/>
<wt:widget id="email"/>
<br/>
<wt:widget-label id="age"/>
<wt:widget id="age"/>
<br/>
<wt:widget-label id="password"/>
<wt:widget id="password">
<wi:styling type="password"/>
</wt:widget>
<br/>
<wt:widget-label id="confirmPassword"/>
<wt:widget id="confirmPassword">
<wi:styling type="password"/>
</wt:widget>
<br/>
<wt:widget id="spam"/>
<wt:widget-label id="spam"/>
<br/>
<input type="submit"/>
</wt:form-template>
</content> 30
</page>
Rendering a form
WoodyTemplateTransformer + XSLT
31
Binding to XML, beans and back-ends
32
Demo XML Binding
33
Binding sample
public class Form2Bean {
Based on JXPath
private String email;
private String ipAddress; XML
public String getEmail() { JavaBeans
return email;
} Directional binding
public void setEmail(String email) { load
this.email = email;
} save
public String getIpAddress() {
return ipAddress; repeater support
}
Possibility to write
public void setIpAddress(String ipAddress) {
}
this.ipAddress = ipAddress; binding code in
} JavaScript
http://cocoon.apache.org/
Mailing list pop stats: on par with Ant
users list population (2004-2-24)
3000
2500
2000
1500
1000
500
900
800
700
600
500
400
300
200
100
jakarta taglibs 36
jakarta commons
Conclusions
http://cocoon.apache.org/
European-wide business support by Orixo - the
XML Business Alliance
Thank you!
37