You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Romain Slootmaekers <ro...@inuron.com> on 2008/01/14 13:40:43 UTC

map:read options

Hi,

I've been trying to use map:read to read a file from a location on the 
fs outside the cocoon root.

http://cocoon.apache.org/2.2/core-modules/core/2.2/846_1_1.html
is rather sparse, but I tried:

<map:match  pattern="**.msi">
                <map:read type="resource"
                    src="installer.msi"
                    mime-type="application/octet-stream" />
</map:match>


and alternatives with ../ ./ / aso. nothing seems to work with mvn 
jetty:run-war)

The question is: can I use map:read for this, or need I write a little 
servlet ?

Tia,

Romain.

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


Re: map:read options

Posted by Romain Slootmaekers <ro...@inuron.com>.
Reinhard Poetz wrote:
>
> Where *exactly* do you want to put the file? Should it become part of 
> the web application or is it located outside?
>

the file needs to be outside the .war and either relative to current.dir 
(from where the servlet runner got launched) or configurable from 
outside the sitemap.

right now I have a little servlet:
public class LittleServlet extends HttpServlet {
  
    public void doGet(HttpServletRequest request, HttpServletResponse 
response)
            throws IOException, ServletException {
        response.setContentType("application/octet-stream");
        String path = System.getProperty("where");
        File f = new File(path);
        FileInputStream fin = new FileInputStream(f);
        // copy fin into response.getOutputStream();
        fin.close();

    }

}

which does the trick,
but I would like to to something similar using map:read

Romain.

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


Re: map:read options

Posted by Reinhard Poetz <re...@apache.org>.
Romain Slootmaekers wrote:
> Robin Wyles wrote:
>> Hi Romain,
>>
>> On 14 Jan 2008, at 13:40, Romain Slootmaekers wrote:
>>
>>> Hi,
>>>
>>> I've been trying to use map:read to read a file from a location on 
>>> the fs outside the cocoon root.
>>>
>>> http://cocoon.apache.org/2.2/core-modules/core/2.2/846_1_1.html
>>> is rather sparse, but I tried:
>>>
>>> <map:match  pattern="**.msi">
>>>                <map:read type="resource"
>>>                    src="installer.msi"
>>>                    mime-type="application/octet-stream" />
>>> </map:match>
>>>
>>>
>>> and alternatives with ../ ./ / aso. nothing seems to work with mvn 
>>> jetty:run-war)
>>>
>>> The question is: can I use map:read for this, or need I write a 
>>> little servlet ?
>>
>>
>> I think you should be able to, have you tried using an absolute path 
>> to the file like so?
>>
>>  <map:read type="resource"
>>                    src="/absolute/path/to/your/file/installer.msi"
>>                    mime-type="application/octet-stream" />
>>
> Yes the file:///C:/some path/installer.msi works
> 
> but I would like to have a relative path as the app needs to be relocatable

Where *exactly* do you want to put the file? Should it become part of the web 
application or is it located outside?

-- 
Reinhard Pötz                            Managing Director, {Indoqa} GmbH
                           http://www.indoqa.com/en/people/reinhard.poetz/

Member of the Apache Software Foundation
Apache Cocoon Committer, PMC member, PMC Chair        reinhard@apache.org
_________________________________________________________________________

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


Re: map:read options

Posted by Grzegorz Kossakowski <gk...@apache.org>.
Robin Wyles pisze:
> 
> On 14 Jan 2008, at 15:40, Romain Slootmaekers wrote:
> 
>> Robin Wyles wrote:
>> Yes the file:///C:/some path/installer.msi works
>>
>> but I would like to have a relative path as the app needs to be
>> relocatable
> 
> Relative paths are resolved relative to the location of the sitemap, and
> in C2.2 the location of the sitemap varies greatly depending on how you
> run cocoon during development, deployment etc. In your production webapp
> your sitemap will be in the jar file created for your block.
> 
> You could use the directory generator [1] along with ../ in your src
> attribute to determine how the relative paths are resolved.
> 
> I would suggest you try to determine the absolute path to your webapp
> context first and then resolve your path relative to that, you might
> want to take a look at using the ContextPathModule [2] which could help
> you.

Robin is right on his suggestion. In order obtain absolute location of your block you could make use
of Input Module provided in COCOON-2145 but this demands patching Cocoon's sources.

Another way is to use properties as Romain already does. In sitemap one can obtain system property
using settings module:

  {settings:your_property}

Since 2.2 incorporates Cocoon Spring Configurator sub-project it's very easy to work with various
configuration options. See [2] for more details.

[1] https://issues.apache.org/jira/browse/COCOON-2145
[2] http://cocoon.apache.org/subprojects/configuration/1.0/spring-configurator/1.0/1304_1_1.html

