hussayn pisze:
Hi;
I working on a project, for which i want to use cocon-2.2. In parts of my
work, i want to utilize dojo. But i hesitate to also start learning
cocoon-forms in first place. So i consider to just use Dojo "besides"
cocoon itself, but inside my cocoon-based application. So my questions are:
- Is it better to download Dojo and place it into a subdirectory inside my
cocon-block,
or is it better to get it into my block via dependency entries in the .pom
file of my block ?
The best would be probably to create separate block that will contain Dojo distribution and serve
dojo resources from there.
Then you could depend on that block from your main block and have things
separated nicely.
Actually, this is already done in Cocoon, we have cocoon-ajax-block[1].
- Once the dojo-distribution is placed into a subfolder of my block,
how can i then access the dojo components inside my cocoon-generated pages ?
(How do i have to write the url's to the dojo-scripts?)
The best idea would be to use servlet: protocol for this purpose the same way as Ajax block samples
are doing it.
For example, there is a page[2] in Ajax samples that wants to reference dojo.js, then it will use
following construct:
<script type="text/javascript"
src="servlet:ajax:/resource/external/dojo/dojo.js"/>
This should be read as "I want resource from servlet (thus servlet: protocol is used) that I'm
connected to using connection name "ajax" and resources path is /resource/external/dojo/dojo.js".
Now let's have a look at connections definitions[3]:
<bean name="org.apache.cocoon.ajax.sample.servlet"
class="org.apache.cocoon.sitemap.SitemapServlet">
<servlet:context mount-path="/samples/ajax"
context-path="blockcontext:/cocoon-ajax-sample/">
<servlet:connections>
<entry key="ajax" value-ref="org.apache.cocoon.ajax.impl.servlet"/>
<entry key="style-default"
value-ref="org.apache.cocoon.samples.style.default.servlet"/>
</servlet:connections>
</servlet:context>
</bean>
As you can see, "ajax" connection refers to org.apache.cocoon.ajax.impl.servlet which is defined in
cocoon-ajax-impl block. Let's have a look at it's definition[4]:
<bean name="org.apache.cocoon.ajax.impl.servlet"
class="org.apache.cocoon.sitemap.SitemapServlet">
<servlet:context mount-path="/cocoon-ajax-impl"
context-path="blockcontext:/cocoon-ajax-impl/"/>
</bean>
The most important thing here is that this servlet is instance of SitemapServlet which means that
resources loading is handled by sitemap in cocoon-ajax-impl block.
So to summarize: when you say servlet:ajax:/resource/external/dojo/dojo.js you ask sitemap defined
in cocoon-ajax-impl block to serve this resource.
Of course, browsers don't understand servlet: protocol so it must be resolved to proper URL. This is
done by servletLinkRewriter transformer in sitemap[5] of Ajax sample block:
<map:match pattern="*.html">
<map:generate type="jx" src="{1}.xml" />
<map:call resource="simple-page2html" />
<map:transform type="servletLinkRewriter" label="content" />
<map:serialize type="html" />
</map:match>
This is the cleanest way to do it even if at the beginning may sound little bit complicated but
using this technique you can be sure that URLs are always correct.
- Do i have to add a sitemap entry for the dojo-subfolder, which simply
returns erverything under the dojo-folder verbatim ? Or is there another
method available, e.g. tell cocoon to serve parts of the directory structure
like a web server wihtout further processing ?
Look at cocoon-ajax-impl block. It uses map:read along with pattern matching. This way you can serve
everything from the folder you choose.
Actually, in cocoon-ajax-impl resources are being served using resource: protocol (so they are read
from classpath). I suggest to just put Dojo resources into resource/external directory of your block
so you can use already defined pipeline for serving this resources.
I just am completely unsure, what would be the best practice approach. So
some hints would be very much appreciated. a small fully working example
would also help a lot.
I hope that my explanation help you a little bit.
[1]
http://svn.eu.apache.org/viewvc/cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/
[2]
http://svn.eu.apache.org/viewvc/cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-sample/src/main/resources/COB-INF/linked-updater.xml?view=markup
[3]
http://svn.eu.apache.org/viewvc/cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-sample/src/main/resources/META-INF/cocoon/spring/cocoon-ajax-sample-blockServlet.xml?view=markup
[4]
http://svn.eu.apache.org/viewvc/cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/META-INF/cocoon/spring/cocoon-ajax-impl-blockServlet.xml?view=markup
[5]
http://svn.eu.apache.org/viewvc/cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-sample/src/main/resources/COB-INF/sitemap.xmap?view=markup
--
Grzegorz Kossakowski
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]