You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Hugh Sparks <hu...@csparks.com> on 2007/10/10 10:43:16 UTC

Cocoon 2.2 - Block name required in file path?

This is a 2.1 to 2.2 migration issue.

I created a simple c2 block using:

 mvn archetype:create \
                -DarchetypeGroupId=org.apache.cocoon \
                -DarchetypeArtifactId=cocoon-22-archetype-block \
                -DarchetypeVersion=1.0.0-RC3-SNAPSHOT \
                -DgroupId=csparks.com \
                -DartifactId=AAQuotes

Then I modified it to do an example I have working in
cocoon 2.1: a simple application that displays a
randomly selected quotation and image.

The quotations work as expected, but the path to the
images in the result.jx template (shown below) requires
the name of my block in the path:

        <img src="AAQuotes/${imageNumber}.gif"/>

I ported this example from a working cocoon 2.1.X version
and the image tag was simply:

        <img src="${imageNumber}.gif"/>

Why is the block name required in the path to fetch the image
when using cocoon 2.2? I would expect the location of the sitemap
to be the root for finding files. If I omit the block name, I
get an error of the form:

    javax.servlet.ServletException: No block for /148.gif

I have quite a bit of work to move from cocoon 2.1 to 2.2,
it would be nice if this behaviour could be configured to
go away...

Thanks for any insights...

-Hugh Sparks, hugh@csparks.com


*******************************************************
An outline of the block:

Block directory AAQuotes\src\main\resources\COB-INF:

        images/
                1.gif
                ...
                127.gif
        quotes.xml
        sitemap.xmap
        result.jx

Sitemap.xmap:

        ...

        <map:flow language="javascript">
                <map:script src="flowscript.js"/>
        </map:flow>

        <map:pipelines>
        <map:pipeline>

        <map:match pattern="">
                <map:call function="startup"/>
        </map:match>

        <map:match pattern="*.jx">
                <map:generate type="jx" src="{1}.jx"/>
                <map:transform type="xinclude"/>
                <map:serialize type="html"/>
        </map:match>

        <map:match pattern="*.gif">
                <map:read mime-type="image/gif" src="images/{1}.gif"/>
        </map:match>

        ...

flowscript.js:

        function startup()
        {        var q = Math.floor( Math.random() * numberOfQuotations + 
1).toString() ;
                  var m = Math.floor( Math.random() * numberOfImages + 
1).toString() ;
                  cocoon.sendPage("result.jx", {quoteNumber: q, imageNumber: 
m}) ;
        }

result.jx:

        <?xml version="1.0"?>

        <html xmlns:xi="http://www.w3.org/2001/XInclude">

        <head>
                <title>Quotations</title>
                <style>
                        h3  { text-align: center }
                        img { padding-left: 5mm }
                        p   { text-align: center }
                </style>
        </head>

        <body>
                <div style="width: 8cm">
                        <h3>Quotations</h3>
                        <img src="AAQuotes/${imageNumber}.gif"/>
                        <p><i>
                                <xi:include
                                        href="quotes.xml"
                                        xpointer="xpointer(/quotes/quote[${quoteNumber}])"
                                />
                        </i></p>
                </div>
        </body>

        </html>

*******************************************************


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Cocoon 2.2 - Block name required in file path?

Posted by Grzegorz Kossakowski <gk...@apache.org>.
Grzegorz Kossakowski pisze:
> Hugh Sparks pisze:
>> This is a 2.1 to 2.2 migration issue.
>>
>> I created a simple c2 block using:
>>
>> mvn archetype:create \
>>                -DarchetypeGroupId=org.apache.cocoon \
>>                -DarchetypeArtifactId=cocoon-22-archetype-block \
>>                -DarchetypeVersion=1.0.0-RC3-SNAPSHOT \
>>                -DgroupId=csparks.com \
>>                -DartifactId=AAQuotes
>>
>> Then I modified it to do an example I have working in
>> cocoon 2.1: a simple application that displays a
>> randomly selected quotation and image.
>>
>> The quotations work as expected, but the path to the
>> images in the result.jx template (shown below) requires
>> the name of my block in the path:
>>
>>        <img src="AAQuotes/${imageNumber}.gif"/>
>>
>> I ported this example from a working cocoon 2.1.X version
>> and the image tag was simply:
>>
>>        <img src="${imageNumber}.gif"/>
>>
>> Why is the block name required in the path to fetch the image
>> when using cocoon 2.2? I would expect the location of the sitemap
>> to be the root for finding files. If I omit the block name, I
>> get an error of the form:
>>
>>    javax.servlet.ServletException: No block for /148.gif
> 
> I wonder why request for "/148.gif" ever happens. I mean, isn't a browser supposed to make request
> relatively to the path of html document? If so, the mount path of a block should not be making any
> problems at all.
> 
> Another comment is that making a block simply mounted at "/" AND basing on this setting when
> developing a block is not a good idea for two reasons:
> 1. Mount path of block can be changed externally (to the block) by using Cocoon Spring Configurator
> and suitable property
> 2. The idea of block is that it is reusable unit that has it's own URI space for living. This design
> decision makes it possible to extend and compose blocks.

Oups, hit the "send" button too early. I wanted to say, that if you need an absolute path of
resource in a block you should use "servlet: protocol + servletLinkRewriter" combo. Forms block
makes an extensive use of this technique and you can have a look at this document[1] to get an idea
how it works.

