cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Giacomo Pati <giac...@apache.ch>
Subject Re: Matchers and Selectors (was Re: Better and Better and RT)
Date Thu, 09 Nov 2000 22:53:10 GMT
Marcus Crafter wrote:
> 
> Hi Giacomo,
> 
> On Sun, 5 Nov 2000, Giacomo Pati wrote:
> 
> > Ross Burton wrote:
> > >
> > > Berin Loritsch wrote:
> > > >
> > > > I envision the following additional selectors to be vital
> > > > to any site:
> > > >
> > > > ParameterSelector (select things pased on HTTP parameters)
> > > > AcceptsSelector (send PNG to browsers that accept it...)
> >
> > Take into account that a Selector chooses between multiple possibilities
> > (and a default one if neither choosen) whereas a Matcher returns a List
> > (or maybe we should change that to a Map) of values you can use for
> > substitution in src attributes of Generators and Transformers. I can
> > imaging to have a Matcher that select values out of the environment
> > objects (Request/Response/Session/Context) and a corresponsing Selector
> > which chooses some component to generate the view expected. This way you
> > can still refer to the values the Matcher has evaluated.
> >
> >   <match type="uri" pattern="myuri">
> >     <match type="value-extractor" pattern="unused">    <-----+
> >       <select type="value-selector">                         !
> >         <when test="first">                                  !
> >           <generate type="file" src="mydir/first/{value}/> --+
> >         </when>
> >         ...
> >       </select>
> >     </match>
> >   </match>
> >
> > I really think that we must think in terms of "team play" between
> > components. What do you think about that?
> 
>         I like the idea of having the selector working with the matcher. But I
>         think I'm getting myself confused between the uses of matchers and
>         selectors. :-(
> 
>         My understanding is that a 'matcher' is used to match something
>         against the current request and a specific parameter passed to the
>         matcher. 

The concept of a Matcher is much more general. You can easily write a
Matcher that matches "high load on the servel" or alike.

> 'Selectors' on the other hand are used to test the current
>         request for particular values.

Even here, think of a Selector based on the time of day.

   <select type="daytime-selector">
     <when test="on">
       ...
     </when>
     <when test="noon">
       ...
     </when>
     <when test="afternoon">
       ...
     </when>
     <otherwise>
       ...
     </otherwise>
   </select>

> 
>         I wrote the RequestParamMatcherFactory which I posted a couple of days
>         back, and are now writing a ParameterSelectorFactory - what i want to
>         do is to be able to tell the selector which request parameter it
>         should be testing - but from what I can see, the selector interface
>         doesn't support parameters like matchers do ?
> 
>         For example:
> 
>         <select type="paramselector" param="myparameter">
>           <when test="on">
>             ...
>           </when>
>         </select>
> 
>         Where 'myparameter' is the what should be passed to
>         request.getParameter(); in the generated paramselector code.
> 
>         How can something like this be implemented ? Selectors seem to be
>         designed to use a predefined parameter to select a value from a
>         defined set. What if we want to vary that parameter ?

How about his:

   <select type="paramselector">
     <when test="myparameter = on">
       ...
     </when>
     <when test="yourparameter = on">
       ...
     </when>
     <otherwise>
       ...
     </otherwise>
   </select>

>         I could set all of the 'param's in the declaration of the selector in
>         the selection section of the sitemap (hows that for a tounge
>         twister!), but then there's problems if 2 or more request parameters
>         are used at the same time.
> 
>         Any ideas ? or have I totally misunderstood everything! :-)

I hope my examples will help you understand the generality of those
components :)

Giacomo

Mime
View raw message