Return-Path: X-Original-To: apmail-cocoon-users-archive@www.apache.org Delivered-To: apmail-cocoon-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0703DE8A6 for ; Sat, 29 Dec 2012 11:06:05 +0000 (UTC) Received: (qmail 39603 invoked by uid 500); 29 Dec 2012 11:06:04 -0000 Delivered-To: apmail-cocoon-users-archive@cocoon.apache.org Received: (qmail 39480 invoked by uid 500); 29 Dec 2012 11:06:01 -0000 Mailing-List: contact users-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: users@cocoon.apache.org List-Id: Delivered-To: mailing list users@cocoon.apache.org Received: (qmail 39441 invoked by uid 99); 29 Dec 2012 11:06:00 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 29 Dec 2012 11:06:00 +0000 X-ASF-Spam-Status: No, hits=2.9 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [212.50.160.61] (HELO smtpout.karoo.kcom.com) (212.50.160.61) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 29 Dec 2012 11:05:53 +0000 X-IronPort-AV: E=Sophos;i="4.84,376,1355097600"; d="scan'208,217";a="934210711" Received: from unknown (HELO [192.168.0.2]) ([82.153.126.91]) by smtpout.karoo.kcom.com with ESMTP; 29 Dec 2012 11:05:31 +0000 Message-ID: <50DECE7D.2010005@didm.co.uk> Date: Sat, 29 Dec 2012 11:05:33 +0000 From: Peter Sparkes Reply-To: peter@didm.co.uk User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: users@cocoon.apache.org Subject: Re: Flowscript - delete file References: <50DC14BF.8070005@didm.co.uk> <1537829089.20121227124200@correios.de> <50DC8168.4030709@didm.co.uk> <702941723.20121227193543@correios.de> <50DEA293.5040200@didm.co.uk> In-Reply-To: <50DEA293.5040200@didm.co.uk> Content-Type: multipart/alternative; boundary="------------010706030602010200040908" X-Virus-Checked: Checked by ClamAV on apache.org --------------010706030602010200040908 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Solved I found the answer at http://markmail.org/message/7psype56uhu5kbad#query:+page:1+mid:ezqkl6i255bjdw75+state:results I amended file.delete(); to: file["delete"](); and it works, the file is deleted. However, I don't know why it works Thank you all for your help Peter On 29/12/2012 07:58, Peter Sparkes wrote: > Hi Martin and Robby, > > Thank you both for your help, what I have ended up with is: > > importClass(Packages.java.io.File); > importClass(Packages.java.io.FileNotFoundException); > > function deletefile() { > > //var filePath = cocoon.parameters["file"]; > > var filePath = "D:/cocoon-2.1.11-wl/build/webapp/B&B/xml/9999.xml"; //for testing > var file = new File(filePath); > try { > if (!file.exists()) { > throw new FileNotFoundException(filePath); > } > file.delete(); > cocoon.sendPage('deletefilesuccess',{file:filePath}); > } catch (e) { > cocoon.sendPage('deletefileerror',{file:e}); > } > } > > However, file.delete(); produces a syntax error. > > If I comment out file.delete(), the rest of the script works correctly: > > * If 9999.xml exists, deletefilesuccess is accessed > * If 9999.xml does not exist, deletefileerror is accessed and I get: > > > Error File java.io.FileNotFoundException: D:/cocoon-2.1.11-wl/build/webapp/B&B/xml/9999.xml > Not Found > > What's wrong with file.delete(); ? > > Regards > > Peter > > > > On 27/12/2012 18:35, Martin Heiden wrote: >> Hi Peter, >> >> Ok, I missed something: >> >> var xml_file = Packages.java.io.File("D:\cocoon-2.1.11-wl\build\webapp\B&B\xml" + file + ".xml"); >> >> should be: >> >> var xml_file = new Packages.java.io.File("D:\cocoon-2.1.11-wl\build\webapp\B&B\xml" + file + ".xml"); >> >> But you should try the function Robby sent to the list. It's much >> cleaner. >> >> Regards, >> >> Martin. >> >> >> Thursday, December 27, 2012, 6:12:08 PM, you wrote: >> >> PS> Hi Martin >> >> PS> Thanks for your suggestion, unfortunately I get the same error. The error log gives: >> >> PS> ERROR (2012-12-27) 15:30.46:723 [flow] (/office/deletefile_9999) PoolThread-4/JSErrorReporter: >> PS>"file:///D:/cocoon-2.1.11-wl/build/webapp/office/flow/deletefile.js", line 13: missing name after . >> PS> operator >> PS> ERROR (2012-12-27) 15:30.46:723 [sitemap.handled-errors] (/office/deletefile_9999) >> PS> PoolThread-4/ErrorHandlerHelper: Sitemap: error calling function 'deletefile' >> PS> at - >> PS>file:///D:/cocoon-2.1.11-wl/build/webapp/office/sitemap.xmap:230:37 >> PS> at - >> PS>file:///D:/cocoon-2.1.11-wl/build/webapp/sitemap.xmap:783:90 >> PS> org.mozilla.javascript.EvaluatorException: >> PS>"file:///D:/cocoon-2.1.11-wl/build/webapp/office/flow/deletefile.js", line 1: Compilation produced 1 >> PS> syntax errors. >> PS> at >> PS> org.apache.cocoon.components.flow.javascript.JSErrorReporter.runtimeError(JSErrorReporter.java:67) >> >> PS> regards >> >> PS> Peter >> >> >> PS> On 27/12/2012 11:42, Martin Heiden wrote: >>>> Hi Peter, >>>> >>>> PS> //Delete file >>>> PS> Packages.java.io.File.xml_file.delete(); >>>> >>>> Try >>>> >>>> xml_file.delete(); >>>> >>>> You just have to add the full "path" to the class when you >>>> construct it. After this, the variable contains a reference and you >>>> can just use it. >>>> >>>> Regards, >>>> >>>> Martin. >>>> >>>> >>>> Thursday, December 27, 2012, 10:28:31 AM, you wrote: >>>> >>>> PS> Hi, >>>> >>>> PS> I am trying to delete xml files using the following flowscript: >>>> >>>> PS> function deletefile() { >>>> >>>> PS> //file to be deleted >>>> PS> var file = >>>> PS> Packages.java.lang.String(cocoon.parameters["file"]); >>>> >>>> PS> try { >>>> PS> // creating a link to the file to be deleted >>>> PS> var xml_file = >>>> PS> Packages.java.io.File("D:\cocoon-2.1.11-wl\build\webapp\B&B\xml" + file >>>> PS> + ".xml"); >>>> >>>> PS> //Delete file >>>> PS> Packages.java.io.File.xml_file.delete(); >>>> >>>> PS> // .txt file with OK message >>>> PS> cocoon.sendPage("success.txt", null); >>>> PS> } >>>> PS> catch(ex){ >>>> PS> cocoon.log.error(ex); >>>> PS> // Smth. went wrong. Sending a error.txt file to the browser >>>> PS> cocoon.sendPage("error.txt", null); >>>> PS> } >>>> >>>> PS> } >>>> >>>> PS> and get "Compilation produced 1 syntax errors" >>>> >>>> PS> The error log contains: >>>> >>>> PS> ERROR ............ deletefile.js", line 13: missing name after . operator >>>> >>>> PS> line 13 is: >>>> >>>> PS> Packages.java.io.File.xml_file.delete(); >>>> >>>> PS> What I am doing wrong? >>>> >>>> PS> Peter >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail:users-unsubscribe@cocoon.apache.org >>>> For additional commands, e-mail:users-help@cocoon.apache.org >>>> >>>> >> >> >> Ciao, >> Martin >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail:users-unsubscribe@cocoon.apache.org >> For additional commands, e-mail:users-help@cocoon.apache.org >> >> > --------------010706030602010200040908 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit
Solved

