Any way to replace ExternalResource Vaadin 8 to Vaadin 14?

Hi,

is there any replace for ExternalResource Vaadin 8 to Vaadin 14?

Thanks
Giovanni

Hi,

what do you want to do with the resource? Some typical use cases: If you have a hyperlink (Anchor in V14), you can use anchor.setHref() to set the URL. If you have an Image, you can use image.setSrc().

-Olli

Olli Tietäväinen:
Hi,

what do you want to do with the resource? Some typical use cases: If you have a hyperlink (Anchor in V14), you can use anchor.setHref() to set the URL. If you have an Image, you can use image.setSrc().

-Olli

Hi Olli, Thanks for your answer,

What i need to do is to create a resource to pass to a pdf Viewer like this

Embedded document = new Embedded();
document.setType(Embedded.TYPE_BROWSER);
document.setSource(new ExternalResource(urlFile));

PdfBrowserViewer viewer = new PdfBrowserViewer(fileResource);

Thanks

If the PdfBrowserViewer is a Vaadin 8 add-on, you might need to create a Vaadin 14 replacement for that one first.

https://vaadin.com/directory/component/pdf-browser looks like something that could be useful; there’s a syntax example on the main page already too

Olli Tietäväinen:
If the PdfBrowserViewer is a Vaadin 8 add-on, you might need to create a Vaadin 14 replacement for that one first.

Hi,

it is a vaadin 14 component.

https://vaadin.com/directory/component/pdf-browser/overview

The resource is from another server, i have the url like http://anothersite/myfile.pdf

Thanks for your help.

The Vaadin 14 verion of PdfBrowserViewer’s constructor seems to take a StreamResource, not an ExternalResource, see here: https://github.com/alejandro-du/pdf-browser/blob/master/src/main/java/org/vaadin/alejandro/PdfBrowserViewer.java#L20

Maybe you’ll need to modify the code or extend the class so that you can just pass the URL.

Olli Tietäväinen:
The Vaadin 14 verion of PdfBrowserViewer’s constructor seems to take a StreamResource, not an ExternalResource, see here: https://github.com/alejandro-du/pdf-browser/blob/master/src/main/java/org/vaadin/alejandro/PdfBrowserViewer.java#L20

Maybe you’ll need to modify the code or extend the class so that you can just pass the URL.

Yes,

what i need is to get an external file and convert in a streamResource, vaadin 14 does not have ExternalResource class, may be ther is another class to do the same thing.

Thanks

Giovanni Adobati:

Olli Tietäväinen:
The Vaadin 14 verion of PdfBrowserViewer’s constructor seems to take a StreamResource, not an ExternalResource, see here: https://github.com/alejandro-du/pdf-browser/blob/master/src/main/java/org/vaadin/alejandro/PdfBrowserViewer.java#L20

Maybe you’ll need to modify the code or extend the class so that you can just pass the URL.

Yes,

what i need is to get an external file and convert in a streamResource, vaadin 14 does not have ExternalResource class, may be ther is another class to do the same thing.

Thanks

Hi,

i did something like this, just testing it.

StreamResource resource = new StreamResource(s3client.getFileName(s3Key), new InputStreamFactory() {

	@Override
	public InputStream createInputStream() {

		URL urlObject;
		try {

			urlObject = new URL(urlFile);
			URLConnection urlConnection = urlObject.openConnection();
			InputStream inputStream = urlConnection.getInputStream();

			return inputStream;

		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}
});

PdfBrowserViewer viewer = new PdfBrowserViewer(resource);

That looks like a good way to go. Another option could be creating a new class that extends PdfBrowserViewer and calling setFile with a manually created URI object without calling the super constructor; it doesn’t look like the StreamResource is used for anything except the URI creation.