You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Colin Paul Adams <co...@colina.demon.co.uk> on 2004/07/26 07:27:37 UTC

Re: Request headers

(switching to the developers list)

>>>>> "Ralph" == Ralph Goers <Ra...@dslextreme.com> writes:

    Ralph> What about the HeaderSelector?

Yes.
I couldn't find it at first, as it is not listed in the navigation
pane of the selectors page of the user manual.

But it appears not to be exactly what I want.
Looking at the source code, it implements Selector.

But I want to be able to select whether or not the "Accept" header
contains the string "application/xhtml+xml" (so as to be able to do
some limited content negotiation).

So I think I need a version of header selector that implements
NamedPatternsSelector, or AbstractRegexpSelector.

I think I could easily implement such a selector. I could call it
ContentTypeSelector, specifically matching on the "Accept" header, but
perhaps something more general might be useful. What do people think?
-- 
Colin Paul Adams
Preston Lancashire

Re: Request headers

Posted by Colin Paul Adams <co...@colina.demon.co.uk>.
>>>>> "Ugo" == Ugo Cei <ug...@apache.org> writes:

    Ugo> Il giorno 26/lug/04, alle 15:53, bernhard huber ha scritto:
    Ugo> Colin Paul Adams wrote:
    >>>>> <pattern name="xhtml">^.*application/xhtml\+xml.*$</pattern>
    Ugo> Wouldn't <pattern
    Ugo> name="xhtml">application/xhtml\+xml</pattern> have the same
    Ugo> effect? I think it should.
    >>> Yes - it does.
    >>> 
    >> I was checking the header accept sent by mozilla, it says:
    >> accept =
    >> text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/
    >> plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
    >> 
    >> thus checking if application/xml is available you need some
    >> sort of RE, that's the reason for using plain HeaderSelector is
    >> a bit tedious.

    Ugo> Of course. But the regexp "application/xhtml\+xml" should
    Ugo> match everything that "^.*application/xhtml\+xml.*$" matches,
    Ugo> unless something is escaping me. The former is simpler and
    Ugo> has the same effect.

The only reason the ^.* and .*$ were there, was I was having problems
getting the thing to work, so I was playing around with various REs.

Now, I'm just having problems with the test case, but I'll fathom it
out sometime tomorrow.
-- 
Colin Paul Adams
Preston Lancashire

Re: Request headers

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 26/lug/04, alle 15:53, bernhard huber ha scritto:

>>     Ugo> Colin Paul Adams wrote:
>>>> <pattern name="xhtml">^.*application/xhtml\+xml.*$</pattern>
>>     Ugo> Wouldn't
>>     Ugo>   	<pattern name="xhtml">application/xhtml\+xml</pattern>
>>     Ugo> have the same effect? I think it should.
>> Yes - it does.
>>
> I was checking the header accept sent by mozilla, it says:
> accept =
> text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/ 
> plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
>
> thus checking if application/xml is available you need some sort of RE,
> that's the reason for using plain HeaderSelector is a bit tedious.

Of course. But the regexp "application/xhtml\+xml" should match  
everything that  "^.*application/xhtml\+xml.*$" matches, unless  
something is escaping me. The former is simpler and has the same  
effect.

	Ugo

-- 
Ugo Cei - http://beblogging.com/

Re: Request headers

Posted by bernhard huber <be...@gmx.at>.
> 
>     >> How do I run the test case?
>     bernhard> you have to options
> 
>     bernhard> 1 - run "build test" runs all testcases, this shall run
>     bernhard> your test, too.
> 
> 
> I'm getting there.
> But one thing I can't work - out - and that is where I define the
> selector for the test. I think it must be in a sitemap.xmap somewhere,
> but I can't find out where.

Well, you define the selector for the test in xtest file.

Your testcase extends SitemapComponentTestCase, and
SitemapCompontentTestCase extends ExcaliburTestCase.
ExcaliburTestCase will load the xtest file having the same basename as
the testcase class.
Thus you need RegexpHeaderSelector.xtest, for your
RegexpHeaderSelectorTestCase.java

In the xtest file you define:
...
  <selectors logger="test">
   <component-instance 
     class="org.apache.cocoon.selection.RegexpHeaderSelector" 
     name="regexpheader">

     <!-- configuration your selector i assume: define the name of
       the header attribute name
     -->
      <header-name>accept</header-name>
    </component-instance>
  </selectors>
...
The snippet is taken from HeaderSelectorTestCase.xtest.

Now in your test case you can use regexpheader for getting the 
RegexpHeaderSelector.

i hope this short explanation helps you.

regards bernhard

