You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Marc Salvetti <ma...@notremanou.net> on 2004/12/20 05:58:22 UTC

File system access in flowscript

Hello,

i'm trying to access some of the xml files in my webapp directly from 
the flowscript for creation/deletion
i can't find a way to adress the correct directory of the servlet

i tried request:contextPath but it gives only a partial path, i also 
tried servletPath but it gives the uri of the calling page

what i'd like to do look like this :

    var path = contextPath + "/cfm/xdocs/planning/cruise7.xml";
    var file = new Packages.java.io.File( path);
    if(!file.isFile()){print(file.getCanonicalPath());}

Does anyone have a working example of how to get the full path of the 
directory where my xml files are ?
Or maybe a better idea ? ;)

Thanks for any help,

Marc

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


Re: File system access in flowscript

Posted by Marc Salvetti <ma...@notremanou.net>.
Thanks Jan, it seems to be working...
I just have to modify slightly your function because i'm on windows, and 
got spaces in my files path.

function resolveToFile(uri)
{
   var resolver = null;
   var filesource = null;
   try
   {
      resolver = 
cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
      filesource = resolver.resolveURI(uri);
      var file = new java.io.File(new 
java.net.URI(filesource.getURI().replaceAll(" ", "%20")));
      return file;
   }
   finally
   {
      if(filesource != null) resolver.release(filesource);
      cocoon.releaseComponent(resolver);
   }
}

It doesn't seem to be very clean solution, but it's working...
Hope this will work on unix as well :)

Marc

Jan Hoskens a écrit :

> When accessing a file, you need to resolve it's uri. Resolving will 
> suffix a path the same way as used in the sitemap.
>
> eg: in your webapp's sitemap you use "pages/mywelcomepage.xml"
>
> mywebapp/pages/mywelcomepage.xml
> mywebapp/sitemap.xmap
>
> then resolving will add the whole path /.../mywebapp/ in front of your 
> relative path "pages/mywelcomepage.xml".
>
> I tend to use a simple function for this in my flowscript:
>
> function resolveToFile(uri)
> {
>    var resolver = null;
>    var filesource = null;
>    try
>    {
>       resolver = 
> cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE); 
>
>       filesource = resolver.resolveURI(uri);
>       var file = new java.io.File(new java.net.URI(filesource.getURI()));
>       return file;
>    }
>    finally
>    {
>       if(filesource != null) resolver.release(filesource);
>       cocoon.releaseComponent(resolver);
>    }
> }
>
>
> Kind Regards,
> Jan
>
> Marc Salvetti wrote:
>
>> Hello,
>>
>> i'm trying to access some of the xml files in my webapp directly from 
>> the flowscript for creation/deletion
>> i can't find a way to adress the correct directory of the servlet
>>
>> i tried request:contextPath but it gives only a partial path, i also 
>> tried servletPath but it gives the uri of the calling page
>>
>> what i'd like to do look like this :
>>
>>    var path = contextPath + "/cfm/xdocs/planning/cruise7.xml";
>>    var file = new Packages.java.io.File( path);
>>    if(!file.isFile()){print(file.getCanonicalPath());}
>>
>> Does anyone have a working example of how to get the full path of the 
>> directory where my xml files are ?
>> Or maybe a better idea ? ;)
>>
>> Thanks for any help,
>>
>> Marc
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>
>

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


Re: File system access in flowscript

Posted by Jan Hoskens <jh...@schaubroeck.be>.
When accessing a file, you need to resolve it's uri. Resolving will 
suffix a path the same way as used in the sitemap.

eg: in your webapp's sitemap you use "pages/mywelcomepage.xml"

mywebapp/pages/mywelcomepage.xml
mywebapp/sitemap.xmap

then resolving will add the whole path /.../mywebapp/ in front of your 
relative path "pages/mywelcomepage.xml".

I tend to use a simple function for this in my flowscript:

function resolveToFile(uri)
{
    var resolver = null;
    var filesource = null;
    try
    {
       resolver = 
cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
       filesource = resolver.resolveURI(uri);
       var file = new java.io.File(new java.net.URI(filesource.getURI()));
       return file;
    }
    finally
    {
       if(filesource != null) resolver.release(filesource);
       cocoon.releaseComponent(resolver);
    }
}


Kind Regards,
Jan

Marc Salvetti wrote:
> Hello,
> 
> i'm trying to access some of the xml files in my webapp directly from 
> the flowscript for creation/deletion
> i can't find a way to adress the correct directory of the servlet
> 
> i tried request:contextPath but it gives only a partial path, i also 
> tried servletPath but it gives the uri of the calling page
> 
> what i'd like to do look like this :
> 
>    var path = contextPath + "/cfm/xdocs/planning/cruise7.xml";
>    var file = new Packages.java.io.File( path);
>    if(!file.isFile()){print(file.getCanonicalPath());}
> 
> Does anyone have a working example of how to get the full path of the 
> directory where my xml files are ?
> Or maybe a better idea ? ;)
> 
> Thanks for any help,
> 
> Marc
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 


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