we've used this trick a number of times:
add an action with:
public Map act( Redirector redirector, SourceResolver resolver,
Map objectModel, String source, Parameters parameters)
throws Exception
{
Request request = ObjectModelHelper.getRequest(objectModel);if (request.getAttribute("mountpoint") == null) {
String mountpoint = "";
String requestURI = NetUtils.decodePath(request.getRequestURI());
String sitemapURI = request.getSitemapURI();
int pos = requestURI.indexOf(sitemapURI);
if (pos != -1)
mountpoint = requestURI.substring(0, pos);
request.setAttribute("mountpoint", mountpoint);
getLogger().debug("mountpoint=" + mountpoint);
} else
getLogger().debug(
"mountpoint=" + request.getAttribute("mountpoint") + " already set!");
return null; }
declare it in your sitemap
<map:actions>
<map:action name="mountpoint"
src="mypackage.MountpointAction"/>
</map:actions>use it on top of those matchers that need it
<map:pipeline>
<map:match.......>
....
</map:match> <!--
| all pipes below need the mountpoint available in the
| request-attribute 'mountpoint'
-->
<map:act type="mountpoint"/>and below this point have one doing this:
<map:match pattern="menu-part/**">
<map:generate src="menu.xml" />
<map:transform src="xslt/menu2div.xsl" >
<map:parameter name="section" value="{1}" />
<map:parameter name="mountpoint"
value="{request-param:mountpoint}" />
</map:transform>
<map:serialize />
</map:match>known issues:
- URL's with special characters (even behind the mountpoint section) are likely to fail:
see http://marc.theaimsgroup.com/?t=109231177100007&r=1&w=2
HTH, -marc=
Lars Huttar wrote:
Hi all,
The short question: How do I find the URI of the current Cocoon subapplication? E.g. if the sitemap is in cocoon/mount/gem/, I want the URI "mount/gem".
Here's what I'm trying to do: Suppose I'm deep in a stylesheet somewhere and want to produce a URI for creating a file (this will be sent to SourceWritingTransformer as the href attribute).From experience, the URIs that work arecontext:/path... where "path" is relative to the Cocoon webapp top-level directory. My "subapplication" (what's the right term?) is in cocoon/mount/gem, i.e. that's where my main sitemap is. So I want to produce something like context:/mount/gem/foo/bar.xml
I've found that I can use the "request" InputModule in the sitemap to get some of this information. {request:requestURI} gives something like: "/mount/gem/zip/zang.xml" while {request:sitemapURI} gives "zip/zang.xml" for the same request.
Therefore, I can just cut sitemapURI off the end of requestURI and get "/mount/gem", the URI of my subapplication. This works just fine, at least when you're not recursively calling pipelines within pipelines.
HOWEVER,
if you have something in your sitemap with src="cocoon:/foo/bar.xml" then there are two request URLs in play; and while the sitemapURI gives a value based on the outer URL, the requestURI gives a value based on the inner URL. So trying to cut off the sitemapURI from the requestURI can give garbage.
If you know the name of the application ("gem") for sure, you can do string surgery based on it. But in our practice, this has sometimes changed ... gem2, gem-tmp, gem-bak, gem-trunk, etc.
So... does anyone have a foolproof way to find the URI of the application (mount/gem)?
Thanks, Lars
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
-- Marc Portier http://outerthought.org/ Outerthought - Open Source, Java & XML Competence Support Center Read my weblog at http://blogs.cocoondev.org/mpo/ [EMAIL PROTECTED] [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
