Using Cocoon 2.2 The Classic Way Vadim Gritsenko - - //blog.reverycodes.com/g

23
Using Cocoon 2.2 The Classic Way Vadim Gritsenko - http://blog.reverycodes.com/ - http://agilepartners.com/blo g/

Transcript of Using Cocoon 2.2 The Classic Way Vadim Gritsenko - - //blog.reverycodes.com/g

Page 1: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

Using Cocoon 2.2The Classic Way

Vadim Gritsenko - http://blog.reverycodes.com/ - http://agilepartners.com/blog/

Page 2: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

If you use Cocoon 2.1:

In multiple software projects

Built multiple reusable, shared software modules

Have standardized directory structure, build, deployment processes...

Page 3: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

If you think of Cocoon 2.2:Ant has been

replaced with Maven

LogKit has been replaced by Log4J

Avalon is being replaced by Spring Framework

‘Real Blocks’ are almost here

No downloads (so far)You don’t have to start from

scratch!

Page 4: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

It’s not that scary.Ant has been replaced with Maven

You don’t have to use it.

LogKit has been replaced by Log4J

You don’t have to use it.

Avalon is being replaced by Spring Framework

You don’t have to use it.

No downloads (so far)

Oops... You’d have to use Maven for that...

Page 5: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

Web ApplicationWeb ApplicationWeb ApplicationWeb Application

SitemapSitemapSitemapSitemap

So how does it look?

Spring FrameworkSpring FrameworkSpring FrameworkSpring Framework

Avalon BridgeAvalon BridgeAvalon BridgeAvalon Bridge PipelinesPipelinesPipelinesPipelines

Your ApplicationYour ApplicationYour ApplicationYour Application

ComponentsComponentsComponentsComponents

applicationConte applicationContext.xml xt.xml

cocoon.xccocoon.xconfonf

sitemap.xsitemap.xmapmap

web.xml web.xml

Page 6: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

Building Cocoon

Install latest maven 2

Check out code from the svn repository

Start maven build process

Get coffee or beer (might take a while)

$ svn co $ svn co http://svn.apache.org/repos/asf/cocoon/trunk cocoon U cocoonU cocoonChecked out revision 577959.Checked out revision 577959.

$ mvn -P allblocks install$ mvn -P allblocks installjava.lang.OutOfMemoryError: Java heap java.lang.OutOfMemoryError: Java heap spacespace

...but only if you want it!

$ export MAVEN_OPTS=-Xmx256m$ export MAVEN_OPTS=-Xmx256m$ mvn -Dmaven.test.skip=true -P $ mvn -Dmaven.test.skip=true -P allblocks installallblocks install[INFO] BUILD SUCCESSFUL[INFO] BUILD SUCCESSFUL

Page 7: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

No more local.build.properties

No more local.blocks.properties

Use maven pom.xml file to select blocks

Need to set a version for each block

More typing but similar in nature

Selecting Blocks<?xml version="1.0" encoding="UTF-8"?><project xmlns="<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" " xmlns:xsi="xmlns:xsi="http://www.w3.org/2001/XMLSchema-http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsdhttp://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.reverycodes</groupId> <artifactId>my-cocoon-webapp</artifactId> <version>1.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>My Cocoon Webapp</name> <build> <finalName>my-cocoon-webapp</finalName> </build> <dependencies> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-core</artifactId> <version>2.2.0-RC2-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-template-impl</artifactId> <version>1.0.0-RC2-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-forms-impl</artifactId> <version>1.0.0-RC1-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-databases-impl</artifactId> <version>1.0.0-RC2-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-repository-impl</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <!-- <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-servlet-service-impl</artifactId> <version>1.0.0-RC1-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-servlet-service-components</artifactId> <version>1.0.0-RC1-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-blocks-fw-impl</artifactId> <version>1.0.0-M2-SNAPSHOT</version> </dependency> --> <!-- <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-batik-impl</artifactId> <version>1.0.0-RC2-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-fop-ng-impl</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-poi-impl</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> --> </dependencies></project>

