Date: 2005-02-16T01:52:37 Editor: BastianBowe Wiki: Cocoon Wiki Page: CocoonAppAsJSR168Portlet URL: http://wiki.apache.org/cocoon/CocoonAppAsJSR168Portlet
solved outstanding link issue Change Log: ------------------------------------------------------------------------------ @@ -1,9 +1,6 @@ === Content === This document describes how to run a existing cocoon application as a -JSR168 portlet. The following example illustrates how to deploy the -cocoon distribution as a JSR168 portlet in Pluto. Unfortunately the -only thing I managed so far is to display one page of the cocoon -app. Navigation inside the app is not possible (see [#linkproblem below]). It should +JSR168 portlet. The following example illustrates how to deploy a subapplication as a JSR168 portlet in Pluto. It should work with any JSR 168 portlet Container. === Tested on === @@ -20,9 +17,15 @@ 1. copied blocks.properties to `local.blocks.properties` and disabled the scratchpad and cron (this one caused a problem on my configuration, but you might leave that step out) blocks - 1. created a `portlet.xml` in `<COCOON_HOME>/src/webapp/WEB-INF` by using `<COCOON_HOME>/src/blocks/portal/WEB-INF/portlet.xml` as a base and removed the first portlet node so that you only keep the second `portlet` node (`portlet-name` = `CocoonPortlet`). You're might be interested in changing the `init-param` `servlet-path` e.g. to the value `/` to see the output you normally get when opening http://localhost:8080/cocoon/ + 1. created a `portlet.xml` in `<COCOON_HOME>/src/webapp/WEB-INF` by using `<COCOON_HOME>/src/blocks/portal/WEB-INF/portlet.xml` as a base and removed the first portlet node so that you only keep the second `portlet` node (`portlet-name` = `CocoonPortlet`). You're might be interested in changing the `init-param` `servlet-path` e.g. to the value `/yourCocoonSubapp` to see the output you normally get when opening http://localhost:8080/cocoon/yourCocoonSubapp if you have a subapp in that directory. - 1. built `cocoon war` from source + 1. modify `<COCOON_HOME>/src/webapp/WEB-INF/cocoon.xconf` to include the following input module {{{ +<component-instance + class="org.apache.cocoon.components.modules.input.PortletURLModule" + logger="core.modules.mapper" name="portlet"/> +}}} it will be used by the LinkRewriterTransformer described [#linkproblem below]. + + 1. built cocoon war (`build war`) from source 1. deleted content of `<TOMCAT_HOME>/common/endorsed` @@ -38,12 +41,12 @@ 1. you can savely delete `portlet-api-1.0.jar` (optional) - 1. modified `<PLUTO_HOME>/WEB-INF/data/portletcontexts.txt` {{{ + 1. modified `<TOMCAT_HOME>/webapps/pluto/WEB-INF/data/portletcontexts.txt` {{{ /testsuite /cocoon }}} - 1. modified `<PLUTO_HOME>/WEB-INF/data/portletentityregistry.xml` to include the following inside the `<portlet-entity-registry>` node:{{{ + 1. modified `<TOMCAT_HOME>/webapps/pluto/WEB-INF/data/portletentityregistry.xml` to include the following inside the `<portlet-entity-registry>` node:{{{ <application id="9"> <definition-id>cocoon</definition-id> <portlet id="1"> @@ -51,7 +54,7 @@ </portlet> </application> }}} - 1. modified `<PLUTO_HOME>/WEB-INF/data/pageregistry.xml` to include the following inside of the `<portal>` node: {{{ + 1. modified `<TOMCAT_HOME>/webapps/pluto/WEB-INF/data/pageregistry.xml` to include the following inside of the `<portal>` node: {{{ <fragment name="cocoon" type="page"> <navigation> <title>Cocoon </title> @@ -71,8 +74,27 @@ Your cocoon app should now be available as a portlet under http://localhost:8080/pluto/portal/cocoon -[[Anchor(linkproblem)]]Anyway, clicking on a link in that portlet (assuming you've set -`servlet-path`'s value to `/`) doesn't work. The link to "samples" -points to http://localhost:8080/pluto/portal/samples. Pointing -manually to http://localhost:8080/pluto/portal/cocoon/samples is the -same as http://localhost:8080/pluto/portal/cocoon. +[[Anchor(linkproblem)]]Anyway, clicking on a link in that portlet won't work. You have to modify the hrefs of you links to use a scheme that is supported by the above defined portlet input module. You then have to transform your links using the LinkRewriterTransformer. The required scheme is described in the [http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/components/modules/input/PortletURLModule.html api doc of the module]. So instead of using `<a href="link.html">link</a>` you have to write `<a href="portlet:render:link.html">link</a>`. You can add the Transformer to your sitemap like this: {{{ +<map:components> + <map:transformer name="linkrewriter" + src="org.apache.cocoon.transformation.LinkRewriterTransformer"> + <link-attrs>href src</link-attrs> + <schemes>portlet</schemes> + <input-module name="portlet"/> + </map:transformer> + </map:transformers> +</map:components> +}}} Then modify your pipeline as follows to actually use the linkrewriter: {{{ +<map:match pattern=""> + <map:read src="cocoon:/index.html"/> +</map:match> + +<map:match pattern="*.html"> + <map:generate src="content/{1}.xml"/> + <map:transform type="linkrewriter"/> + <map:transform src="style/xsl/page2html.xsl"/> + <map:serialize type="html"/> +</map:match> +}}} + +I've not tried to use CForms but I think VadimGritsenko has a solution for this in [http://blog.reverycodes.com/archives/000018.html a blog entry].
