Example usage for com.vaadin.server StreamResource StreamResource

List of usage examples for com.vaadin.server StreamResource StreamResource

Introduction

In this page you can find the example usage for com.vaadin.server StreamResource StreamResource.

Prototype

public StreamResource(StreamSource streamSource, String filename) 

Source Link

Document

Creates a new stream resource for downloading from stream.

Usage

From source file:fi.semantum.strategia.custom.OnDemandFileDownloader.java

License:Open Source License

public OnDemandFileDownloader(OnDemandStreamSource onDemandStreamSource) {
    super(new StreamResource(onDemandStreamSource, "") {
        private static final long serialVersionUID = -7386418918429322891L;

        // Inject the content length
        @Override/*  w w w .  j  a v  a 2 s.c o m*/
        public DownloadStream getStream() {
            DownloadStream ds = super.getStream();
            long size = ((OnDemandStreamSource) getStreamSource()).getFileSize();
            if (size > 0) {
                ds.setParameter("Content-Length", String.valueOf(size));
            }
            return ds;
        }
    });
    this.onDemandStreamSource = onDemandStreamSource;
}

From source file:fi.vtt.RVaadin.RContainer.java

License:Apache License

/**
 * This function is the actual workhorse for
 * {@link RContainer#getEmbeddedGraph}. It gets a Vaadin StreamResource
 * object that contains the corresponding R plot generated by submitting and
 * evaluating the RPlotCall String. The imageName corresponds to the
 * downloadable image name, and device is the format supported by the Cairo
 * graphics engine. The full name of the images shown in the browser are
 * imageName_ISODate_runningId_[sessionId].[device], e.g.
 * 'Image_2012-08-29_001_[bmgolmfgvk].png' to keep them chronologically
 * ordered.//  w  w  w . j ava  2s.  com
 * 
 * @param RPlotCall
 *            the String to be evaluated by R
 * @param width
 *            plot width in pixels
 * @param height
 *            plot height in pixels
 * @param device
 *            A plot device supported by Cairo ('png','pdf',...)
 * @return The image as Embedded Vaadin object
 */
public StreamResource getImageResource(String RPlotCall, int width, int height, String imageName,
        String device) {

    StreamSource imagesource = new RImageSource(rc, RPlotCall, width, height, rSemaphore, device);

    /* Get a systematic name for the image */
    imageCount++;
    String fileName = imageName + "_" + getDateAndCount(imageCount) + "_[" + sessionID + "]." + device;

    /*
     * Create a resource that uses the stream source and give it a name. The
     * constructor will automatically register the resource with the
     * application.
     */
    StreamResource imageresource = new StreamResource(imagesource, fileName);

    /*
     * Instruct browser not to cache the image. See the Book of Vaadin 6
     * page 131.
     */
    imageresource.setCacheTime(0);
    return imageresource;
}

From source file:fi.vtt.RVaadin.RContainer.java

License:Apache License

/**
 * Get a Vaadin Resource object which links to a file in the R working
 * directory. The Resource object can be associated e.g. with Links.
 * //from  ww  w  . j  a  v  a 2s . c om
 * @param filename
 *            The name of the file stored under R current working directory.
 * @return Vaadin Resource object
 */
public Resource getDownloadResource(String filename) {

    StreamSource filesource = new RDownloadSource(filename, this);
    StreamResource fileresource = new StreamResource(filesource, filename);

    fileresource.setCacheTime(0);
    return fileresource;
}

From source file:fr.amapj.view.engine.excelgenerator.LinkCreator.java

License:Open Source License

/**
 * /*from www .j  a va2  s .co m*/
 * @param generator
 * @param addPrefixTelecharger : si true, on ajoute le libell "Telecharger" devant le nom du fichier
 * @return
 */
static public Link createLink(CoreGenerator generator, boolean addPrefixTelecharger) {
    FileInfoDTO fileInfoDTO = new CoreGeneratorService().getFileInfo(generator);

    String titre = fileInfoDTO.nameToDisplay;
    String fileName = fileInfoDTO.fileName;
    String extension = fileInfoDTO.extension;

    StreamResource streamResource = new StreamResource(new CoreResource(fileInfoDTO.generator),
            fileName + "." + extension);
    streamResource.setCacheTime(1000);

    String lien = addPrefixTelecharger ? "Tlcharger " + titre : titre;
    Link extractFile = new Link(lien, streamResource);
    extractFile.setIcon(FontAwesome.DOWNLOAD);
    extractFile.setTargetName("_blank");

    return extractFile;
}

From source file:fr.amapj.view.engine.excelgenerator.TelechargerPopup.java

License:Open Source License

private void addLink(VerticalLayout contentLayout, FileInfoDTO fileInfoDTO) {
    String titre = fileInfoDTO.nameToDisplay;
    String fileName = fileInfoDTO.fileName;
    String extension = fileInfoDTO.extension;

    StreamResource streamResource = new StreamResource(new CoreResource(fileInfoDTO.generator),
            fileName + "." + extension);
    streamResource.setCacheTime(1000);/*from w  w  w  . j  a  v a2s .c  om*/

    Link extractFile = new Link(titre, streamResource);
    extractFile.setIcon(FontAwesome.DOWNLOAD);
    extractFile.setTargetName("_blank");

    contentLayout.addComponent(extractFile);
}

From source file:fr.amapj.view.views.advanced.devtools.PopupAttachementDisplay.java

License:Open Source License