<version>1.0.0-RC2-SNAPSHOT</version> </dependency> <version>1.0.0-RC2-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-forms-impl</artifactId> <version>1.0.0-RC1-<artifactId>cocoon-forms-impl</artifactId> <version>1.0.0-RC1-SNAPSHOT</version> </dependency> <dependency> SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-<groupId>org.apache.cocoon</groupId> <artifactId>cocoon-databases-impl</artifactId> databases-impl</artifactId> <version>1.0.0-RC2-SNAPSHOT</version> </dependency> <version>1.0.0-RC2-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-repository-impl</artifactId> <version>1.0.0-<artifactId>cocoon-repository-impl</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-batik-<groupId>org.apache.cocoon</groupId> <artifactId>cocoon-batik-impl</artifactId> <version>1.0.0-RC2-SNAPSHOT</version> impl</artifactId> <version>1.0.0-RC2-SNAPSHOT</version> </dependency> <dependency> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-fop-ng-<groupId>org.apache.cocoon</groupId> <artifactId>cocoon-fop-ng-impl</artifactId> <version>1.0.0-SNAPSHOT</version> impl</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-poi-<groupId>org.apache.cocoon</groupId> <artifactId>cocoon-poi-impl</artifactId> <version>1.0.0-SNAPSHOT</version> impl</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> --> </dependencies></project></dependency> --> </dependencies></project>

<artifactId>cocoon-fop-ng-impl</artifactId> <artifactId>cocoon-fop-ng-impl</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-poi- <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-poi-impl</artifactId> <version>1.0.0-SNAPSHOT</version> impl</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency></dependency>

...... </dependencies></project></dependencies></project>

<?xml version="1.0" encoding="UTF-8"?><project xmlns="<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" " xmlns:xsi="xmlns:xsi="http://www.w3.org/2001/XMLSchema-http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsdhttp://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.reverycodes</groupId> <artifactId>my-cocoon-webapp</artifactId> <version>1.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>My Cocoon Webapp</name> <build> <finalName>my-cocoon-webapp</finalName> </build> <dependencies> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-core</artifactId> <version>2.2.0-RC2-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-template-impl</artifactId> <version>1.0.0-RC2-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-forms-impl</artifactId> <version>1.0.0-RC1-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-databases-impl</artifactId> <version>1.0.0-RC2-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-repository-impl</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <!-- <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-servlet-service-impl</artifactId> <version>1.0.0-RC1-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-servlet-service-components</artifactId> <version>1.0.0-RC1-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-blocks-fw-impl</artifactId> <version>1.0.0-M2-SNAPSHOT</version> </dependency> --> <!-- <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-batik-impl</artifactId> <version>1.0.0-RC2-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-fop-ng-impl</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-poi-impl</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> --> </dependencies></project>

Page 8: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

Assembling Cocoon

Install latest maven 2

Start maven build process

Get coffee or beer (might take a while)

Gets faster on subsequent runs

$ ls$ lspom.xmlpom.xml

$ export MAVEN_OPTS=-Xmx256m$ export MAVEN_OPTS=-Xmx256m$ mvn war:war$ mvn war:war[INFO] BUILD SUCCESSFUL[INFO] BUILD SUCCESSFUL

$ ls target$ ls targetmy-cocoon-webapp/my-cocoon-webapp/my-cocoon-webapp.warmy-cocoon-webapp.war

$ find . -type f$ find . -type f./pom.xml./pom.xml./src/main/webapp/WEB-INF/web.xml./src/main/webapp/WEB-INF/web.xml

$ export MAVEN_OPTS=-Xmx256m$ export MAVEN_OPTS=-Xmx256m$ mvn war:war$ mvn war:war[INFO] BUILD SUCCESSFUL[INFO] BUILD SUCCESSFUL

$ ls target$ ls targetmy-cocoon-webapp/my-cocoon-webapp/my-cocoon-webapp.warmy-cocoon-webapp.war

Page 9: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

web.xml

applicationContext.xml

core.xml

cocoon.xconf

sitemap.xmap

WEB-INF/lib

Updating Webapp

Page 10: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

Updating web.xml

