cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marc Portier <...@outerthought.org>
Subject Re: finding the URL of the current Cocoon application?
Date Mon, 06 Sep 2004 19:31:59 GMT


Ralph Goers wrote:
> At 9/6/2004  02:55 AM, you wrote:
> 
>> 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;
>>   }
> 
> 
> This is a good technique, but I would change
> 
>     Request request = ObjectModelHelper.getRequest(objectModel);
> 
> to
> 
>     HttpServletRequest request = 
> (HttpServletRequest)objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT);
> 
> As Lars pointed out, Cocoon's Request object can sometimes point to an 
> internal pipeline which is usually not what you want.
> 

good remark,

I should have noted that we only put the action in on the public 
pipelines (ie not internal-only)

regards,
-marc=
-- 
Marc Portier                            http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at                http://blogs.cocoondev.org/mpo/
mpo@outerthought.org                              mpo@apache.org

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


Mime
View raw message