You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ExternalResource.java 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.itmill.toolkit.terminal;
  5. import java.net.URL;
  6. import com.itmill.toolkit.service.FileTypeResolver;
  7. /**
  8. * <code>ExternalResource</code> implements source for resources fetched from
  9. * location specified by URL:s. The resources are fetched directly by the client
  10. * terminal and are not fetched trough the terminal adapter.
  11. *
  12. * @author IT Mill Ltd.
  13. * @version
  14. * @VERSION@
  15. * @since 3.0
  16. */
  17. public class ExternalResource implements Resource {
  18. /**
  19. * Url of the download.
  20. */
  21. private String sourceURL = null;
  22. /**
  23. * Creates a new download component for downloading directly from given URL.
  24. *
  25. * @param sourceURL
  26. * the source URL.
  27. */
  28. public ExternalResource(URL sourceURL) {
  29. if (sourceURL == null) {
  30. throw new RuntimeException("Source must be non-null");
  31. }
  32. this.sourceURL = sourceURL.toString();
  33. }
  34. /**
  35. * Creates a new download component for downloading directly from given URL.
  36. *
  37. * @param sourceURL
  38. * the source URL.
  39. */
  40. public ExternalResource(String sourceURL) {
  41. if (sourceURL == null) {
  42. throw new RuntimeException("Source must be non-null");
  43. }
  44. this.sourceURL = sourceURL.toString();
  45. }
  46. /**
  47. * Gets the URL of the external resource.
  48. *
  49. * @return the URL of the external resource.
  50. */
  51. public String getURL() {
  52. return sourceURL;
  53. }
  54. /**
  55. * Gets the MIME type of the resource.
  56. *
  57. * @see com.itmill.toolkit.terminal.Resource#getMIMEType()
  58. */
  59. public String getMIMEType() {
  60. return FileTypeResolver.getMIMEType(getURL().toString());
  61. }
  62. }