Servlet 2.4<!-- - Web application configuration. --><web-app <!-- - Web application configuration. --><web-app xmlns="xmlns="http://java.sun.com/xml/ns/j2ee" " version="2.4">version="2.4">

<!-- - Declare a filter for multipart MIME handling <!-- - Declare a filter for multipart MIME handling --><filter> <description>--><filter> <description> Multipart MIME handling filter for CocoonMultipart MIME handling filter for Cocoon </description> <display-name></description> <display-name> Cocoon multipart filterCocoon multipart filter </display-name> <filter-</display-name> <filter-name>CocoonMultipartFilter</filter-name> <filter-name>CocoonMultipartFilter</filter-name> <filter-class>class>org.apache.cocoon.servlet.multipart.MultipartFilterorg.apache.cocoon.servlet.multipart.MultipartFilter </filter-class></filter></filter-class></filter>

Servlet 2.4

MIME Multipart Servlet Filter

Servlet 2.4

MIME Multipart Servlet Filter

Filter Mapping

<!-- - Use the Cocoon multipart filter together with <!-- - Use the Cocoon multipart filter together with the Cocoon servlet --><filter-mapping> <filter-the Cocoon servlet --><filter-mapping> <filter-name>CocoonMultipartFilter</filter-name> <servlet-name>CocoonMultipartFilter</filter-name> <servlet-name>Cocoon</servlet-name></filter-mapping>name>Cocoon</servlet-name></filter-mapping>

<!-- - Spring request listener ... --><listener> <!-- - Spring request listener ... --><listener> <listener-class><listener-class>org.springframework.web.context.request.RequestContexorg.springframework.web.context.request.RequestContextListenertListener </listener-class></listener><!-- - Spring context </listener-class></listener><!-- - Spring context listener ... --><listener> <listener-class>listener ... --><listener> <listener-class>org.springframework.web.context.ContextLoaderListenerorg.springframework.web.context.ContextLoaderListener </listener-class> </listener> </listener-class> </listener>

<!-- - Declare Classic Cocoon servlet --><servlet> <!-- - Declare Classic Cocoon servlet --><servlet> <servlet-name>Cocoon</servlet-name> <display-<servlet-name>Cocoon</servlet-name> <display-name>Cocoon</display-name> <description>Classic name>Cocoon</display-name> <description>Classic Cocoon Servlet</description> <servlet-class>Cocoon Servlet</description> <servlet-class>org.apache.cocoon.servlet.SitemapServletorg.apache.cocoon.servlet.SitemapServlet </servlet-class> <load-on-startup>5</load-on-</servlet-class> <load-on-startup>5</load-on-startup></servlet>startup></servlet>

Servlet 2.4

MIME Multipart Servlet Filter

Filter Mapping

Context Listeners

Servlet 2.4

MIME Multipart Servlet Filter

Filter Mapping

Context Listeners

and Cocoon Servlet!

Page 11: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