public Link createLink(int pieceNumber, ByteArrayInputStream bais, String fileName) {
    StreamResource streamResource = new StreamResource(() -> bais, fileName);
    streamResource.setCacheTime(1000);/*  w w  w  .jav a 2  s.c  om*/

    Link extractFile = new Link("Pice " + pieceNumber + " - " + fileName, streamResource);
    extractFile.setIcon(FontAwesome.DOWNLOAD);
    extractFile.setTargetName("_blank");

    return extractFile;
}

From source file:fr.amapj.view.views.advanced.devtools.PopupHtmlToPdf.java

License:Open Source License

private void addFieldSaisie() {
    setStepTitle("Conversion");

    tf = new TextArea("Contenu html");
    tf.setWidth("90%");
    tf.setHeight(10, Unit.CM);/*ww w.  j a  va 2  s  .c  o  m*/
    tf.setImmediate(true);
    form.addComponent(tf);

    StreamResource streamResource = new StreamResource(new PdfResource(tf), "test.pdf");
    streamResource.setCacheTime(1000);

    Link extractFile = new Link("Tlcharger le pdf", streamResource);
    extractFile.setIcon(FontAwesome.DOWNLOAD);
    extractFile.setTargetName("_blank");

    form.addComponent(extractFile);
}

From source file:fr.amapj.view.views.logview.LogView.java

License:Open Source License

@Override
protected void drawTable() {
    // Gestion de la liste des colonnes visibles
    cdesTable.setVisibleColumns("sudo", "nom", "prenom", "dbName", "status", "typLog", "ip", "browser",
            "dateIn", "dateOut", "nbError");

    cdesTable.setColumnHeader("sudo", "Sudo");
    cdesTable.setColumnHeader("nom", "Nom");
    cdesTable.setColumnHeader("prenom", "Prnom");
    cdesTable.setColumnHeader("dbName", "Base");
    cdesTable.setColumnHeader("ip", "Ip");
    cdesTable.setColumnHeader("browser", "Browser");
    cdesTable.setColumnHeader("dateIn", "Date connexion");
    cdesTable.setColumnHeader("dateOut", "Date dconnexion");
    cdesTable.setColumnHeader("status", "Etat");
    cdesTable.setColumnHeader("typLog", "Type");
    cdesTable.setColumnHeader("nbError", "Erreur");
    cdesTable.setColumnAlignment("nbError", Align.CENTER);

    cdesTable.setConverter("dateIn", new DateTimeToStringConverter());
    cdesTable.setConverter("dateOut", new DateTimeToStringConverter());

    cdesTable.addGeneratedColumn("Tlcharger ...", new ColumnGenerator() {
        @Override/*from  w  w  w  .j a  v a2s .c  o  m*/
        public Object generateCell(final Table source, final Object itemId, Object columnId) {
            LogAccessDTO dto = (LogAccessDTO) itemId;
            if (dto.logFileName == null) {
                Label l = new Label("Pas de fichier");
                return l;
            }
            LogFileResource logFileResource = new LogFileResource(dto.logFileName);

            Link extractFile = new Link("Tlcharger le fichier de log",
                    new StreamResource(logFileResource, dto.logFileName + ".log"));
            return extractFile;
        }
    });
}

From source file:fr.amapj.view.views.logview.TelechargerLogPopup.java

License:Open Source License

protected void createContent(VerticalLayout contentLayout) {
    contentLayout.addComponent(/* w  w  w  . j a  v a  2s . c  o  m*/
            new Label("Veuillez cliquer sur le lien du fichier que vous souhaitez tlcharger"));

    String name = "global";

    LogFileResource logFileResource = new LogFileResource(name);

    Link extractFile = new Link("Tlcharger le fichier global.log",
            new StreamResource(logFileResource, name + ".log"));

    contentLayout.addComponent(extractFile);
}

From source file:fr.univlorraine.mondossierweb.controllers.CalendrierController.java

License:Apache License

/**
 * //from  w ww .  ja va 2 s  .  c om
 * @return le fichier pdf du calendrier des examens.
 */
public com.vaadin.server.Resource exportPdf() {

    String nomFichier = applicationContext.getMessage("pdf.calendrier.title", null, Locale.getDefault()) + " "
            + MainUI.getCurrent().getEtudiant().getNom().replace('.', ' ').replace(' ', '_') + ".pdf";

    nomFichier = nomFichier.replaceAll(" ", "_");

    StreamResource.StreamSource source = new StreamResource.StreamSource() {
        private static final long serialVersionUID = 1L;

        @Override
        public InputStream getStream() {
            try {
                ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(OUTPUTSTREAM_SIZE);
                PdfWriter docWriter = null;
                Document document = configureDocument(MARGE_PDF);
                docWriter = PdfWriter.getInstance(document, baosPDF);
                docWriter.setEncryption(null, null, PdfWriter.AllowPrinting, PdfWriter.ENCRYPTION_AES_128);
                docWriter.setStrictImageSequence(true);
                creerPdfCalendrier(document, MainUI.getCurrent().getEtudiant());
                docWriter.close();
                baosPDF.close();
                //Creation de l'export
                byte[] bytes = baosPDF.toByteArray();
                return new ByteArrayInputStream(bytes);
            } catch (DocumentException e) {
                LOG.error("Erreur  la gnration du calendrier des examens : DocumentException ", e);
                return null;
            } catch (IOException e) {
                LOG.error("Erreur  la gnration du calendrier des examens : IOException ", e);
                return null;
            }

        }
    };

    // Cration de la ressource 
    StreamResource resource = new StreamResource(source, nomFichier);
    resource.setMIMEType("application/force-download;charset=UTF-8");
    resource.setCacheTime(0);
    return resource;

}