I found the answer at http://markmail.org/message/7psype56uhu5kbad#query:+page:1+mid:ezqkl6i255bjdw75+state:results

I amended file.delete(); to:

file["delete"]();

and it works,  the file is deleted. However, I don't know why it works

Thank you all for your help

Peter

On 29/12/2012 07:58, Peter Sparkes wrote:
Hi Martin and Robby,

Thank you both for your help, what I have ended up with is:

importClass(Packages.java.io.File);
importClass(Packages.java.io.FileNotFoundException);

function deletefile() {
   
    //var filePath = cocoon.parameters["file"];
   
    var filePath = "D:/cocoon-2.1.11-wl/build/webapp/B&B/xml/9999.xml";  //for testing
    var file = new File(filePath);
     try {
        if (!file.exists()) {
           throw new FileNotFoundException(filePath);
        }
        file.delete();
        cocoon.sendPage('deletefilesuccess',{file:filePath});
    } catch (e) {
        cocoon.sendPage('deletefileerror',{file:e});
    }
}

However, file.delete(); produces a syntax error.

If I comment out file.delete(), the rest of the script works correctly:
  • If 9999.xml exists, deletefilesuccess is accessed
  • If 9999.xml does not exist, deletefileerror is accessed and I get:

    Error File java.io.FileNotFoundException: D:/cocoon-2.1.11-wl/build/webapp/B&B/xml/9999.xml Not Found