Complete web.xml<!-- - Web application configuration. --><web-app xmlns="<!-- - Web application configuration. --><web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4"> <!-- - Declare a filter for multipart MIME " version="2.4"> <!-- - Declare a filter for multipart MIME handling --> <filter> <description>Multipart MIME handling filter for Cocoon</description> <display-name>Cocoon multipart filter</display-name> handling --> <filter> <description>Multipart MIME handling filter for Cocoon</description> <display-name>Cocoon multipart filter</display-name> <filter-name>CocoonMultipartFilter</filter-name> <filter-class>org.apache.cocoon.servlet.multipart.MultipartFilter</filter-class> </filter> <!-- - <filter-name>CocoonMultipartFilter</filter-name> <filter-class>org.apache.cocoon.servlet.multipart.MultipartFilter</filter-class> </filter> <!-- - Declare a filter for debugging incoming request --> <filter> <description>Log debug information about each request</description> <display-name>Cocoon Declare a filter for debugging incoming request --> <filter> <description>Log debug information about each request</description> <display-name>Cocoon debug filter</display-name> <filter-name>CocoonDebugFilter</filter-name> <filter-class>org.apache.cocoon.servlet.DebugFilter</filter-class> </filter> debug filter</display-name> <filter-name>CocoonDebugFilter</filter-name> <filter-class>org.apache.cocoon.servlet.DebugFilter</filter-class> </filter> <!-- - Use the Cocoon multipart filter together with the Cocoon servlet --> <filter-mapping> <filter-name>CocoonMultipartFilter</filter-name> <!-- - Use the Cocoon multipart filter together with the Cocoon servlet --> <filter-mapping> <filter-name>CocoonMultipartFilter</filter-name> <servlet-name>Cocoon</servlet-name> </filter-mapping> <!-- - Declare Spring request listener which sets up the required RequestAttributes - to support <servlet-name>Cocoon</servlet-name> </filter-mapping> <!-- - Declare Spring request listener which sets up the required RequestAttributes - to support Springs and Cocoon custom bean scopes like the request scope or the - session scope. --> <listener> <listener-Springs and Cocoon custom bean scopes like the request scope or the - session scope. --> <listener> <listener-class>org.springframework.class>org.springframework.web.context.request.RequestContweb.context.request.RequestContextListener</listener-class> </listener> <!-- - Declare Spring context listener which sets up the Spring - Application Context containing all application components. --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListenerweb.context.ContextLoaderListener</listener-class> </listener> <!-- </listener-class> </listener> <!-- - Declare Classic Cocoon servlet --> <servlet> <servlet-name>Cocoon</servlet-name> <display-name>Cocoon</display-name> <description>Classic Cocoon Servlet</description> <servlet-class>org.apache.cocoon.servlet.SitemapServlet</servlet-class> <load-on-startup>5</load-on-startup> </servlet> <!-- - Cocoon handles all the URL space assigned to the webapp using its sitemap. - It is recommended to leave it unchanged. Under some circumstances though - (like integration with proprietary webapps or servlets) you might have - to change this parameter. --> <servlet-mapping> <servlet-name>Cocoon</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> <!-- - Some servlet engines (Tomcat) have defaults which are not overriden - by '/' mapping, but must be overriden explicitly. --> <servlet-mapping> <servlet-name>Cocoon</servlet-name> <url-pattern>*.jsp</url-pattern> </servlet-mapping> <!-- - Some servlet engines (WebLogic) have defaults which are not overriden - by '/' mapping, but must be overriden explicitly. --> <servlet-mapping> <servlet-name>Cocoon</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping> <!-- - Default session timeout parameter. --> <session-config> <session-timeout>30</session-timeout> </session-config></web-app>

Debug filter

Servlet mappings

Session timeout

Mime types

...

Page 12: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

Adding appContext.xml

Main Spring configuration file

Just loads Cocoon’s core.xml

<!-- - Spring Application Context definition --><beans <!-- - Spring Application Context definition --><beans xmlns="xmlns="http://www.springframework.org/schema/beans" " xmlns:xsi="xmlns:xsi="http://www.w3.org/2001/XMLSchema-instancehttp://www.w3.org/2001/XMLSchema-instance" " xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/behttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <!-- - Load Cocoon --> <import resource="cocoon/spring/core.xml"/> </beans>

Page 13: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

Adding core.xml

It’s all Greek!And a lot of it!

Get used to it - this is a replacement for cocoon.xconf!

So, what’s in it?

<beans xmlns="<beans xmlns="http://www.springframework.org/schema/beans" " xmlns:xsi="xmlns:xsi="http://www.w3.org/2001/XMLSchema-instancehttp://www.w3.org/2001/XMLSchema-instance" " xmlns:util="http://www.springframework.org/schema/util" " xmlns:configurator=" xmlns:configurator="http://cocoon.http://cocoon.apache.org/schema/configurator" xmlns:avalon="http://cocoon.apache.org/schema/avalonhttp://cocoon.apache.org/schema/avalon" " xmlns:aop="xmlns:aop="htthttp://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schemahttp://www.springframework.org/schema/beans/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd httphttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd http://cocoon.apache.org/schema/configurator http://cocoon.apache.orghttp://cocoon.apache.org/schema/configurator/cocoon-configurator-1.0.1.xsd http://cocoon.apache.org/schema/avalonhttp://cocoon.apache.org/schema/avalon http://cocoon.apache.org/schema/avalon/http://cocoon.apache.org/schema/avalon/cocoon-avalon-1.0.xsd http://www.springframework.org/schemahttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">">