-- 
NEU: WLAN-Router f�r 0,- EUR* - auch f�r DSL-Wechsler!
GMX DSL = superg�nstig & kabellos http://www.gmx.net/de/go/dsl


Re: Request headers

Posted by Colin Paul Adams <co...@colina.demon.co.uk>.
>>>>> "bernhard" == bernhard huber <be...@gmx.at> writes:

    >> How do I run the test case?
    bernhard> you have to options

    bernhard> 1 - run "build test" runs all testcases, this shall run
    bernhard> your test, too.


I'm getting there.
But one thing I can't work - out - and that is where I define the
selector for the test. I think it must be in a sitemap.xmap somewhere,
but I can't find out where.
-- 
Colin Paul Adams
Preston Lancashire

Re: Request headers

Posted by bernhard huber <be...@gmx.at>.
> How do I run the test case?
you have to options

1 - run "build test" runs all testcases, this shall run your test, too.
You may want to adopt tools/targets/test-build.xml, target junit-tests
decreasing the number of testcases

2 - your IDE allows to run a single the testcase, or single main-class
Option 2 works fine using eclipse, or netbeans

regards bernhard

-- 
250 MB Mailbox, 100 FreeSMS/Monat, 1000 MB Online-Festplatte
Jetzt GMX TopMail kostenlos testen http://www.gmx.net/de/go/topmail


Re: Request headers

Posted by Colin Paul Adams <co...@colina.demon.co.uk>.
>>>>> "bernhard" == bernhard huber <be...@gmx.at> writes:


    bernhard> Copy HeaderSelectorTestCase.java to
    bernhard> RegexpHeaderSelectorTestCase.java, dito for
    bernhard> RegexpHeaderSelectorTestCase.xtest.  Adopt
    bernhard> RegexpHeaderSelectorTestCase.xtest replacing all
    bernhard> HeaderSelector occurences by RegexpHeaderSelector Adopt
    bernhard> RegexpHeaderSelectorTestCase.java to your header
    bernhard> testings

How do I run the test case?
-- 
Colin Paul Adams
Preston Lancashire

Re: Request headers

Posted by bernhard huber <be...@gmx.at>.
>     Ugo> Colin Paul Adams wrote:
>     >> <pattern name="xhtml">^.*application/xhtml\+xml.*$</pattern>
>     Ugo> Wouldn't 
>     Ugo>   	<pattern name="xhtml">application/xhtml\+xml</pattern>
>     Ugo> have the same effect? I think it should.
> Yes - it does.
> 
I was checking the header accept sent by mozilla, it says:
accept =
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1

thus checking if application/xml is available you need some sort of RE,
that's the reason for using plain HeaderSelector is a bit tedious.

for the documentation, and testcase templete you will probably
need CVS access.
documentation template :
src/documentation/xdocs/userdocs/selectors/header-selector.xml,
or src/documentation/xdocs/userdocs/selectors/selector.template.

testcase template :
src/test/org/apache/cocoon/selection/HeaderSelectorTestCase.java,
src/test/org/apache/cocoon/selection/HeaderSelectorTestCase.xtest,

Copy HeaderSelectorTestCase.java to RegexpHeaderSelectorTestCase.java, dito
for RegexpHeaderSelectorTestCase.xtest.
Adopt RegexpHeaderSelectorTestCase.xtest replacing all HeaderSelector
occurences by RegexpHeaderSelector
Adopt RegexpHeaderSelectorTestCase.java to your header testings

Add both docu + testcase to the bugzilla

regards bernhard

-- 
250 MB Mailbox, 100 FreeSMS/Monat, 1000 MB Online-Festplatte
Jetzt GMX TopMail kostenlos testen http://www.gmx.net/de/go/topmail


Re: Request headers

Posted by Ugo Cei <u....@cbim.it>.
Colin Paul Adams wrote:
>     Ugo> It would be nice if you could provide unit tests for the
>     Ugo> selector, too :-).
> 
> Well, you'll have to tell me what this involves.

Take inspiration from 
src/test/org/apache/cocoon/selection/HeaderSelectorTestCase.java for 
instance.

	Ugo


Re: Request headers

Posted by Colin Paul Adams <co...@colina.demon.co.uk>.
>>>>> "Ugo" == Ugo Cei <u....@cbim.it> writes:

    Ugo> Colin Paul Adams wrote:
    >> <pattern name="xhtml">^.*application/xhtml\+xml.*$</pattern>

    Ugo> Wouldn't

    Ugo>   	<pattern name="xhtml">application/xhtml\+xml</pattern>

    Ugo> have the same effect? I think it should.

Yes - it does.

    >> This I think is useful. How can I contribute it to Cocoon (I've
    >> only written the java class - I don't know where I should add
    >> documentation).

    Ugo> Open an issue on Bugzilla and attach the sources. For the
    Ugo> docs, provide something similar to the files in
    Ugo> src/documentation/xdocs/userdocs/selectors.