What's wrong with file.delete(); ?

Regards

Peter



On 27/12/2012 18:35, Martin Heiden wrote:
Hi Peter,

Ok, I missed something:

 var xml_file = Packages.java.io.File("D:\cocoon-2.1.11-wl\build\webapp\B&B\xml" + file + ".xml");

should be:

 var xml_file = new Packages.java.io.File("D:\cocoon-2.1.11-wl\build\webapp\B&B\xml" + file + ".xml");

But you should try the function Robby sent to the list. It's much
cleaner.

Regards,

  Martin.


Thursday, December 27, 2012, 6:12:08 PM, you wrote:

PS> Hi Martin

PS> Thanks for your suggestion, unfortunately I get the same  error. The error log gives:

PS> ERROR (2012-12-27) 15:30.46:723 [flow] (/office/deletefile_9999) PoolThread-4/JSErrorReporter:
PS> "file:///D:/cocoon-2.1.11-wl/build/webapp/office/flow/deletefile.js", line 13: missing name after .
PS> operator
PS> ERROR (2012-12-27) 15:30.46:723 [sitemap.handled-errors] (/office/deletefile_9999)
PS> PoolThread-4/ErrorHandlerHelper: Sitemap: error calling function 'deletefile'
PS>      at <map:call> -
PS> file:///D:/cocoon-2.1.11-wl/build/webapp/office/sitemap.xmap:230:37
PS>      at <map:mount> -
PS> file:///D:/cocoon-2.1.11-wl/build/webapp/sitemap.xmap:783:90
PS> org.mozilla.javascript.EvaluatorException: 
PS> "file:///D:/cocoon-2.1.11-wl/build/webapp/office/flow/deletefile.js", line 1: Compilation produced 1
PS> syntax errors.
PS>      at 
PS> org.apache.cocoon.components.flow.javascript.JSErrorReporter.runtimeError(JSErrorReporter.java:67)

PS> regards

PS> Peter


PS> On 27/12/2012 11:42, Martin Heiden wrote:
Hi Peter,

PS>              //Delete file
PS>              Packages.java.io.File.xml_file.delete();

Try

xml_file.delete();

You just have to add the full "path" to the class when you
construct it. After this, the variable contains a reference and you
can just use it.

Regards,

   Martin.


Thursday, December 27, 2012, 10:28:31 AM, you wrote:

PS> Hi,

PS> I am trying to delete xml files using the following flowscript:

PS>     function deletefile() {

PS>          //file to be deleted
PS>          var file =
PS> Packages.java.lang.String(cocoon.parameters["file"]);

PS>          try {
PS>              // creating a link to the file to be deleted
PS>              var xml_file =
PS> Packages.java.io.File("D:\cocoon-2.1.11-wl\build\webapp\B&B\xml" + file
PS>     + ".xml");

PS>              //Delete file
PS>              Packages.java.io.File.xml_file.delete();

PS>              //  .txt file with OK message
PS>              cocoon.sendPage("success.txt", null);
PS>          }
PS>          catch(ex){
PS>              cocoon.log.error(ex);
PS>              // Smth. went wrong. Sending a error.txt file to the browser
PS>            cocoon.sendPage("error.txt", null);
PS>          }

PS>     }

PS> and get "Compilation produced 1 syntax errors"

PS> The error log contains:

PS>     ERROR ............    deletefile.js", line 13: missing name after . operator

PS> line 13 is:

PS>     Packages.java.io.File.xml_file.delete();

PS> What I am doing wrong?

PS> Peter







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




Ciao,
 Martin


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




--------------010706030602010200040908--