Page 14: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

What’s in core.xml?

Configurator loads Cocoon configuration and property files from file system

Log4J Bean

Avalon Bridge

<!-- Activate Cocoon Spring Configurator --> <!-- Activate Cocoon Spring Configurator --> <configurator:settings readFromClasspath="false"/> <!-- <configurator:settings readFromClasspath="false"/> <!-- Configure Log4j --> <bean Configure Log4j --> <bean name="org.apache.cocoon.spring.configurator.log4j" name="org.apache.cocoon.spring.configurator.log4j" class="org.apache.cocoon.spring.configurator.log4j.Log4JConficlass="org.apache.cocoon.spring.configurator.log4j.Log4JConfigurator" scope="singleton"> <property gurator" scope="singleton"> <property name="settings" name="settings" ref="org.apache.cocoon.configuration.Settings"/> <property ref="org.apache.cocoon.configuration.Settings"/> <property name="resource" value="/WEB-INF/cocoon/log4j.xml"/> name="resource" value="/WEB-INF/cocoon/log4j.xml"/> </bean></bean> <!-- Activate Avalon Bridge --> <avalon:bridge <!-- Activate Avalon Bridge --> <avalon:bridge location="/WEB-INF/cocoon.xconf"/>location="/WEB-INF/cocoon.xconf"/>

Page 15: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

What’s in core.xml?

Components <!--+ | Entity resolution catalogs +--> <bean <!--+ | Entity resolution catalogs +--> <bean name="org.xml.sax.EntityResolver" name="org.xml.sax.EntityResolver" class="org.apache.cocoon.core.xml.impl.DefaultEntityResolverclass="org.apache.cocoon.core.xml.impl.DefaultEntityResolver" init-method="init" scope="singleton"> <property " init-method="init" scope="singleton"> <property name="verbosity" value="2"/> </bean>name="verbosity" value="2"/> </bean> <!--+ | DOM XML Parser +--> <bean <!--+ | DOM XML Parser +--> <bean name="org.apache.cocoon.core.xml.DOMParser" name="org.apache.cocoon.core.xml.DOMParser" class="org.apache.cocoon.core.xml.impl.JaxpDOMParser" class="org.apache.cocoon.core.xml.impl.JaxpDOMParser" scope="singleton"> <property name="validate" scope="singleton"> <property name="validate" value="false"/> </bean>value="false"/> </bean>

<!--+ | Entity resolution catalogs +--> <entity-<!--+ | Entity resolution catalogs +--> <entity-resolver logger="core.resolver"> <parameter resolver logger="core.resolver"> <parameter name="catalog" value="WEB-INF/entities/catalog"/> name="catalog" value="WEB-INF/entities/catalog"/> <parameter name="verbosity" value="1"/> </entity-<parameter name="verbosity" value="1"/> </entity-resolver>resolver>

<!--+ | DOM XML Parser +--> <xml-parser <!--+ | DOM XML Parser +--> <xml-parser class="org.apache.excalibur.xml.impl.JaxpParser" class="org.apache.excalibur.xml.impl.JaxpParser" logger="core.xml-parser" pool-max="${xml-parser.pool-logger="core.xml-parser" pool-max="${xml-parser.pool-max}"> <parameter name="validate" value="false"/> max}"> <parameter name="validate" value="false"/> </xml-parser></xml-parser>