I would only add that if you need to reference a resource from current (your own) block you can use
this syntax:
servlet:/path/to/your/resource (ommitting the part that contains block's name)

[1] http://cocoon.apache.org/2.2/blocks/forms/1.0/1351_1_1.html

-- 
Grzegorz Kossakowski
Committer and PMC Member of Apache Cocoon
http://reflectingonthevicissitudes.wordpress.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Cocoon 2.2 - Block name required in file path?

Posted by Grzegorz Kossakowski <gk...@apache.org>.
Hugh Sparks pisze:
> This is a 2.1 to 2.2 migration issue.
> 
> I created a simple c2 block using:
> 
> mvn archetype:create \
>                -DarchetypeGroupId=org.apache.cocoon \
>                -DarchetypeArtifactId=cocoon-22-archetype-block \
>                -DarchetypeVersion=1.0.0-RC3-SNAPSHOT \
>                -DgroupId=csparks.com \
>                -DartifactId=AAQuotes
> 
> Then I modified it to do an example I have working in
> cocoon 2.1: a simple application that displays a
> randomly selected quotation and image.
> 
> The quotations work as expected, but the path to the
> images in the result.jx template (shown below) requires
> the name of my block in the path:
> 
>        <img src="AAQuotes/${imageNumber}.gif"/>
> 
> I ported this example from a working cocoon 2.1.X version
> and the image tag was simply:
> 
>        <img src="${imageNumber}.gif"/>
> 
> Why is the block name required in the path to fetch the image
> when using cocoon 2.2? I would expect the location of the sitemap
> to be the root for finding files. If I omit the block name, I
> get an error of the form:
> 
>    javax.servlet.ServletException: No block for /148.gif

I wonder why request for "/148.gif" ever happens. I mean, isn't a browser supposed to make request
relatively to the path of html document? If so, the mount path of a block should not be making any
problems at all.

Another comment is that making a block simply mounted at "/" AND basing on this setting when
developing a block is not a good idea for two reasons:
1. Mount path of block can be changed externally (to the block) by using Cocoon Spring Configurator
and suitable property
2. The idea of block is that it is reusable unit that has it's own URI space for living. This design
decision makes it possible to extend and compose blocks.

-- 
Grzegorz Kossakowski
Committer and PMC Member of Apache Cocoon
http://reflectingonthevicissitudes.wordpress.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Cocoon 2.2 - Block name required in file path?

Posted by Hanne Moa <ha...@uninett.no>.
Hugh Sparks wrote:
>> From: "Joerg Heinicke" <jo...@gmx.de>
>>
>> I didn't know it but I saw today the thread about "mounting a block at
>> root level". So in case you missed it:
>>
>> http://marc.info/?t=119202558600004&r=1&w=4
> 
> The information at that link 

... which is the bottom of <http://cocoon.apache.org/2.2/1362_1_1.html>.
The file mentioned there, block.xml, does not exist...

> is no longer accurate for Cocoon 2.2,
> but it was close enough to help me fix my problem.
> 
> In case others would like to mount a block at the root level, the correct
> procedure is to edit the file:
> 
>    myBlock1\src\main\resources\META-INF\cocoon\spring\servlet-service.xml
> 
> This file contains an element:
> 
> <bean id="mysite.com.myBlock1.service" class="org.apache.cocoon.sitemap.SitemapServlet">
>     <servlet:context mount-path="myBlock1" context-path="blockcontext:/myBlock1/"/>
> </bean>
> 
> To mount the block at the root level, you change the mount-path
> attribute in the
> servlet:context element to be an empty string:

Changing mount-path to either of "" or "/" works, actually.


HM

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Cocoon 2.2 - Block name required in file path?

Posted by Hugh Sparks <hu...@csparks.com>.
> From: "Joerg Heinicke" <jo...@gmx.de>
>
> I didn't know it but I saw today the thread about "mounting a block at 
> root level". So in case you missed it:
>
> http://marc.info/?t=119202558600004&r=1&w=4

The information at that link is no longer accurate for Cocoon 2.2,
but it was close enough to help me fix my problem.

In case others would like to mount a block at the root level, the correct
procedure is to edit the file:

    myBlock1\src\main\resources\META-INF\cocoon\spring\servlet-service.xml

This file contains an element:

    <bean id="mysite.com.myBlock1.service" 
class="org.apache.cocoon.sitemap.SitemapServlet">
        <servlet:context mount-path="myBlock1" 
context-path="blockcontext:/myBlock1/"/>
    </bean>

To mount the block at the root level, you change the mount-path attribute in 
the
servlet:context element to be an empty string:

Thanks very much!

-Hugh Sparks



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Cocoon 2.2 - Block name required in file path?

Posted by Joerg Heinicke <jo...@gmx.de>.
On 10.10.2007 4:43 Uhr, Hugh Sparks wrote:

> The quotations work as expected, but the path to the
> images in the result.jx template (shown below) requires
> the name of my block in the path:

I didn't know it but I saw today the thread about "mounting a block at 
root level". So in case you missed it:
http://marc.info/?t=119202031400001&r=1&w=4
http://marc.info/?t=119202558600004&r=1&w=4

Joerg

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org