Package com.vaadin.server

Examples of com.vaadin.server.StreamResource


        browser.setId("browser");
        browser.setWidth("600px");
        browser.setHeight("300px");
        browser.setAlternateText("Browser alternative text");
        final TextSource textSource = new TextSource("initial");
        final StreamResource textResource = new StreamResource(textSource,
                "initial.txt");
        textResource.setMIMEType("text/plain");
        browser.setSource(textResource);
        addComponent(browser);

        page1.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                TextSource helloSource = new TextSource("Hello World");
                StreamResource helloResource = new StreamResource(helloSource,
                        "helloworld.txt");
                helloResource.setMIMEType("text/plain");
                browser.setSource(helloResource);
            }
        });

        page2.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                TextSource helloSource = new TextSource("Lorem Ipsum");
                StreamResource helloResource = new StreamResource(helloSource,
                        "loremipsum.txt");
                helloResource.setMIMEType("text/plain");
                browser.setSource(helloResource);
            }
        });

        page3.addClickListener(new Button.ClickListener() {
View Full Code Here


                    + event.getMIMEType(), ContentMode.HTML));
            statusLayout.addComponent(new Label("<b>Size:</b> "
                    + event.getLength() + " bytes.", ContentMode.HTML));

            statusLayout.addComponent(new Link("Download "
                    + buffer.getFileName(), new StreamResource(buffer, buffer
                    .getFileName())));

            status.setVisible(true);
        }
    }
View Full Code Here

                            + event.getMIMEType(), ContentMode.HTML));
                    statusLayout.addComponent(new Label("<b>Size:</b> "
                            + event.getLength() + " bytes.", ContentMode.HTML));

                    statusLayout.addComponent(new Link("Download "
                            + buffer.getFileName(), new StreamResource(buffer,
                            buffer.getFileName())));

                    statusLayout.setVisible(true);
                }
View Full Code Here

    }

    protected void download(String target) {
        String filename = "filename";
        StreamResource streamResource = new StreamResource(new StreamSource() {

            @Override
            public InputStream getStream() {
                try {
                    return new FileInputStream("FIXME C:/temp/file.xls");
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    return null;
                }
            }
        }, filename + ".xls");
        streamResource.setCacheTime(5000); // no cache (<=0) does not work with
        // IE8
        streamResource.setMIMEType("application/x-msexcel");

        getMainWindow().open(streamResource, target);

    }
View Full Code Here

    @Override
    protected void init(VaadinRequest request) {
        Button downloadButton = new Button("Download image");

        StreamResource myResource = createResource();
        FileDownloader fileDownloader = new FileDownloader(myResource);
        fileDownloader.extend(downloadButton);

        setContent(downloadButton);
    }
View Full Code Here

        setContent(downloadButton);
    }

    private StreamResource createResource() {
        return new StreamResource(new StreamSource() {
            @Override
            public InputStream getStream() {
                String text = "My image";
                BufferedImage bi = new BufferedImage(100, 30,
                        BufferedImage.TYPE_3BYTE_BGR);
View Full Code Here

    protected void setup() {

        final Styles stylesheet = Page.getCurrent().getStyles();

        // Inject some resources initially
        final StreamResource initialResource = new StreamResource(
                new StreamResource.StreamSource() {

                    @Override
                    public InputStream getStream() {
                        return new ByteArrayInputStream(
                                ".hello, .world { color:silver; }".getBytes());
                    }
                }, "mystyles-" + System.currentTimeMillis() + ".css");
        stylesheet.add(initialResource);

        Label hello = new Label(
                "<span class='hello'>Hello</span> <span class='world'>world</span>",
                ContentMode.HTML);
        addComponent(hello);

        final TextArea cssToInject = new TextArea();
        cssToInject.setImmediate(true);
        addComponent(cssToInject);

        Button inject = new Button("Inject!", new Button.ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                stylesheet.add(cssToInject.getValue());
                cssToInject.setValue("");
            }
        });
        addComponent(inject);

        Button injectRandom = new Button("Inject as resource!",
                new Button.ClickListener() {

                    @Override
                    public void buttonClick(ClickEvent event) {

                        final String css = cssToInject.getValue();

                        stylesheet.add(new StreamResource(
                                new StreamResource.StreamSource() {

                                    @Override
                                    public InputStream getStream() {
                                        return new ByteArrayInputStream(css
View Full Code Here

*/
public class TestStreamResource {

    @Test
    public void testEqualsWithNullFields() {
        StreamResource resource1 = new StreamResource(null, null);
        StreamResource resource2 = new StreamResource(null, null);

        Assert.assertEquals(resource1, resource2);
    }
View Full Code Here

        Assert.assertEquals(resource1, resource2);
    }

    @Test
    public void testNotEqualsWithNullFields() {
        StreamResource resource1 = new StreamResource(null, null);
        StreamResource resource2 = new StreamResource(
                EasyMock.createMock(StreamSource.class), "");

        Assert.assertNotEquals(resource1, resource2);
    }
View Full Code Here

        Assert.assertNotEquals(resource1, resource2);
    }

    @Test
    public void testHashCodeForNullFields() {
        StreamResource resource = new StreamResource(null, null);
        // No NPE
        resource.hashCode();
    }
View Full Code Here

TOP

Related Classes of com.vaadin.server.StreamResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.