<!--+ | Entity resolution catalogs +--> <bean <!--+ | Entity resolution catalogs +--> <bean name="org.xml.sax.EntityResolver" name="org.xml.sax.EntityResolver" class="org.apache.cocoon.core.xml.impl.DefaultEntityResolverclass="org.apache.cocoon.core.xml.impl.DefaultEntityResolver" init-method="init" scope="singleton"> <property " init-method="init" scope="singleton"> <property name="verbosity" value="2"/> </bean>name="verbosity" value="2"/> </bean> <!--+ | DOM XML Parser +--> <bean <!--+ | DOM XML Parser +--> <bean name="org.apache.cocoon.core.xml.DOMParser" name="org.apache.cocoon.core.xml.DOMParser" class="org.apache.cocoon.core.xml.impl.JaxpDOMParser" class="org.apache.cocoon.core.xml.impl.JaxpDOMParser" scope="singleton"> <property name="validate" scope="singleton"> <property name="validate" value="false"/> </bean>value="false"/> </bean>

Deja Vu?

Components are being migrated from Avalon to Spring - from cocoon.xconf into core.xml

Page 16: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

Updating cocoon.xconf

Supports includes for modularity!

Many components are moved to core.xml

More will be moved in upcoming releases.

<!--+ | Classic Cocoon configuration file +--><cocoon <!--+ | Classic Cocoon configuration file +--><cocoon version="2.2"> <!--+ | Include the core roles definitions. version="2.2"> <!--+ | Include the core roles definitions. +--> <include +--> <include src="resource://org/apache/cocoon/cocoon.roles"/> <!-- - src="resource://org/apache/cocoon/cocoon.roles"/> <!-- - Allow other building blocks to supply components - by Allow other building blocks to supply components - by dropping configuration file into the directory. --> <include dropping configuration file into the directory. --> <include dir="/WEB-INF/cocoon/avalon" pattern="*.xconf"/>dir="/WEB-INF/cocoon/avalon" pattern="*.xconf"/> <!-- =========== Sitemap =========== --> <!-- =========== Sitemap =========== --> <sitemap check-reload="yes" file="context://sitemap.xmap" <sitemap check-reload="yes" file="context://sitemap.xmap" logger="sitemap"/>logger="sitemap"/>

Page 17: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

Updating sitemap.xmap

Cocoon 2.1 Sitemaps are completely supported.

No changes necessary!

Springified Generators, etc must be in core.xml (ex: POI)

<map:sitemap xmlns:map="<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0"> <map:components> "> <map:components> <map:generators default="file"> <map:generator <map:generators default="file"> <map:generator name="file" name="file" src="org.apache.cocoon.generation.FileGenerator"/> src="org.apache.cocoon.generation.FileGenerator"/> <map:generator name="jx"<map:generator name="jx" src="org.apache.cocoon.template.JXTemplateGenerator"/> src="org.apache.cocoon.template.JXTemplateGenerator"/> </map:generators> <map:serializers default="html"> </map:generators> <map:serializers default="html"> <map:serializer name="html" <map:serializer name="html" src="org.apache.cocoon.serialization.HTMLSerializer" src="org.apache.cocoon.serialization.HTMLSerializer" mime-type="text/html"> mime-type="text/html"> <encoding>UTF-8</encoding> <encoding>UTF-8</encoding> <doctype- <doctype-public>-//W3C//DTD HTML 4.01 Transitional//EN</doctype-public>-//W3C//DTD HTML 4.01 Transitional//EN</doctype-public> public> <doctype-system><doctype-system>http://www.w3.org/TR/html4/loose.dtdhttp://www.w3.org/TR/html4/loose.dtd</doctype-system> </map:serializer> </map:serializers>

Page 18: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

About Blocks

Where are all xpatch files?

Spring XML files and Cocoon xconf files inside block JARs

Include them or copy, edit, paste

Or add config directory

$ unzip -l target/my-cocoon-webapp/WEB-INF/lib/cocoon-...$ unzip -l target/my-cocoon-webapp/WEB-INF/lib/cocoon-........./META-INF/cocoon/spring/cocoon-some-block.xml/META-INF/cocoon/spring/cocoon-some-block.xml/META-INF/cocoon/avalon/cocoon-some-block.xconf/META-INF/cocoon/avalon/cocoon-some-block.xconf......

$ # Edit core.xml$ # Edit core.xml<import <import resource="classpath://META-INF/cocoon/spring/cocoon-resource="classpath://META-INF/cocoon/spring/cocoon-poi.xml"/>poi.xml"/>

