You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Jonathan Layes <j....@layes.com> on 2002/06/10 00:53:46 UTC

sitemap design patterns - hybrid selector/matcher?

Hi all, 

I have a recurring theme in a few of my sitemaps and, although I
have solved the problem, I'm not particularly happy with the solution.
Here's the problem in pseudo-sitemapese: 

  <map:match pattern="*.html">
    <map:act desc="an action to be applied to all xhtml">
    
      <map:match pattern="a*.html" desc="source A-prefixed xhtml">
         <map:generate/>
         <map:transform/>
      </map:match>

      <map:match pattern="b*.html" desc="source B-prefixed xhtml">
         <map:generate/>
         <map:transform/>
      </map:match>

      <map:match pattern="*.html" desc="source of all other xhtml">
         <map:generate/>
         <map:transform/>
      </map:match>

      <map:transform desc="a common template to apply regardless of source"/>
      <map:serialize/>
    </map:act>
  </map:match>

The above doesn't work when coded with matchers.  C2 falls through
the nested matches, hits the generic case and obviously throws 
an exception because it tries to call a second generator.

There are some obvious solutions to this problem.  One is to copy
the common transform and serialize stages into each of the 
nested matches, forcing C2 to stop processing in the individual
nested matches.  Slightly cleaner is to put the final transform/
serialize step in a resource and have each of the nested matches
call the resource.  I really don't like the finality of resources,
however - they feel too much like goto statements.  

What I think I want to do here is use the "if-then-else" processing
model of selectors.  Choose only one of the a*, b* or * patterns,
generate the xhtml, and finish by applying the final transform/
serialization regardless of source.  

However, the documentation states that selectors were designed with
the intent of choosing between well-defined values.  Indeed, none
of the shipped selectors use patterns or regexps.  I'm crafty enough
at writing my own components that I can easily write a selector that 
takes a regular expression as a test argument instead of a constant. 
I would rather not go against design philosophy, however, if there
is a better way to solve this class of problem.

Does anyone have thoughts on refactoring this class of problem?

Thanks, Jonathan


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


RE: sitemap design patterns - hybrid selector/matcher?

Posted by Vadim Gritsenko <va...@verizon.net>.
> From: Jonathan Layes [mailto:j.cocoon@layes.com]
> 
> On Mon, Jun 10, 2002 at 11:35:58AM -0400, Vadim Gritsenko wrote:
> > > From: Christian Haul [mailto:haul@dvs1.informatik.tu-darmstadt.de]
> > > > > From: Christian Haul
[mailto:haul@dvs1.informatik.tu-darmstadt.de]
> > > > > > Nope, this is not a bug. Sitemap works this way, breaking
> > > > > > execution
> > > > > > on
> > > > > > first serialize.
> > > > >
> > > > > Sure, but have a second look at the code: There's only one
> > > > > serialize.
> > > >
> > > > Yup, one serialize. It means every request will get through:
match,
> > > > generator, transformer, match, generator... Oops! Exception:
can't
> > > > have two generators.
> > >
> > > Oh, haven't realized that the last match matches everything and
then
> > > two generators are used. But apart from using two generators, the
> > > snippet should work, right? Like using a regex-matcher and
matching
> > > "[^ab]*.html"
> >
> > Yes, if you make matcher patterns so they do not intersect,
everything
> > will be OK.
> 
> My first interpretation of the docs was much like Christian's - only
> the first successful matcher at a given nest level will run.  But
> further investigation and experimentation led me to conclude what
> Vadim pointed out:  the subpipeline will keep executing matchers
> until a serializer is reached.

You might have many levels of nesting with actions/matchers/selectors in
any combinations. They do not indicate that pipeline has been assembled,
but just route sitemap engine through sitemap, allowing to choose
desired branch(es) according to the state of the system (URL / headers /
request attributes / session attributes / etc).


> Sometimes this behaviour is convenient and sometimes it isn't.
> In the example I provided where I want a default, catch-all case
> to apply to everything that hasn't matched earlier in the subpipeline,
> it isn't convenient.  However, I don't think changing the behaviour
> of matchers is a good idea as it would seriously break existing
> sitemaps.
> 
> The default, catch-all case is where the selector model seems a
> better fit.  However, selectors really weren't designed for
> pattern matching.  For starters, a new map isn't created with
> selectors so extracting parts of the matched pattern doesn't
> really work.  Christian, thanks for pointing out SwitchSelector
> in CVS, though.  That is the class from which I'd derive such a
> pattern-matching selector if I decide it's a good idea.
> 
> Vadim, what is your opinion on dealing with this type of situation?

Yes, selectors are somewhat limited comparing to matchers. And yes, in
choose-only-one-from-many-options situation selector should be used.

