Example usage for com.vaadin.server StreamResource setCacheTime

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

Introduction

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

Prototype

public void setCacheTime(long cacheTime) 

Source Link

Document

Sets the length of cache expiration time.

Usage

From source file:org.adho.dhconvalidator.ui.ConverterPanel.java

/** Provides a new FileDownloader with the conversion result. */
private void prepareForResultDownload() {
    downloadInfo.setVisible(true);//from  w  ww  .  j  a v  a  2 s .  co  m

    // detach the old file downloader
    if (currentFileDownloader != null) {
        currentFileDownloader.remove();
    }

    StreamResource resultStreamResource = new StreamResource(new StreamSource() {

        @Override
        public InputStream getStream() {
            return createResultStream();
        }
    }, filename.substring(0, filename.lastIndexOf('.')) + ".dhc");

    resultStreamResource.setCacheTime(0);

    currentFileDownloader = new FileDownloader(resultStreamResource);
    currentFileDownloader.extend(btDownloadResult);

    btDownloadResult.setVisible(true);
}

From source file:org.adho.dhconvalidator.ui.PaperSelectionPanel.java

/** Setup UI. */
private void initComponents() {
    Label info = new Label(Messages.getString("PaperSelectionPanel.hintMsg"), ContentMode.HTML);

    languages = new ComboBox(Messages.getString("PaperSelectionPanel.language"),
            Arrays.asList(SubmissionLanguage.values()));
    languages.setNullSelectionAllowed(false);
    languages.setValue(SubmissionLanguage
            .valueOf(PropertyKey.defaultSubmissionLanguage.getValue(SubmissionLanguage.ENGLISH.name())));

    paperTable = new Table(Messages.getString("PaperSelectionPanel.tableTitle"));
    paperTable.setSelectable(true);//from www.  j  av  a  2 s .c o  m
    paperTable.setMultiSelect(true);
    paperTable.setPageLength(4);
    paperTable.addContainerProperty("title", String.class, null);
    paperTable.setColumnHeader("title", Messages.getString("PaperSelectionPanel.titleColumnTitle"));
    paperTable.setWidth("100%");
    paperTable.setImmediate(true);

    btGenerate = new Button(Messages.getString("PaperSelectionPanel.generateButtonCaption"));
    StreamResource templateStreamResource = new StreamResource(new StreamSource() {
        @Override
        public InputStream getStream() {
            return createTemplates();
        }
    }, "your_personal_dh_templates.zip");

    templateStreamResource.setCacheTime(0);
    new FileDownloader(templateStreamResource).extend(btGenerate);

    addCenteredComponent(info);
    addCenteredComponent(languages);
    addCenteredComponent(paperTable);
    addCenteredComponent(btGenerate);

    postDownloadLabel = new Label(
            Messages.getString("PaperSelectionPanel.postDownloadInfo",
                    inputConverter.getTextEditorDescription(),
                    PropertyKey.base_url.getValue() + "popup/DHConvalidatorServices#!converter"),
            ContentMode.HTML);
    postDownloadLabel.addStyleName("postDownloadInfoRedAndBold");
    postDownloadLabel.setVisible(false);

    addCenteredComponent(postDownloadLabel);
}

From source file:org.apache.openaz.xacml.admin.components.PolicyEditor.java

License:Apache License

protected void initializeDownload() {
    ///*from   w  ww  .jav  a 2 s  . com*/
    // Create a stream resource pointing to the file
    //
    StreamResource r = new StreamResource(new StreamResource.StreamSource() {
        private static final long serialVersionUID = 1L;

        @Override
        public InputStream getStream() {
            try {
                return new FileInputStream(self.file);
            } catch (Exception e) {
                logger.error("Failed to open input stream " + self.file);
            }
            return null;
        }
    }, self.file.getName());
    r.setCacheTime(-1);
    r.setMIMEType("application/xml");
    //
    // Extend a downloader to attach to the Export Button
    //
    FileDownloader downloader = new FileDownloader(r);
    downloader.extend(this.buttonExport);
}

From source file:org.vaadin.addon.ewopener.demo.DemoUI.java

License:Apache License

private StreamResource generateResource() {
    StreamResource streamResource = new StreamResource(makeStreamSource(), "simpleTextFile.txt");
    streamResource.setCacheTime(0); // do not cache
    streamResource.setMIMEType("text/plain");
    return streamResource;
}

From source file:org.vaadin.addon.ewopener.demo.DemoUI.java

License:Apache License

private StreamResource streamContent() {
    StreamResource streamResource = new StreamResource(
            () -> new ByteArrayInputStream(LocalDateTime.now().toString().getBytes()), "simpleTextFile.txt");
    streamResource.setCacheTime(0); // do not cache
    streamResource.setMIMEType("text/plain");
    return streamResource;
}

From source file:org.vaadin.easyuploads.ImagePreviewField.java

License:Apache License

@Override
protected void updateDisplayComponent() {
    try {/*  w w  w. ja  v a2s  .c  o m*/
        Image image = (Image) display;
        // check if upload is an image
        if (getValue() != null && ImageIO.read(new ByteArrayInputStream(getValue())) != null) {
            // Update the image according to
            // https://vaadin.com/book/vaadin7/-/page/components.embedded.html
            SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
            String filename = df.format(new Date()) + getLastFileName();
            StreamResource resource = new StreamResource(new ImageSource(getValue()), filename);
            resource.setCacheTime(0);
            image.setSource(resource);
            image.setVisible(true);
        } else {
            image.setVisible(false);
            image.setSource(null);
            setValue(null);
        }
        image.markAsDirty();
        if (display.getParent() == null) {
            getRootLayout().addComponent(display);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}