$ # Edit cocoon.xconf$ # Edit cocoon.xconf<include src="resource://META-INF/cocoon/avalon/cocoon-<include src="resource://META-INF/cocoon/avalon/cocoon-template.xconf"/>template.xconf"/>

$ # Or use config directory$ # Or use config directory

Page 19: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

About Forms Block

If you are using resources shipped with forms block

There are couple of references to “servlet:” protocol in resource files

Replace “servlet:” with path to resources

In cocoon-forms-impl:In cocoon-forms-impl:/org/apache/cocoon/forms/resources/js/manifest.js/org/apache/cocoon/forms/resources/js/manifest.js/org/apache/cocoon/forms/resources/js/MultiValueEditorWithSuggestion.js/org/apache/cocoon/forms/resources/js/MultiValueEditorWithSuggestion.js

In cocoon-forms-sample:In cocoon-forms-sample:/src/main/resources/COB-INF/resources/forms-samples-styling.xsl/src/main/resources/COB-INF/resources/forms-samples-styling.xsl......

Page 20: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

Config Directory

Sitemap can have

Properties

Sitemap level components

Sitemap level Spring beans

$ find . -type f$ find . -type f./sitemap.xmap./sitemap.xmap./config/avalon/custom.xconf./config/avalon/custom.xconf./config/spring/custom.xml./config/spring/custom.xml./config/properties/custom.properties./config/properties/custom.properties......

$ # Example: Deploy POI Spring components into sitemap$ # Example: Deploy POI Spring components into sitemap$ unzip -p WEB-INF/lib/cocoon-poi-impl-1.0.0-SNAPSHOT.jar $ unzip -p WEB-INF/lib/cocoon-poi-impl-1.0.0-SNAPSHOT.jar META-INF/cocoon/spring/cocoon-poi.xml > META-INF/cocoon/spring/cocoon-poi.xml > config/spring/cocoon-poi.xmlconfig/spring/cocoon-poi.xml

Page 21: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

web.xml

applicationContext.xml

core.xml

cocoon.xconf

sitemap.xmap

WEB-INF/lib

Updating Webapp

Page 22: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

Demo

mybook ~/Projects/ReveryCodes/MyCocoonWebapp $ ./run.sh 2007-09-24 23:58:36.326::INFO: Logging to mybook ~/Projects/ReveryCodes/MyCocoonWebapp $ ./run.sh 2007-09-24 23:58:36.326::INFO: Logging to STDERR via org.mortbay.log.StdErrLog2007-09-24 23:58:37.519::INFO: jetty-6.1.52007-09-24 STDERR via org.mortbay.log.StdErrLog2007-09-24 23:58:37.519::INFO: jetty-6.1.52007-09-24 23:58:37.905:/:INFO: Initializing Spring root WebApplicationContextlog4j:WARN No appenders could be 23:58:37.905:/:INFO: Initializing Spring root WebApplicationContextlog4j:WARN No appenders could be found for logger (org.springframework.found for logger (org.springframework.web.context.ContextLoader).log4j:WARN Please initialize the log4j ).log4j:WARN Please initialize the log4j system properly.2007-09-24 23:58:38.666:/:INFO: Apache Cocoon Spring Configurator v1.0.1-SNAPSHOT is system properly.2007-09-24 23:58:38.666:/:INFO: Apache Cocoon Spring Configurator v1.0.1-SNAPSHOT is running in mode 'prod'.2007-09-24 23:58:39.785::INFO: WebApp@13222953 at running in mode 'prod'.2007-09-24 23:58:39.785::INFO: WebApp@13222953 at http://0.0.0.0:8888http://0.0.0.0:8888/cocoo/cocoon2007-09-24 23:58:39.797::INFO: Started [email protected]@0.0.0.0:8888:8888

Page 23: Using Cocoon 2.2 The Classic Way Vadim Gritsenko -  - //blog.reverycodes.com/g

Questions?

Ready to use application template is available at:http://reverycodes.com/gt/MyCocoonWebapp.zip

Includes Jetty configuration, build and run scripts.