cocoon-users-fr mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marc Salvetti <m...@notremanou.net>
Subject Re: Flowscript et Upload
Date Wed, 27 Jul 2005 08:14:25 GMT
Pour cforms il y a cette javadoc :

http://www.jdocs.com/cocoon/1.2.5.1/api/org/apache/cocoon/forms/formmodel/package-summary.html

sinon pour l'upload j'avait fait ca il y a longtemps pour des photos, tu 
trouveras pe qq lignes a copier coller ici, mais je ne suis pas sur de 
la qualité de ce code ;)

    // Handle newly uploaded files
    for(var i=0; i<form.getChild("photos").getSize(); i++){
        var row = form.getChild("photos").getRow(i);
        var pic = row.getChild("upload").getValue();
        var uri;
        if(pic != null){
            print("upload : "+pic.getheaders().get("filename"));
            upImg =  readImage(pic);
           
            //If the upload replace an old file, delete this file and 
the thumbnail
            if(row.getChild("src").getValue() != null){
                uri = form.getChild("folderPath").getValue() + "/" + 
row.getChild("src").getValue();
                var oldImage = resolveToFile( uri);
                if(oldImage.isFile()){
                    oldImage["delete"]();
                }
                uri = form.getChild("folderPath").getValue() + 
"/thumbnails/" + row.getChild("src").getValue();
                oldImage = resolveToFile( uri);
                if(oldImage.isFile()){
                    oldImage["delete"]();
                }
            }

            uri = form.getChild("folderPath").getValue() + "/" + 
pic.getheaders().get("filename");
            var newImage = resolveToFile( uri);
            uri = form.getChild("folderPath").getValue() + 
"/thumbnails/" + pic.getheaders().get("filename");
            var newThumb = resolveToFile( uri);

            //try to copy the image and thumbnail to local filesystem
            copyFiles(upImg, newImage, newThumb);

        }

    }

    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);
       }
}
function readImage(file){
    var upImg =  javax.imageio.ImageIO.read(file.getInputStream());
    try{
        upImg.getHeight();
    }catch(e){
        throw new Exception("Unreadable image");
    }
    return upImg;
}
function copyFiles(upImg,    newImage, newThumbnail) {
    var THUMBNAILS_MAX_DIM = 100;
    var IMAGES_MAX_WIDTH = 500;

    var scale = THUMBNAILS_MAX_DIM / upImg.getHeight();
    if(upImg.getWidth() > upImg.getHeight()){
        scale = THUMBNAILS_MAX_DIM / upImg.getWidth();
    }
//           Determine size of new tuhmbnail. One of them should equal 
maxDim.
    var scaledW = scale * upImg.getWidth();
    var scaledH = scale * upImg.getHeight();
    var outImg = new java.awt.image.BufferedImage(scaledW, scaledH, 
upImg.getType());
    var g = outImg.createGraphics();
//        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, 
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.drawImage(upImg,0,0,scaledW, scaledH, null);
    javax.imageio.ImageIO.write(outImg, "jpg", newThumbnail);

    //Checks if the width or height exceeds the limits
    scale = 0;
    if(upImg.getWidth() > IMAGES_MAX_WIDTH){
        scale = IMAGES_MAX_WIDTH / upImg.getWidth();
        scaledW = scale * upImg.getWidth();
        scaledH = scale * upImg.getHeight();
    }

    //Resize to the limits if so
    if(scale != 0){
        outImg = new java.awt.image.BufferedImage(scaledW, scaledH, 
upImg.getType());
        g = outImg.createGraphics();
        g.drawImage(upImg,0,0,scaledW, scaledH, null);
        javax.imageio.ImageIO.write(outImg, "jpg", newImage);
    }else{
        javax.imageio.ImageIO.write(upImg, "jpg", newImage);
    }
}

Janet Yvan a écrit :

>Salut.
>
> 
>
>J’ai besoin d’uploader des fichiers d’icones avec CForms et les placer dans
>un de mes répertoires qui sert pour les resources d’images. J’ai cru
>comprendre que ça se faisait dans mon flowscript, mais je n’ai trouvé l’API
>JScriptnulle part ??
>
>Quelqu’un aurait-il une idée (et / ou simplement une URL pour l’API)
>
> 
>
>Merci d’avance.
>
> 
>
>Yvan
>
> 
>
>
>  
>

---------------------------------------------------------------------
Liste francophone Apache Cocoon -- http://cocoon.apache.org/fr/
Pour vous desinscrire : mailto:users-fr-unsubscribe@cocoon.apache.org
Autres commandes : mailto:users-fr-help@cocoon.apache.org


Mime
View raw message