OK.

    Ugo> It would be nice if you could provide unit tests for the
    Ugo> selector, too :-).

Well, you'll have to tell me what this involves.
-- 
Colin Paul Adams
Preston Lancashire

Re: Request headers

Posted by Ugo Cei <u....@cbim.it>.
Colin Paul Adams wrote:
> 	<pattern name="xhtml">^.*application/xhtml\+xml.*$</pattern>

Wouldn't

  	<pattern name="xhtml">application/xhtml\+xml</pattern>

have the same effect? I think it should.

> This I think is useful. How can I contribute it to Cocoon (I've only
> written the java class - I don't know where I should add documentation).

Open an issue on Bugzilla and attach the sources. For the docs, provide 
something similar to the files in 
src/documentation/xdocs/userdocs/selectors.

It would be nice if you could provide unit tests for the selector, too :-).

	Ugo


Re: Request headers

Posted by Colin Paul Adams <co...@colina.demon.co.uk>.
>>>>> "Colin" == Colin Paul Adams <co...@colina.demon.co.uk> writes:

    Colin> I think I'll write a RegexpHeaderSelector.

I've done this, and it works to the limit of my testing - namely one
example:

     <map:selector name="content-type" src="org.apache.cocoon.selection.RegexpHeaderSelector">
	<pattern name="xhtml">^.*application/xhtml\+xml.*$</pattern>
	<header-name>accept</header-name>
      </map:selector>

     <map:match pattern="test">
	<map:select type="content-type">
	  <map:when test="xhtml">
	    <map:read src="test.xhtml" mime-type="application/xhtml+xml"/>
	  </map:when>
	  <map:otherwise>
	    <map:read src="test.html" mime-type="text/html"/>
	  </map:otherwise>
	</map:select>
      </map:match>

Mozilla and Opera display test.xhtml whereas Lynx and Konqueror
display test.html. I don't have MSIE, but I've asked a friend to test
it, and I have no doubt it will display test.html.

This I think is useful. How can I contribute it to Cocoon (I've only
written the java class - I don't know where I should add documentation).
-- 
Colin Paul Adams
Preston Lancashire

Re: Request headers

Posted by Colin Paul Adams <co...@colina.demon.co.uk>.
>>>>> "Bernhard" == bernhard huber <be...@gmx.at> writes:

    Bernhard> hi, what about using this kind of snippet?

    Bernhard> <map:select type="header"> <map:parameter
    Bernhard> name="header-name" value="accept"/> <map:when
    Bernhard> test="application/xhtml+xml"> ...  </map:when>
    Bernhard> <map:otherwise> ...  </map:otherwise> </map:select>

I don't think so.

    Bernhard> you may want to read the wiki, too, see
    Bernhard> http://wiki.apache.org/cocoon/HeaderSelector

I read it. And it says you can only match on the value of the header,
whereas I want to check if the header contains the string or not.

I think I'll write a RegexpHeaderSelector.
-- 
Colin Paul Adams
Preston Lancashire

Re: Request headers

Posted by bernhard huber <be...@gmx.at>.
hi,
what about using this kind of snippet?

<map:select type="header">
    <map:parameter name="header-name" value="accept"/>
    <map:when test="application/xhtml+xml">
      ...
    </map:when>
    <map:otherwise>
      ...
    </map:otherwise>
</map:select>

you may want to read the wiki, too,
see http://wiki.apache.org/cocoon/HeaderSelector

regards bernhard

> (switching to the developers list)
> 
> >>>>> "Ralph" == Ralph Goers <Ra...@dslextreme.com> writes:
> 
>     Ralph> What about the HeaderSelector?
> 
> Yes.
> I couldn't find it at first, as it is not listed in the navigation
> pane of the selectors page of the user manual.
> 
> But it appears not to be exactly what I want.
> Looking at the source code, it implements Selector.
> 
> But I want to be able to select whether or not the "Accept" header
> contains the string "application/xhtml+xml" (so as to be able to do
> some limited content negotiation).
> 
> So I think I need a version of header selector that implements
> NamedPatternsSelector, or AbstractRegexpSelector.
> 
> I think I could easily implement such a selector. I could call it
> ContentTypeSelector, specifically matching on the "Accept" header, but
> perhaps something more general might be useful. What do people think?
> -- 
> Colin Paul Adams
> Preston Lancashire
> 

-- 
250 MB Mailbox, 100 FreeSMS/Monat, 1000 MB Online-Festplatte
Jetzt GMX TopMail kostenlos testen http://www.gmx.net/de/go/topmail