What is Cocoon? - Chesapeake Bay Program

saucecopywriterInternet και Εφαρμογές Web

2 Φεβ 2013 (πριν από 4 χρόνια και 6 μήνες)

226 εμφανίσεις

What is Cocoon?

1.x
-

XML transforming servlet


2.0
-

XML publishing framework

2.1
-

XML web application framework


"Apache Cocoon is a web development framework built around the concepts of
separation of concerns (making sure people can interact and collaborate on a
project, without stepping on each other toes) and component
-
based web
development."

Getting it...

Source snapshots and anonymous CVS [Concurrent Versions System] available.

Building from CVS checkouts lets you track development.

Using CVS reduces time spent downloading since you request only the changes.

So first get CVS from
http://www.cvshome.org

then unzip it somewhere and add it to
your PATH.

Initial checkout:

cd
\
your
\
cvs
\
directory

cvs
-
d :pserver:anoncvs@cvs.apache.org:/home/cvspublic login

...use this password: anoncvs

cvs
-
d :pserver:anoncvs@cvs.apache.org:/home/cvspublic
checkout cocoon
-
2.1

cvs
-
d :pserver:anoncvs@cvs.apache.org:/home/cvspublic logout

Update your tree:

cd
\
your
\
cvs
\
directory
\
cocoon
-
2.1

cvs update

d
-
P

Building it...

Install the JDK 1.3+ for your platform

Set a JAVA_HOME environment variable for your platform pointing to your JVM root
directory.

SET JAVA_HOME=c:
\
path
\
to
\
java

cd
\
your
\
cvs
\
directory
\
cocoon
-
2.1

build

…messages go by, time passes.


Other build commands:

build clean

build

projecthelp

The default build includes the Jetty servlet container and is run
-
able right away.

When you want to customize your build you can find more detailed build instructions
in the file
~/INSTALL.txt

and online.

Running it...

Cocoon allows for easy migration from static to dynamic websites and applications
when the need arises.

Look what it can do!


It generates XML from databases, text files and more.


It transforms XML into HTML, PDF, JPG and more.


It handles application logic.


It does it all with a high degree of Separation of Concerns.

cocoon servlet

…visit

http://localhost:8888

in your browser.

cocoon cli [options] [targets]

…watch Cocoon crawl your site and generate static content for you.

…as a servlet:

…from the command line:

How does it do it?

Developers build pipelines in XML files named
sitemap.xmap
.

Pipelines match a request.

Pipeline execution begins with a
Generator
, applies one or more
Transformer
s
and ends with a
Serializer
.

<map:match pattern="hello.xhtml">


<map:generate src="content/hello.xml"/>


<map:transform src="style/xsl/page2html.xsl"/>


<map:serialize type="xhtml"/>

</map:match

<map:match pattern="hello.svg">


<map:generate src="content/hello.xml"/>


<map:transform src="style/xsl/page2svg.xsl"/>


<map:serialize type="svgxml"/>

</map:match>

Pipeline Components

Matcher



matches a URI with a pipeline; matchers allow Cocoon to associate a
pure "virtual" URI space with a given set of "instructions" found in a Cocoon
sitemap. Sitemap matchers are used to determine the flow and order of request
processing.

Generator



is the starting point for a pipeline; it delivers SAX events down the
pipeline. Generators are independent of the concept "file;" any source of SAX
events can be made a generator.

Transformer



gets an XML document (or SAX events), and generates another
XML document (or SAX events).

Serializer



transforms SAX events to a presentation format such as HTML,
XML or PDF; to a user
-
agent the serializer output looks like any static file on the
server.

Reader



encapsulates the features of a generator, transformer, and serializer.
Readers are useful for delivering binary content like images

Selector



selectors are like matchers but allow more complex, multiple
-
choice
use cases.


For a complete sitemap diagram:
http://outerthought.net/downloads/sitemap.pdf

Slightly More Complex Pipeline

<map:match pattern="cars/*/*">


<map:generate src="forms/car
-
db.xml"/>


<map:transform src="xsl/carfilter.xsl">


<map:parameter name="list" value="models"/>


<map:parameter name="make" value="{1}"/>


<map:parameter name="type" value="{2}"/>


</map:transform>


<map:serialize type="xml"/>

</map:match>

Pipelines:


can pass parameters to components.


can call other pipelines to aggregate content in complex ways.


can handle errors.


can be made internal to Cocoon and not directly accessible to users.

Avalon Components in Cocoon

Avalon is a component framework upon which Cocoon development is based.
http://avalon.apache.org

To gain the benefits of Avalon component lifecycle management and Cocoon
integration:


Extend Cocoon base classes for the desired pipeline component


Override base class methods


Implement additional Avalon interfaces

Add the new component to your
sitemap.xmap

Add its configuration data to

\
WEB
-
INF
\
cocoon.xconf
if the component
implements the
Configurable
interface

Use the component in the sitemap to construct new pipelines.

Blocks

Contain services and components that are not core to Cocoon operation.

Some interesting blocks:


fop
-

PDF, PS and PCL serialization


