On Friday 10 January 2003 13:55, J�rg Walter wrote:

>
> The problem is, what syntax would one use. 

Yup. Let me cite my password-matches-example:

      <auth:password-matches 
encrypted="$1$jsdxRBEt$IzCeNthea4KqzkzNB7sT4/" clear="ficken">
        <auth:false>Password is invalid</auth:false>
        <auth:true><strong><xsp:content>Password is 
valid</xsp:content></strong></auth:true>
      </auth:password-matches>

Obviously, sometimes it is better to use the child elements (I have this 
funny aversion about the word "tag", it reminds me of the bad old days 
of "tag soup"... :-) ) encrypted and clear, especially since I'll be 
writing a taglib to get the encrypted password from my DB. 

So, I'll end up with something like:

<auth:password-matches> 
        <auth:encrypted><mydb:getpasswd/></auth:encrypted> 
        <auth:clear><param:passwd/></auth:clear>
        <auth:false>Password is invalid</auth:false>
        <auth:true><strong><xsp:content>Password is 
valid</xsp:content></strong></auth:true>
      </auth:password-matches>

Conceptually, it might be argued it would be nicer to seperate the input 
stuff (encrypted and clear) from the output stuff (true, false), but I 
don't feel too strongly about that.

> If we use something
> XSLT'ish, the result would probably look like
> <cond:if><cond:expr><ns:something-boolean/></cond:expr><cond:action><
>p>true</p></cond:action></cond:if> which is longer but not really
> prettier than
> <xsp:logic>if (<ns:something-boolean/>) {<p>true</p>}</xsp:logic>

True... :-) Except for that I really don't like perl-code in my XML... 


> now, with some evil intentions it might (should) be possible to do
> this: <cond:if tag="ns:something-boolean"><p>true</p></cond:if>
>
> (where we could also supply other attribs, like expr="$foo == 1" or
> param="some_query_param", so it would serve multiple purposes)

True.

> Only I'm still not entirely happy, especially regarding the auth
> taglib: <xsp:logic>if (<auth:get-single-access type="user"/> eq
> 'guest') {<p>sorry, only for registered users</p>}</xsp:logic>
>
> I don't yet see an elegant solution for this... 

How about 
<auth:single-access-ok type="user" name="guest"/>
        <auth:true><p>sorry, only for registered users</p></auth:true>
</auth:single-access-ok>

> and then there is the "else".

Well, that's true, but I would say that we probably shouldn't try to 
chew too much... :-) If we restrict ourselves to the strict boolean 
situation, it's still many cool things to do... Besides, it is a lot 
you can do with XSLT if it is fed something sensible. 

> In the end, for those who like having no perl code at all in their
> XSP, 

*raises hand* :-)

>I suggest this one:
>
> <cond:if>
>   <cond:expr><ns:tag/></cond:expr>
>   <cond:true><p>yeah!</p></cond:true>
>   <cond:false><p>oh no!</p></cond:false>
> </cond:if>

Yup, but in my example above, I have preferred to think like this: We're 
declaring a tag boolean, not a block that contains a boolean tag. 

It gets a lot shorter that way, and we also gain 
backwards-compatibility: If the tag contains no true or false child 
elements, then it will just return 1 or 0, like they used to.

For Auth, this is obviously a benefit, as all the current boolean tags 
can only be extended with true and false child elements. 

OK, I'll just post my rather verbose password_matches sub, feel free to 
tear your hear off, but do not hold me responsible for baldness...: :-)
Anyway, this does this, except of course that the true/false child 
elements can't have child elements of their own.
 
sub password_matches : attribOrChild(clear,encrypted)
                       child(true,false)
                       expr
{
    return << 'EOF';
    my $ok = ($attr_clear && $attr_encrypted && 
crypt($attr_clear,$attr_encrypted) eq $attr_encrypted?1:0);
    my $res;
    if($attr_true && $ok)
    {
        $res = $attr_true;
    }
    if($attr_false && ! $ok)
    {
        $res = $attr_false;
    }
    if(!$res)
    {
        $res = $ok;
    }
    $res;
EOF
}


Cheers,

Kjetil
-- 
Kjetil Kjernsmo
Astrophysicist/IT Consultant/Skeptic/Ski-orienteer/Orienteer/Mountaineer
[EMAIL PROTECTED]  [EMAIL PROTECTED]  [EMAIL PROTECTED]
Homepage: http://www.kjetil.kjernsmo.net/


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to