You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Martin Holmes <mh...@uvic.ca> on 2009/01/09 23:36:08 UTC

mkdir in flowscript fails

Hi there,

I'm trying to write flowscript which saves the output of a pipeline onto 
the file system. I've successfully done this for several pipelines, 
following the instructions on the WIKI. Up to now, I've been saving all 
the output files in an existing directory. Now I want to save one 
pipeline into a subdirectory, which I create on the fly based on the 
document id:

var xhtml_folder = new Packages.java.io.File("teiJournal/backups/" + 
styleGuide + "/" +  docId);

      if (!xhtml_folder.exists()){

        xhtml_folder.mkdir();

      }

The new folder is named with the string in docId, and its parent folder 
already exists. The parent folder is writable by the user under which 
Cocoon is running (in fact, it's owned by that user), and other 
pipelines can already save files into it; however, I just can't get 
Cocoon to create the subfolder. This is running on a RedHat server. If I 
modify the function to write the file directly to the existing 
directory, it works fine.

Does anyone have any idea why this might fail? This is the error, 
followed by the complete flowscript function:

ERROR (2009-01-09) 14:30.51:770 [flow] 
(/ialltjournal/teiJournal/backups/apa/doc.xhtml?id=iallt_40_01_sawhill) 
http-8081-7/MemberBox: JavaException: java.io.FileNotFoundException: 
/usr/local/apache-tomcat-dev/webapps/ialltjournal/teiJournal/backups/apa/iallt_40_01_sawhill/iallt_40_01_sawhill.xhtml 
(No such file or directory)

(In other words, the output file is not saved, because the new directory 
has not been successfully created.)

function makeBackupXHTML() {
    var xml_file;
    var xhtml_folder;
    var xhtml_file;
    var outstreamXHTML;

    try {

// Get required variables.

      var folder = Packages.java.lang.String(cocoon.parameters["folder"]);
      var styleGuide = 
Packages.java.lang.String(cocoon.parameters["styleGuide"]);
      var qParams = 
Packages.java.lang.String(cocoon.parameters["urlQueryString"]);
      var arrTemp = qParams.split("&");
      var docId = arrTemp[0].split("=")[1];

//Create a directory to dump the files to

      xhtml_folder = new Packages.java.io.File("teiJournal/backups/" + 
styleGuide + "/" +  docId);
      if (!xhtml_folder.exists()){
        xhtml_folder.mkdir();
      }

// Create link to file

      xhtml_file = Packages.java.io.File(folder + "teiJournal/backups/" 
+ styleGuide + "/" + docId + "/" + docId + ".xhtml");

// Create outputstream to dump the results of conversion to the file

      outstreamXHTML = new Packages.java.io.FileOutputStream( xhtml_file );

// Call cocoon pipeline and save the results to the outputstream
      var pipePath = styleGuide + "/doc.xhtml?id=" + docId;
      cocoon.processPipelineTo(pipePath, null, outstreamXHTML);

      outstreamXHTML.close();

// Bounce back to the backups list page.
      cocoon.redirectTo("../../backups.xhtml?styleGuide=" + styleGuide + 
"#" + docId, true);

    } catch( ex ) {
       cocoon.log.error(ex);
// Smth. went wrong. Sending a error.txt file to the browser
       cocoon.sendPage("backups/save_file_error.txt", null);
    }
}

All help appreciated,
Martin



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


Re: mkdir in flowscript fails

Posted by Martin Holmes <mh...@uvic.ca>.
Hi Steven,

I think you nailed it -- I'd omitted the folder prefix. It's set to 
{realpath:/} in the sitemap.

A fresh pair of eyes is a wonderful thing. Thanks indeed!

Cheers,
Martin

Steven D. Majewski wrote:
> 
> 
> 
> 
> On Jan 9, 2009, at 5:36 PM, Martin Holmes wrote:
> 
>> Hi there,
>>
>> I'm trying to write flowscript which saves the output of a pipeline 
>> onto the file system. I've successfully done this for several 
>> pipelines, following the instructions on the WIKI. Up to now, I've 
>> been saving all the output files in an existing directory. Now I want 
>> to save one pipeline into a subdirectory, which I create on the fly 
>> based on the document id:
>>
> 
> 
> Using relative pathnames is kind of iffy:
> 
>> var xhtml_folder = new Packages.java.io.File("teiJournal/backups/" + 
>> styleGuide + "/" +  docId);
>>
>>     if (!xhtml_folder.exists()){
>>
>>       xhtml_folder.mkdir();
>>
>>     }
>>
> 
> 
> If you're running cocoon in tomcat, the current working directory will 
> likely be the directory you
> were in when you ran startup.sh -- not necessarily tomcat or cocoons 
> home directory. ( I'm guessing
> that other servlet containers do the same thing. )
> 
> 
> 
> 
>> The new folder is named with the string in docId, and its parent 
>> folder already exists. The parent folder is writable by the user under 
>> which Cocoon is running (in fact, it's owned by that user), and other 
>> pipelines can already save files into it; however, I just can't get 
>> Cocoon to create the subfolder. This is running on a RedHat server. If 
>> I modify the function to write the file directly to the existing 
>> directory, it works fine.
>>
>> Does anyone have any idea why this might fail? This is the error, 
>> followed by the complete flowscript function:
>>
>> ERROR (2009-01-09) 14:30.51:770 [flow] 
>> (/ialltjournal/teiJournal/backups/apa/doc.xhtml?id=iallt_40_01_sawhill) 
>> http-8081-7/MemberBox: JavaException: java.io.FileNotFoundException: 
>> /usr/local/apache-tomcat-dev/webapps/ialltjournal/teiJournal/backups/apa/iallt_40_01_sawhill/iallt_40_01_sawhill.xhtml 
>> (No such file or directory)
>>
>> (In other words, the output file is not saved, because the new 
>> directory has not been successfully created.)
>>
>> function makeBackupXHTML() {
>>   var xml_file;
>>   var xhtml_folder;
>>   var xhtml_file;
>>   var outstreamXHTML;
>>
>>   try {
>>
>> // Get required variables.
>>
>>     var folder = Packages.java.lang.String(cocoon.parameters["folder"]);
>>     var styleGuide = 
>> Packages.java.lang.String(cocoon.parameters["styleGuide"]);
>>     var qParams = 
>> Packages.java.lang.String(cocoon.parameters["urlQueryString"]);
>>     var arrTemp = qParams.split("&");
>>     var docId = arrTemp[0].split("=")[1];
>>
>> //Create a directory to dump the files to
>>
>>     xhtml_folder = new Packages.java.io.File("teiJournal/backups/" + 
>> styleGuide + "/" +  docId);
>>     if (!xhtml_folder.exists()){
>>       xhtml_folder.mkdir();
>>     }
>>
> 
> And here you're prefixing teiJournal with parameter "folder" ,
> so the path printed in the error message for the file may not match the 
> relative directory path name
> for the directory you created.  ( What is being passed as parameter 
> "folder" ? )
> 
> Rather than concatenating the pathnames twice, you might use the
> 
>     File(File parent, String child)
> 
> constructor for the second instance, using File xhtml_folder as the 
> parent File.
> This will guarantee that they are both on the same path.
> 
> 
>> // Create link to file
>>
>>
>>     xhtml_file = Packages.java.io.File(folder + "teiJournal/backups/" 
>> + styleGuide + "/" + docId + "/" + docId + ".xhtml");
>>
>> // Create outputstream to dump the results of conversion to the file
>>
>>     outstreamXHTML = new Packages.java.io.FileOutputStream( xhtml_file );
>>
>> // Call cocoon pipeline and save the results to the outputstream
>>     var pipePath = styleGuide + "/doc.xhtml?id=" + docId;
>>     cocoon.processPipelineTo(pipePath, null, outstreamXHTML);
>>
>>     outstreamXHTML.close();
>>
>> // Bounce back to the backups list page.
>>     cocoon.redirectTo("../../backups.xhtml?styleGuide=" + styleGuide + 
>> "#" + docId, true);
>>
>>   } catch( ex ) {
>>      cocoon.log.error(ex);
>> // Smth. went wrong. Sending a error.txt file to the browser
>>      cocoon.sendPage("backups/save_file_error.txt", null);
>>   }
>> }
>>
> 
> 
> 
> -- Steve Majewski / UVA Alderman Library


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


Re: mkdir in flowscript fails

Posted by "Steven D. Majewski" <sd...@virginia.edu>.



On Jan 9, 2009, at 5:36 PM, Martin Holmes wrote:

> Hi there,
>
> I'm trying to write flowscript which saves the output of a pipeline  
> onto the file system. I've successfully done this for several  
> pipelines, following the instructions on the WIKI. Up to now, I've  
> been saving all the output files in an existing directory. Now I  
> want to save one pipeline into a subdirectory, which I create on the  
> fly based on the document id:
>


Using relative pathnames is kind of iffy:

> var xhtml_folder = new Packages.java.io.File("teiJournal/backups/" +  
> styleGuide + "/" +  docId);
>
>     if (!xhtml_folder.exists()){
>
>       xhtml_folder.mkdir();
>
>     }
>


If you're running cocoon in tomcat, the current working directory will  
likely be the directory you
were in when you ran startup.sh -- not necessarily tomcat or cocoons  
home directory. ( I'm guessing
that other servlet containers do the same thing. )




> The new folder is named with the string in docId, and its parent  
> folder already exists. The parent folder is writable by the user  
> under which Cocoon is running (in fact, it's owned by that user),  
> and other pipelines can already save files into it; however, I just  
> can't get Cocoon to create the subfolder. This is running on a  
> RedHat server. If I modify the function to write the file directly  
> to the existing directory, it works fine.
>
> Does anyone have any idea why this might fail? This is the error,  
> followed by the complete flowscript function:
>
> ERROR (2009-01-09) 14:30.51:770 [flow] (/ialltjournal/teiJournal/ 
> backups/apa/doc.xhtml?id=iallt_40_01_sawhill) http-8081-7/MemberBox:  
> JavaException: java.io.FileNotFoundException: /usr/local/apache- 
> tomcat-dev/webapps/ialltjournal/teiJournal/backups/apa/ 
> iallt_40_01_sawhill/iallt_40_01_sawhill.xhtml (No such file or  
> directory)
>
> (In other words, the output file is not saved, because the new  
> directory has not been successfully created.)
>
> function makeBackupXHTML() {
>   var xml_file;
>   var xhtml_folder;
>   var xhtml_file;
>   var outstreamXHTML;
>
>   try {
>
> // Get required variables.
>
>     var folder =  
> Packages.java.lang.String(cocoon.parameters["folder"]);
>     var styleGuide =  
> Packages.java.lang.String(cocoon.parameters["styleGuide"]);
>     var qParams =  
> Packages.java.lang.String(cocoon.parameters["urlQueryString"]);
>     var arrTemp = qParams.split("&");
>     var docId = arrTemp[0].split("=")[1];
>
> //Create a directory to dump the files to
>
>     xhtml_folder = new Packages.java.io.File("teiJournal/backups/" +  
> styleGuide + "/" +  docId);
>     if (!xhtml_folder.exists()){
>       xhtml_folder.mkdir();
>     }
>

And here you're prefixing teiJournal with parameter "folder" ,
so the path printed in the error message for the file may not match  
the relative directory path name
for the directory you created.  ( What is being passed as parameter  
"folder" ? )

Rather than concatenating the pathnames twice, you might use the

	File(File parent, String child)

constructor for the second instance, using File xhtml_folder as the  
parent File.
This will guarantee that they are both on the same path.


> // Create link to file
>
>
>     xhtml_file = Packages.java.io.File(folder + "teiJournal/ 
> backups/" + styleGuide + "/" + docId + "/" + docId + ".xhtml");
>
> // Create outputstream to dump the results of conversion to the file
>
>     outstreamXHTML = new  
> Packages.java.io.FileOutputStream( xhtml_file );
>
> // Call cocoon pipeline and save the results to the outputstream
>     var pipePath = styleGuide + "/doc.xhtml?id=" + docId;
>     cocoon.processPipelineTo(pipePath, null, outstreamXHTML);
>
>     outstreamXHTML.close();
>
> // Bounce back to the backups list page.
>     cocoon.redirectTo("../../backups.xhtml?styleGuide=" + styleGuide  
> + "#" + docId, true);
>
>   } catch( ex ) {
>      cocoon.log.error(ex);
> // Smth. went wrong. Sending a error.txt file to the browser
>      cocoon.sendPage("backups/save_file_error.txt", null);
>   }
> }
>



-- Steve Majewski / UVA Alderman Library


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


Re: mkdir in flowscript fails

Posted by Martin Holmes <mh...@uvic.ca>.
This is Cocoon 2.1, by the way -- forgot to mention that.

Martin Holmes wrote:
> Hi there,
> 
> I'm trying to write flowscript ...


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