Vadim



---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: sitemap design patterns - hybrid selector/matcher?

Posted by Jonathan Layes <j....@layes.com>.
On Mon, Jun 10, 2002 at 11:35:58AM -0400, Vadim Gritsenko wrote:
> > From: Christian Haul [mailto:haul@dvs1.informatik.tu-darmstadt.de]
> > > > From: Christian Haul [mailto:haul@dvs1.informatik.tu-darmstadt.de]
> > > > > Nope, this is not a bug. Sitemap works this way, breaking
> execution
> > > > > on
> > > > > first serialize.
> > > >
> > > > Sure, but have a second look at the code: There's only one
> serialize.
> > >
> > > Yup, one serialize. It means every request will get through: match,
> > > generator, transformer, match, generator... Oops! Exception: can't
> have
> > > two generators.
> > 
> > Oh, haven't realized that the last match matches everything and then
> > two generators are used. But apart from using two generators, the
> > snippet should work, right? Like using a regex-matcher and matching
> > "[^ab]*.html"
> 
> Yes, if you make matcher patterns so they do not intersect, everything
> will be OK.

My first interpretation of the docs was much like Christian's - only
the first successful matcher at a given nest level will run.  But
further investigation and experimentation led me to conclude what 
Vadim pointed out:  the subpipeline will keep executing matchers
until a serializer is reached.

Sometimes this behaviour is convenient and sometimes it isn't. 
In the example I provided where I want a default, catch-all case
to apply to everything that hasn't matched earlier in the subpipeline,
it isn't convenient.  However, I don't think changing the behaviour 
of matchers is a good idea as it would seriously break existing 
sitemaps.

The default, catch-all case is where the selector model seems a
better fit.  However, selectors really weren't designed for 
pattern matching.  For starters, a new map isn't created with
selectors so extracting parts of the matched pattern doesn't
really work.  Christian, thanks for pointing out SwitchSelector 
in CVS, though.  That is the class from which I'd derive such a
pattern-matching selector if I decide it's a good idea.

Vadim, what is your opinion on dealing with this type of situation?


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


RE: sitemap design patterns - hybrid selector/matcher?

Posted by Vadim Gritsenko <va...@verizon.net>.
> From: Christian Haul [mailto:haul@dvs1.informatik.tu-darmstadt.de]
> 
> On 10.Jun.2002 -- 11:05 AM, Vadim Gritsenko wrote:
> > > From: Christian Haul [mailto:haul@dvs1.informatik.tu-darmstadt.de]
> > >
> > > > Nope, this is not a bug. Sitemap works this way, breaking
execution
> > > > on
> > > > first serialize.
> > >
> > > Sure, but have a second look at the code: There's only one
serialize.
> >
> > Yup, one serialize. It means every request will get through: match,
> > generator, transformer, match, generator... Oops! Exception: can't
have
> > two generators.
> 
> Oh, haven't realized that the last match matches everything and then
> two generators are used. But apart from using two generators, the
> snippet should work, right? Like using a regex-matcher and matching
> "[^ab]*.html"

Yes, if you make matcher patterns so they do not intersect, everything
will be OK.

Vadim

 
> 	Chris.
> 
> --
> C h r i s t i a n       H a u l
> haul@informatik.tu-darmstadt.de
>     fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08
> 


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: sitemap design patterns - hybrid selector/matcher?

Posted by Christian Haul <ha...@dvs1.informatik.tu-darmstadt.de>.
On 10.Jun.2002 -- 11:05 AM, Vadim Gritsenko wrote:
> > From: Christian Haul [mailto:haul@dvs1.informatik.tu-darmstadt.de]
> > 
> > > Nope, this is not a bug. Sitemap works this way, breaking execution
> on
> > > first serialize.
> > 
> > Sure, but have a second look at the code: There's only one serialize.
> 
> Yup, one serialize. It means every request will get through: match,
> generator, transformer, match, generator... Oops! Exception: can't have
> two generators.

Oh, haven't realized that the last match matches everything and then
two generators are used. But apart from using two generators, the
snippet should work, right? Like using a regex-matcher and matching
"[^ab]*.html"

	Chris.

-- 
C h r i s t i a n       H a u l
haul@informatik.tu-darmstadt.de
    fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


RE: sitemap design patterns - hybrid selector/matcher?

