cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Man <Martin....@seznam.cz>
Subject SessionValidator action
Date Thu, 15 Mar 2001 17:51:16 GMT
Hi all,
	I'have started to write a SessionValidator action which will provide
you with basic flow control, it's almost complete and will work almost the
same way as described in org/apache/cocoon/acting/README

<map:action type="session validator" src="..."/>

<map:match pattern="protected_area">
    <map:act type="session validator">
        <parameter name="descriptor" value="session-params.xml"/>
        <parameter name="required" value="name,role=admin,lang"/>
        
        <map:my_select name="{result}">
            <map:my_when test="nosession">
                <map:redirect-to uri="login"/>
            </map:my_when>
            <map:my_when test="error">
                <map:redirect-to uri="buggy_session"/>
            </map:my_when>
            <map:my_when test="ok">
                <map:generate src="admin.xsp"/>
                ...
            </map:my_when>
        </map:my_select>
    </map:act>
</map:match>

in a file session-params.xml or wherever else there should be description of
parameters that may occur in a session, there will be all possible parameters
and by parameter 'required' of an action we specify what should be there in a
session right now, this way we can share one session-params.xml descriptor
across a whole webapp, 

-- cut session-params.xml --
<session-params>
    <param name="name" type="string" nullable="no" default="guest"/>
    <param name="role" type="string" nullable="no" default="guest"/>
    <param name="lang" type="string" nullable="no" default="en"/>
</session-params>
-- cut --


the statement <parameter name="required" value="...,role=admin,..."/> is
telling that session validator is about to check whether session parameter
role really has the value of admin,

the action will return parameter {result} into sitemap which we can then check
and control the flow appropriately the values returned in a {result} can be
ok - when check passed
nosession - when there is no session object at all
error - when there is a session but not all 'required' parameters are present
	or they have wrong value

the <map:select name="{result}" is not in a sitemap syntax yet, so I have made
an ugly patch into sitemap.xsl which enables simple byte-to-byte comparsion on
{result}

the patch is something like this (lying bellow template for <map:act ...>)

-- cut sitemap.xsl --

  <xsl:template match="map:my_select">
	  <xsl:apply-templates select="map:my_when"/>
  </xsl:template>

  <xsl:template match="map:my_when">
	  if ("<xsl:value-of
		  select="@test"/>".equals (substitute (listOfMaps,
	  "<xsl:value-of select="../@name"/>"))) {
	  	<xsl:apply-templates/>
	  }
  </xsl:template>

-- cut --
 

tell me what do you think about it, I know that it is really HUGE pollution of
a sitemap with flow control, but as long as actions will reside there this stuff
will probaby stay also...

the same way a "form validator" can be written, which will check request
parameters instead of session ones, this would be nice if we can for example
here check that form parameter called message is a well-formed xml

<map:act type="form validator">
    <parameter name="descriptor" value="form-descriptor.xml"/>
    <parameter name="required" value="day,month,year,author,message"/>
    <map:my_select name="{result}">

    </map:my_select>
</map:act>

where form-descriptor.xml

<form-descriptor>
    <param name="day" type="number" digits="2" nullable="no"/>
    <param name="month" type="number" digits="2" nullable="no"/>
    <param name="year" type="number" digits="4" nullable="no"/>

    <param name="author" type="string" nullable="no"/>
    <param name="message" type="xml" nullable="no"/>
</form-descriptor>

again, we can check in an action whether all parameters are valid and then
proceed somwehere else....

what we need I think now is either to introduce flowmap somehow or implement
<map:my_select> in a clean way, (but using selectors is probably overhead)
than I can finish those two validators and contribute them, (if you want of
course :-))))


regards,
martin

P.S. as you might have seen it's all inspired by DatabaseActions :-))
-- 
-------------------------------------------------------------------------------
"Only dead fish swims with a stream"
gpg_key_fingerprint: 2CC0 4AF6 92DA 5CBF 5F09  7BCB 6202 7024 6E06 0223

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message