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.

ResourceReference.java 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package com.vaadin.terminal.gwt.client.communication;
  2. import com.vaadin.Application;
  3. import com.vaadin.terminal.ApplicationResource;
  4. import com.vaadin.terminal.ExternalResource;
  5. import com.vaadin.terminal.Resource;
  6. import com.vaadin.terminal.ThemeResource;
  7. public class ResourceReference extends URLReference {
  8. private Resource resource;
  9. public ResourceReference(Resource resource) {
  10. this.resource = resource;
  11. }
  12. public Resource getResource() {
  13. return resource;
  14. }
  15. @Override
  16. public String getURL() {
  17. if (resource instanceof ExternalResource) {
  18. return ((ExternalResource) resource).getURL();
  19. } else if (resource instanceof ApplicationResource) {
  20. final ApplicationResource r = (ApplicationResource) resource;
  21. final Application a = r.getApplication();
  22. if (a == null) {
  23. throw new RuntimeException(
  24. "An ApplicationResource ("
  25. + r.getClass().getName()
  26. + " must be attached to an application when it is sent to the client.");
  27. }
  28. final String uri = a.getRelativeLocation(r);
  29. return uri;
  30. } else if (resource instanceof ThemeResource) {
  31. final String uri = "theme://"
  32. + ((ThemeResource) resource).getResourceId();
  33. return uri;
  34. } else {
  35. throw new RuntimeException(getClass().getSimpleName()
  36. + " does not support resources of type: "
  37. + resource.getClass().getName());
  38. }
  39. }
  40. }