batik
-

SVG rasterization and serialization


axis


SOAP
-
style webservices


jsp
-

use existing JSP pages within Cocoon


lucene
-

sophisticated search indexing


woody
-

a widget
-
based forms framework


poi
-

transform XML to Excel spreadsheets for your users

...and many more

Right now Blocks are units of code but there are big plans for Blocks:


Blocks will be like WAR files [web application archive] but more


Inter
-
Block communication and dependency


Blocks will extend or inherit functionality from other blocks

Control Flow and Continuations

Continuations are a language feature implemented in the Rhino JavaScript
interpreter.

Flowscripts are controlling logic written in JavaScript.

Continuations represent your Flowscript execution stack at different points in your
application.

Cocoon puts these continuations in a hash table along with an associated ID.

Cocoon's
Flow Control
retrieves saved continuations and resumes Flowscript
execution each time the user requests a page that embeds the continuation ID.

Cocoon’s
Flow Object Model

(FOM) provides system objects for use by Flowscripts:


Cocoon



Context


Request



Cookie


Response


Log


Session



Continuation

Benefits:


Easily control application state without complicated session management.


Handle page transitions as in a forms wizard.


Deal gracefully with things such as back button events.


var cart;


function checkout()


{



sendPageAndWait("login.xml");



var user = UserRegistry.getUser(cocoon.request.get("name"));



sendPageAndWait("shippingAddress.xml");



var address = cocoon.request.get("address");



sendPageAndWait("creditCard.xml");



var creditCard = cocoon.request.get("creditCard");



sendPageAndWait("placeOrder.xml");



EnterpriseSystem.placeOrder(cart);



sendPage("orderPlaced.xml");


}

Flow Example

1.
The flow interpreter saves a continuation at each
sendPageAndWait()
invocation.

2.
Execution restarts transparently on user response.

3.
Finally, the
sendPage()

method terminates execution and continuations are
garbage collected.

Forms framework

Woody has developed into the "best of breed" among earlier forms frameworks
[JXForms, Precept, XMLForm, Woody] and will become
"
Cocoon Forms."

Woody is a forms framework made up of:


Woody Definition [wd namespace]


declares form widgets and form structure.


Woody Template [wt namespace]


a template that calls widgets by ID from a form
definition. The WoodyTemplateTransformer transforms the widgets in your template into
form and widget instances.


Woody Instances [wi namespace]


widget instances remember their state, validate data,
and generate XML representations.


Woody Binding [wb namespace]


binds form data, by widget ID, to a Javabean or XML
document using a JXPath expression.


Woody Documentation:

WoodyIntro

WoodySample

WoodyBinding

WoodyEventHandling

WoodyWidgetReference

Cocoon Resources

Cocoon Website:
http://cocoon.apache.org

Cocoon 2.1 Documentation:
http://cocoon.apache.org/2.1/introduction.html

Cocoon Wiki:
http://wiki.cocoondev.org/

Mailing Lists:
http://cocoon.apache.org/community/mail
-
lists.html

Mailing List Archives:
http://cocoon.apache.org/community/mail
-
archives.html

Cocoon Links:
http://cocoon.apache.org/link/index.html

Presentations from Cocoon GetTogether 2003:


http://www.apache.org/dist/cocoon/events/gt2003/presentations/

Books:

Cocoon: Building XML Applications, 2002, Carsten Ziegeler and Matthew Langham

Cocoon Developer's Handbook, 2002, Lajos Moczar and Jeremy Aston

Cocoon 2 Programming: Web Publishing with XML and Java, 2002,


Bill Brogden, Conrad D'Cruz and Mark Gaither

Cocoon People

Some people to watch in the mailing lists and blogs:

Stefano Mazzochi [Cocoon founder]:
http://www.betaversion.org/~stefano

Steven Noels [VP Cocoon]:
http://blogs.cocoondev.org/stevenn/

Berin Loritsch [VP Avalon]

Sam Ruby [VP Jakarta]:
http://www.intertwingly.net/blog/

Carsten Ziegler [Release manager]:
http://radio.weblogs.com/0107211/

Matthew Langham [Book author]
:
http://www.silent
-
penguin.com

Ovidu Predescu [Control Flow]:
http://www.webweavertech.com/ovidiu/weblog/

Ugo Cei [Control Flow]:
http://www.beblogging.com/blog/

Bruno Dumon [Woody forms]:
http://wiki.cocoondev.org/Wiki.jsp?page=BrunoDumon

Sylvain Wallez [Interpreted sitemap]:
http://www.anyware
-
tech.com/blogs/sylvain/


And many more contributors and interesting people.

There is much more…

It is possible to develop sophisticated applications without writing a line of Java:


Application developers can use standard Cocoon functionality in pipeline
construction.


Web designers can create, and re
-
create styles using XSLT, CSS.


Content developers can contribute without worrying about logic and
presentation.

…but power and flexibility exists so that:


Application developers can extend Cocoon to supply desired functionality.


Application developers can implement application logic.


Cocoon is reaching maturity as a web application framework.