Posted by Vadim Gritsenko <va...@verizon.net>.
> From: Christian Haul [mailto:haul@dvs1.informatik.tu-darmstadt.de]
> 
> On 10.Jun.2002 -- 10:15 AM, Vadim Gritsenko wrote:
> > > From: Christian Haul [mailto:haul@dvs1.informatik.tu-darmstadt.de]
> > >
> > > On 09.Jun.2002 -- 07:53 PM, Jonathan Layes wrote:
> > > > Hi all,
> > > >
> > > > I have a recurring theme in a few of my sitemaps and, although I
> > > > have solved the problem, I'm not particularly happy with the
> > > > solution.
> > > > Here's the problem in pseudo-sitemapese:
> > > >
> > > >   <map:match pattern="*.html">
> > > >     <map:act desc="an action to be applied to all xhtml">
> > > >
> > > >       <map:match pattern="a*.html" desc="source A-prefixed
xhtml">
> > > >          <map:generate/>
> > > >          <map:transform/>
> > > >       </map:match>
> > > >
> > > >       <map:match pattern="b*.html" desc="source B-prefixed
xhtml">
> > > >          <map:generate/>
> > > >          <map:transform/>
> > > >       </map:match>
> > > >
> > > >       <map:match pattern="*.html" desc="source of all other
xhtml">
> > > >          <map:generate/>
> > > >          <map:transform/>
> > > >       </map:match>
> > > >
> > > >       <map:transform desc="a common template to apply regardless
of
> > > > source"/>
> > > >       <map:serialize/>
> > > >     </map:act>
> > > >   </map:match>
> > > >
> > > > The above doesn't work when coded with matchers.  C2 falls
through
> > > > the nested matches, hits the generic case and obviously throws
> > > > an exception because it tries to call a second generator.
> > >
> > > That sounds like a bug. Although I'm probably not the right person
to
> > > help finding it, it would be important to provide more
information,
> > > like the version of Cocoon you're running and the actual sitemap
> > > snippet plus sitemap.log for this case.
> >
> > Nope, this is not a bug. Sitemap works this way, breaking execution
on
> > first serialize.
> 
> Sure, but have a second look at the code: There's only one serialize.

Yup, one serialize. It means every request will get through: match,
generator, transformer, match, generator... Oops! Exception: can't have
two generators.

Absolutely expected behavior. Should this be changed or not is other
question, but this is not a bug, it is current sitemap language
semantics.

Vadim


> 	Chris.
> 
> --
> C h r i s t i a n       H a u l
> haul@informatik.tu-darmstadt.de
>     fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08
> 


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: sitemap design patterns - hybrid selector/matcher?

Posted by Christian Haul <ha...@dvs1.informatik.tu-darmstadt.de>.
On 10.Jun.2002 -- 10:15 AM, Vadim Gritsenko wrote:
> > From: Christian Haul [mailto:haul@dvs1.informatik.tu-darmstadt.de]
> > 
> > On 09.Jun.2002 -- 07:53 PM, Jonathan Layes wrote:
> > > Hi all,
> > >
> > > I have a recurring theme in a few of my sitemaps and, although I
> > > have solved the problem, I'm not particularly happy with the
> solution.
> > > Here's the problem in pseudo-sitemapese:
> > >
> > >   <map:match pattern="*.html">
> > >     <map:act desc="an action to be applied to all xhtml">
> > >
> > >       <map:match pattern="a*.html" desc="source A-prefixed xhtml">
> > >          <map:generate/>
> > >          <map:transform/>
> > >       </map:match>
> > >
> > >       <map:match pattern="b*.html" desc="source B-prefixed xhtml">
> > >          <map:generate/>
> > >          <map:transform/>
> > >       </map:match>
> > >
> > >       <map:match pattern="*.html" desc="source of all other xhtml">
> > >          <map:generate/>
> > >          <map:transform/>
> > >       </map:match>
> > >
> > >       <map:transform desc="a common template to apply regardless of
> > source"/>
> > >       <map:serialize/>
> > >     </map:act>
> > >   </map:match>
> > >
> > > The above doesn't work when coded with matchers.  C2 falls through
> > > the nested matches, hits the generic case and obviously throws
> > > an exception because it tries to call a second generator.
> > 
> > That sounds like a bug. Although I'm probably not the right person to
> > help finding it, it would be important to provide more information,
> > like the version of Cocoon you're running and the actual sitemap
> > snippet plus sitemap.log for this case.
> 
> Nope, this is not a bug. Sitemap works this way, breaking execution on
> first serialize.

Sure, but have a second look at the code: There's only one serialize.

	Chris.

-- 
C h r i s t i a n       H a u l
haul@informatik.tu-darmstadt.de
    fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


RE: sitemap design patterns - hybrid selector/matcher?

