cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Hertz <danielhe...@shaw.ca>
Subject Flow problem w. renameTo()
Date Sun, 04 Dec 2005 15:30:57 GMT
Can someone help me understand why the following code does not move the 
image stream to a new directory (still uploads to directory set in 
web.xml)? I'm new to java and javascript. Thanks!

== Using the samples/flow/form/upload_example.js as model ==

importPackage(Packages.java.io);
importPackage(Packages.java.util);
importPackage(Packages.java.sql);

cocoon.load("resource://org/apache/cocoon/forms/flow/javascript/Form.js");

function upload() {
   
    var form = new Form("forms/upload_model.xml");
    var k = form.showForm("upload-display-pipeline");

    k.invalidate();

    cocoon.sendPage("upload-success-pipeline.jx",
        {
            uploadContent: handleUpload(form),
            username: form.lookupWidget("user").getValue(),
            filename: 
form.lookupWidget("upload").getValue().getHeaders().get("filename")
        }
    );
}

function handleUpload(form) {
 
  var buf = new java.lang.StringBuffer();
 
  var uploadWidget = form.lookupWidget("upload");
  if (uploadWidget.getValue() != null) {
    var stream = uploadWidget.getValue().getInputStream();
    var reader = new java.io.BufferedReader(new 
java.io.InputStreamReader(stream));
    var line;
    while ((line=reader.readLine())!=null)
      buf.append(line).append("\n");
   
    // File (or directory) to be moved
    var f = new java.io.File(new java.io.File(reader));
   
    // Destination directory
    var dir = new java.io.File(new java.io.File("C:/Uploads/NewDirectory"));
   
    // Move file to new directory
    var success = f.renameTo(new java.io.File(dir, f.getName()));
    if (!success) {
        // File was not moved
    }
    reader.close();
   
    }
    return buf.toString();

      }
 


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


Mime
View raw message