-- 
Grzegorz Kossakowski
Committer and PMC Member of Apache Cocoon
http://reflectingonthevicissitudes.wordpress.com/

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


Re: map:read options

Posted by Robin Wyles <ro...@robinwyles.com>.
On 14 Jan 2008, at 15:40, Romain Slootmaekers wrote:

> Robin Wyles wrote:
>> Hi Romain,
>>
>> On 14 Jan 2008, at 13:40, Romain Slootmaekers wrote:
>>
>>> Hi,
>>>
>>> I've been trying to use map:read to read a file from a location  
>>> on the fs outside the cocoon root.
>>>
>>> http://cocoon.apache.org/2.2/core-modules/core/2.2/846_1_1.html
>>> is rather sparse, but I tried:
>>>
>>> <map:match  pattern="**.msi">
>>>                <map:read type="resource"
>>>                    src="installer.msi"
>>>                    mime-type="application/octet-stream" />
>>> </map:match>
>>>
>>>
>>> and alternatives with ../ ./ / aso. nothing seems to work with  
>>> mvn jetty:run-war)
>>>
>>> The question is: can I use map:read for this, or need I write a  
>>> little servlet ?
>>
>>
>> I think you should be able to, have you tried using an absolute  
>> path to the file like so?
>>
>>  <map:read type="resource"
>>                    src="/absolute/path/to/your/file/installer.msi"
>>                    mime-type="application/octet-stream" />
>>
> Yes the file:///C:/some path/installer.msi works
>
> but I would like to have a relative path as the app needs to be  
> relocatable

Relative paths are resolved relative to the location of the sitemap,  
and in C2.2 the location of the sitemap varies greatly depending on  
how you run cocoon during development, deployment etc. In your  
production webapp your sitemap will be in the jar file created for  
your block.

You could use the directory generator [1] along with ../ in your src  
attribute to determine how the relative paths are resolved.

I would suggest you try to determine the absolute path to your webapp  
context first and then resolve your path relative to that, you might  
want to take a look at using the ContextPathModule [2] which could  
help you.

Robin

[1] http://cocoon.apache.org/2.2/core-modules/core/2.2/953_1_1.html
[2] http://cocoon.apache.org/2.1/userdocs/concepts/modules-ref.html  
(These are the docs for C2.1, I don't think the comparable  
documentation for C2.2 exists yet, but they should work in the same  
way.)


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


Re: map:read options

Posted by Romain Slootmaekers <ro...@inuron.com>.
Robin Wyles wrote:
> Hi Romain,
>
> On 14 Jan 2008, at 13:40, Romain Slootmaekers wrote:
>
>> Hi,
>>
>> I've been trying to use map:read to read a file from a location on 
>> the fs outside the cocoon root.
>>
>> http://cocoon.apache.org/2.2/core-modules/core/2.2/846_1_1.html
>> is rather sparse, but I tried:
>>
>> <map:match  pattern="**.msi">
>>                <map:read type="resource"
>>                    src="installer.msi"
>>                    mime-type="application/octet-stream" />
>> </map:match>
>>
>>
>> and alternatives with ../ ./ / aso. nothing seems to work with mvn 
>> jetty:run-war)
>>
>> The question is: can I use map:read for this, or need I write a 
>> little servlet ?
>
>
> I think you should be able to, have you tried using an absolute path 
> to the file like so?
>
>  <map:read type="resource"
>                    src="/absolute/path/to/your/file/installer.msi"
>                    mime-type="application/octet-stream" />
>
Yes the file:///C:/some path/installer.msi works

but I would like to have a relative path as the app needs to be relocatable


Romain.

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


Re: map:read options

Posted by Robin Wyles <ro...@robinwyles.com>.
Hi Romain,

On 14 Jan 2008, at 13:40, Romain Slootmaekers wrote:

> Hi,
>
> I've been trying to use map:read to read a file from a location on  
> the fs outside the cocoon root.
>
> http://cocoon.apache.org/2.2/core-modules/core/2.2/846_1_1.html
> is rather sparse, but I tried:
>
> <map:match  pattern="**.msi">
>                <map:read type="resource"
>                    src="installer.msi"
>                    mime-type="application/octet-stream" />
> </map:match>
>
>
> and alternatives with ../ ./ / aso. nothing seems to work with mvn  
> jetty:run-war)
>
> The question is: can I use map:read for this, or need I write a  
> little servlet ?


I think you should be able to, have you tried using an absolute path  
to the file like so?

  <map:read type="resource"
                    src="/absolute/path/to/your/file/installer.msi"
                    mime-type="application/octet-stream" />

or maybe even:

<map:read type="resource"
                    src="file:///absolute/path/to/your/file/ 
installer.msi"
                    mime-type="application/octet-stream" />


Robin