Posted by Vadim Gritsenko <va...@verizon.net>.
> From: Christian Haul [mailto:haul@dvs1.informatik.tu-darmstadt.de]
> 
> On 09.Jun.2002 -- 07:53 PM, Jonathan Layes wrote:
> > Hi all,
> >
> > I have a recurring theme in a few of my sitemaps and, although I
> > have solved the problem, I'm not particularly happy with the
solution.
> > Here's the problem in pseudo-sitemapese:
> >
> >   <map:match pattern="*.html">
> >     <map:act desc="an action to be applied to all xhtml">
> >
> >       <map:match pattern="a*.html" desc="source A-prefixed xhtml">
> >          <map:generate/>
> >          <map:transform/>
> >       </map:match>
> >
> >       <map:match pattern="b*.html" desc="source B-prefixed xhtml">
> >          <map:generate/>
> >          <map:transform/>
> >       </map:match>
> >
> >       <map:match pattern="*.html" desc="source of all other xhtml">
> >          <map:generate/>
> >          <map:transform/>
> >       </map:match>
> >
> >       <map:transform desc="a common template to apply regardless of
> source"/>
> >       <map:serialize/>
> >     </map:act>
> >   </map:match>
> >
> > The above doesn't work when coded with matchers.  C2 falls through
> > the nested matches, hits the generic case and obviously throws
> > an exception because it tries to call a second generator.
> 
> That sounds like a bug. Although I'm probably not the right person to
> help finding it, it would be important to provide more information,
> like the version of Cocoon you're running and the actual sitemap
> snippet plus sitemap.log for this case.

Nope, this is not a bug. Sitemap works this way, breaking execution on
first serialize.

Vadim


> > There are some obvious solutions to this problem.  One is to copy
> > the common transform and serialize stages into each of the
> > nested matches, forcing C2 to stop processing in the individual
> > nested matches.  Slightly cleaner is to put the final transform/
> > serialize step in a resource and have each of the nested matches
> > call the resource.  I really don't like the finality of resources,
> > however - they feel too much like goto statements.
> >
> > What I think I want to do here is use the "if-then-else" processing
> > model of selectors.  Choose only one of the a*, b* or * patterns,
> > generate the xhtml, and finish by applying the final transform/
> > serialization regardless of source.
> 
> Look for a switch selector. I'm not aware whether it's in 2.0.3 or
> HEAD only. AFAIR it was invented for such a case.
> 
> 	Chris.
> 
> --
> C h r i s t i a n       H a u l
> haul@informatik.tu-darmstadt.de
>     fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: sitemap design patterns - hybrid selector/matcher?

Posted by Christian Haul <ha...@dvs1.informatik.tu-darmstadt.de>.
On 09.Jun.2002 -- 07:53 PM, Jonathan Layes wrote:
> Hi all, 
> 
> I have a recurring theme in a few of my sitemaps and, although I
> have solved the problem, I'm not particularly happy with the solution.
> Here's the problem in pseudo-sitemapese: 
> 
>   <map:match pattern="*.html">
>     <map:act desc="an action to be applied to all xhtml">
>     
>       <map:match pattern="a*.html" desc="source A-prefixed xhtml">
>          <map:generate/>
>          <map:transform/>
>       </map:match>
> 
>       <map:match pattern="b*.html" desc="source B-prefixed xhtml">
>          <map:generate/>
>          <map:transform/>
>       </map:match>
> 
>       <map:match pattern="*.html" desc="source of all other xhtml">
>          <map:generate/>
>          <map:transform/>
>       </map:match>
> 
>       <map:transform desc="a common template to apply regardless of source"/>
>       <map:serialize/>
>     </map:act>
>   </map:match>
> 
> The above doesn't work when coded with matchers.  C2 falls through
> the nested matches, hits the generic case and obviously throws 
> an exception because it tries to call a second generator.

That sounds like a bug. Although I'm probably not the right person to
help finding it, it would be important to provide more information,
like the version of Cocoon you're running and the actual sitemap
snippet plus sitemap.log for this case.

> There are some obvious solutions to this problem.  One is to copy
> the common transform and serialize stages into each of the 
> nested matches, forcing C2 to stop processing in the individual
> nested matches.  Slightly cleaner is to put the final transform/
> serialize step in a resource and have each of the nested matches
> call the resource.  I really don't like the finality of resources,
> however - they feel too much like goto statements.  
> 
> What I think I want to do here is use the "if-then-else" processing
> model of selectors.  Choose only one of the a*, b* or * patterns,
> generate the xhtml, and finish by applying the final transform/
> serialization regardless of source.  

Look for a switch selector. I'm not aware whether it's in 2.0.3 or
HEAD only. AFAIR it was invented for such a case.

	Chris.

-- 
C h r i s t i a n       H a u l
haul@informatik.tu-darmstadt.de
    fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>