You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Giacomo Pati <Gi...@pwr.ch> on 2000/06/25 14:47:18 UTC
[C2] Matcher concept
Hi all
While I'm considering how a sitemap class may be constructed I've
encountered the following problem concerning the java layout of a
pipeline.
As we have proposed that a matcher implements the interface
public interface CompiledMatcher implements Component {
public Map match(...);
}
and also consider the following snipped from a hypothetical sitemap
<match type="user-agent" pattern="Mozilla */* *">
<match type="uri" pattern="/my/page/*">
<generator type="parser" src="/my/data/$1.xml/>
...
</match>
</match>
Now, what is the $1 representing. The browser match or the uri match?
Should the pipeline code provide the Map to the matcher so that they
could add stuff to it? And then, must a pipeline maintainer count all
wildcards from the topmost matcher in the pipeline to get the right
replacement, so that in my example the $1 should be written as $4?
You thoughts are welcome here.
Giacomo
--
PWR GmbH, Organisation & Entwicklung Tel: +41 (0)1 856 2202
Giacomo Pati, CTO/CEO Fax: +41 (0)1 856 2201
Hintereichenstrasse 7 Mailto:Giacomo.Pati@pwr.ch
CH-8166 Niederweningen Web: http://www.pwr.ch
Re: [C2] Matcher concept
Posted by Jonathan Stimmel <jo...@stimmel.net>.
On Sun, Jun 25, 2000 at 04:42:10PM +0200, Giacomo Pati wrote:
> Niclas Hedhman wrote:
> >
> > Giacomo Pati wrote:
> >
> > > Now, what is the $1 representing. The browser match or the uri match?
> > > You thoughts are welcome here.
> >
> > Thinking........................................!!
> >
> > $1 = matching the first parameter of the nearest level.
> > $$1 = matching the first parameter of the seond nearest level.
> > and so forth.
>
> Uah! I don't like this :(
Ditto. I'd expect them to only hit the most recent match, but then
you don't have access to the previous match.
Ross Burton had suggested adding named parameters (see "RT on Patterns
and Choosers"); perhaps this would be an appropriate use?
Re: [C2] Matcher concept
Posted by Giacomo Pati <Gi...@pwr.ch>.
Niclas Hedhman wrote:
>
> Giacomo Pati wrote:
>
> > Now, what is the $1 representing. The browser match or the uri match?
> > You thoughts are welcome here.
>
> Thinking........................................!!
>
> $1 = matching the first parameter of the nearest level.
> $$1 = matching the first parameter of the seond nearest level.
> and so forth.
Uah! I don't like this :(
> Perhaps a better hierarchy naming is needed;
Yes, looks like. Any other proposals, folks?
Giacomo
--
PWR GmbH, Organisation & Entwicklung Tel: +41 (0)1 856 2202
Giacomo Pati, CTO/CEO Fax: +41 (0)1 856 2201
Hintereichenstrasse 7 Mailto:Giacomo.Pati@pwr.ch
CH-8166 Niederweningen Web: http://www.pwr.ch
Re: [C2] Matcher concept
Posted by Niclas Hedhman <ni...@localbar.com>.
Giacomo Pati wrote:
> Now, what is the $1 representing. The browser match or the uri match?
> You thoughts are welcome here.
Thinking........................................!!
$1 = matching the first parameter of the nearest level.
$$1 = matching the first parameter of the seond nearest level.
and so forth.
Perhaps a better hierarchy naming is needed;
Niclas
Re: [C2] Matcher concept
Posted by Giacomo Pati <Gi...@pwr.ch>.
Donald Ball wrote:
>
> On Sun, 25 Jun 2000, Giacomo Pati wrote:
>
> > While I'm considering how a sitemap class may be constructed I've
> > encountered the following problem concerning the java layout of a
> > pipeline.
> >
> > As we have proposed that a matcher implements the interface
> >
> > public interface CompiledMatcher implements Component {
> > public Map match(...);
> > }
> >
> > and also consider the following snipped from a hypothetical sitemap
> >
> > <match type="user-agent" pattern="Mozilla */* *">
> > <match type="uri" pattern="/my/page/*">
> > <generator type="parser" src="/my/data/$1.xml/>
> > ...
> > </match>
> > </match>
> >
> > Now, what is the $1 representing. The browser match or the uri match?
> > Should the pipeline code provide the Map to the matcher so that they
> > could add stuff to it? And then, must a pipeline maintainer count all
> > wildcards from the topmost matcher in the pipeline to get the right
> > replacement, so that in my example the $1 should be written as $4?
>
> perl would say that the $number convenience variables are reset after the
> next regexp with variables, so you'd need to explicitly save them if you
> need to use them later:
>
> <match type="user-agent" pattern="Mozilla */* *">
> <variable name="agent" value="$1"/>
> <match type="uri" pattern="/my/page/*">
> <generator type="parser" src="/my/data/$variable.xml/>
> ...
> </match>
> </match>
>
> i think that's probably reasonable.
Yes.
>
> perl also says, though, that wildcarding by itself doesn't save a
> variable - you use parentheses to indicate portions of the regexp to save,
> e.g.:
>
> <match type="user-agent" pattern="Mozilla ([^/]+)/* *">
We never said we can mix wildcards and regexp! So you example should be
written like:
<match type="user-agent" pattern="Mozilla ([^/]+)/([^/]*) ([^/]*)">
because wildcards don't need parenthesis.
Giacomo
--
PWR GmbH, Organisation & Entwicklung Tel: +41 (0)1 856 2202
Giacomo Pati, CTO/CEO Fax: +41 (0)1 856 2201
Hintereichenstrasse 7 Mailto:Giacomo.Pati@pwr.ch
CH-8166 Niederweningen Web: http://www.pwr.ch
Re: [C2] Matcher concept
Posted by Donald Ball <ba...@webslingerZ.com>.
On Sun, 25 Jun 2000, Stefano Mazzocchi wrote:
> Well, in case you didn't notice there is this example in the current
> working draft
>
> <!--
> Complex example to show how some xpath-like syntax is used
> to get access to the pattern tokens generated by the matchers.
> -->
> <map:match pattern="nested-matchers/*">
> <map:match type="browser" pattern="name('Mozilla ?\?*')">
> <map:mount src="file:///home/www/mozilla-{1}-{2}/{../1}"/>
> </map:match>
> </map:match>
>
> in which I used XSLT/XPath design principles.
>
> Isn't this good enough?
{../1} is much better than $$1. +1 from me.
- donald
Re: [C2] Matcher concept
Posted by Stefano Mazzocchi <st...@apache.org>.
Donald Ball wrote:
>
> On Sun, 25 Jun 2000, Giacomo Pati wrote:
>
> > While I'm considering how a sitemap class may be constructed I've
> > encountered the following problem concerning the java layout of a
> > pipeline.
> >
> > As we have proposed that a matcher implements the interface
> >
> > public interface CompiledMatcher implements Component {
> > public Map match(...);
> > }
> >
> > and also consider the following snipped from a hypothetical sitemap
> >
> > <match type="user-agent" pattern="Mozilla */* *">
> > <match type="uri" pattern="/my/page/*">
> > <generator type="parser" src="/my/data/$1.xml/>
> > ...
> > </match>
> > </match>
> >
> > Now, what is the $1 representing. The browser match or the uri match?
> > Should the pipeline code provide the Map to the matcher so that they
> > could add stuff to it? And then, must a pipeline maintainer count all
> > wildcards from the topmost matcher in the pipeline to get the right
> > replacement, so that in my example the $1 should be written as $4?
>
> perl would say that the $number convenience variables are reset after the
> next regexp with variables, so you'd need to explicitly save them if you
> need to use them later:
>
> <match type="user-agent" pattern="Mozilla */* *">
> <variable name="agent" value="$1"/>
> <match type="uri" pattern="/my/page/*">
> <generator type="parser" src="/my/data/$variable.xml/>
> ...
> </match>
> </match>
>
> i think that's probably reasonable.
>
> perl also says, though, that wildcarding by itself doesn't save a
> variable - you use parentheses to indicate portions of the regexp to save,
> e.g.:
>
> <match type="user-agent" pattern="Mozilla ([^/]+)/* *">
> ...
> </match>
Well, in case you didn't notice there is this example in the current
working draft
<!--
Complex example to show how some xpath-like syntax is used
to get access to the pattern tokens generated by the matchers.
-->
<map:match pattern="nested-matchers/*">
<map:match type="browser" pattern="name('Mozilla ?\?*')">
<map:mount src="file:///home/www/mozilla-{1}-{2}/{../1}"/>
</map:match>
</map:match>
in which I used XSLT/XPath design principles.
Isn't this good enough?
--
Stefano Mazzocchi One must still have chaos in oneself to be
able to give birth to a dancing star.
<st...@apache.org> Friedrich Nietzsche
--------------------------------------------------------------------
Missed us in Orlando? Make it up with ApacheCON Europe in London!
------------------------- http://ApacheCon.Com ---------------------
Re: [C2] Matcher concept
Posted by Donald Ball <ba...@webslingerZ.com>.
On Sun, 25 Jun 2000, Giacomo Pati wrote:
> While I'm considering how a sitemap class may be constructed I've
> encountered the following problem concerning the java layout of a
> pipeline.
>
> As we have proposed that a matcher implements the interface
>
> public interface CompiledMatcher implements Component {
> public Map match(...);
> }
>
> and also consider the following snipped from a hypothetical sitemap
>
> <match type="user-agent" pattern="Mozilla */* *">
> <match type="uri" pattern="/my/page/*">
> <generator type="parser" src="/my/data/$1.xml/>
> ...
> </match>
> </match>
>
> Now, what is the $1 representing. The browser match or the uri match?
> Should the pipeline code provide the Map to the matcher so that they
> could add stuff to it? And then, must a pipeline maintainer count all
> wildcards from the topmost matcher in the pipeline to get the right
> replacement, so that in my example the $1 should be written as $4?
perl would say that the $number convenience variables are reset after the
next regexp with variables, so you'd need to explicitly save them if you
need to use them later:
<match type="user-agent" pattern="Mozilla */* *">
<variable name="agent" value="$1"/>
<match type="uri" pattern="/my/page/*">
<generator type="parser" src="/my/data/$variable.xml/>
...
</match>
</match>
i think that's probably reasonable.
perl also says, though, that wildcarding by itself doesn't save a
variable - you use parentheses to indicate portions of the regexp to save,
e.g.:
<match type="user-agent" pattern="Mozilla ([^/]+)/* *">
...
</match>
- donald