You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Petri Wessman <or...@iki.fi> on 2004/10/04 10:48:22 UTC
Question about map parameters and actions
Hello all, I have a small problem figuring out how to do something with
Cocoon, and some amount of rtfm hasn't enlightened me so far.
The problem is this: when accessing some pages, I want the content to be
served as application/xhtml+xml when (and only when) the browser requests it
with an Accept header. I also need to do some access checks based on client
IP. Currently I have something like this in the sitemap (in general terms):
<map:match pattern="*">
<map:generate src="file://some_path/{1}.xml"/>
<map:select type="accept-header">
<map:when test="application/xhtml+xml">
<map:act type="permission-checks">
<map:transform src="file://some_path/page.xslt">
<map:parameter name="permission" value="{permission}"/>
<map:parameter name="metaContentType"
value="application/xhtml+xml; charset=utf-8"/>
</map:transform>
</map:act>
<map:serialize type="xhtml11"/>
</map:when>
<map:otherwise>
<map:act type="permission-checks">
<map:transform src="file://some_path/page.xslt">
<map:parameter name="permission" value="{permission}"/>
<map:parameter name="metaContentType"
value="text/html; charset=utf-8"/>
</map:transform>
</map:act>
<map:serialize type="xhtml-as-html"/>
</map:otherwise>
</map:select>
</map:match>
This works but is clumsy and has lots of repetition, especially since this
sort of block needs to be repeated in numerous places in the sitemap.
What I'd like to so is to have one action both set the access permissions (for
the XSLT) and decide on the output format. Or have two separate actions that
are run in a chain, if that is possible in Cocoon(?).
What I tried to do is this:
<map:match pattern="*">
<map:generate src="file://some_path/{1}.xml"/>
<map:act type="combined-access">
<map:transform src="file://some_path/page.xslt">
<map:parameter name="permission" value="{permission}"/>
<map:parameter name="metaContentType" value="{content-type}"/>
</map:transform>
<map:serialize type="{serializer}"/>
</map:act>
</map:match>
Where the Java code in the combined-access Action does this:
...
Map map = new HashMap();
map.put("permission", ok ? "yes" : "no");
...
if (xhtmlOk) {
map.put("serializer","xhtml11");
map.put("content-type","application/xhtml+xml; charset=utf-8");
} else {
map.put("serializer","xhtml-as-html");
map.put("content-type","text/html; charset=utf-8");
}
return map;
This fails, with the error message that the parameter {serializer} could not
be found (for the serializer). I would have though that the parameters set by
the action would be visible for the whole block contained by the action, but
obviously they are not. Do I need to use some special syntax for this, or how
do I solve this? Any help appreciated.
While I'm at it: is there any way to set variables and/or define code blocks
for reuse in a sitemap? I find I'm doing a lot of cut+pasting, with identical
pipeline fragments, file paths, etc. It would be very convenient to be able
to define things once and then just refer to then, sort of what I can do in
Ant build files. I realize that a sitemap is quite a different beast, but...
anything like this possible currently?
//Petri Wessman
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org