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.

ThemeResource.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.server;
  17. import com.vaadin.util.FileTypeResolver;
  18. /**
  19. * <code>ThemeResource</code> is a named theme dependant resource provided and
  20. * managed by a theme. The actual resource contents are dynamically resolved to
  21. * comply with the used theme by the terminal adapter. This is commonly used to
  22. * provide static images, flash, java-applets, etc for the terminals.
  23. *
  24. * @author Vaadin Ltd.
  25. * @since 3.0
  26. */
  27. @SuppressWarnings("serial")
  28. public class ThemeResource implements Resource {
  29. /**
  30. * Id of the terminal managed resource.
  31. */
  32. private String resourceID = null;
  33. /**
  34. * Creates a resource.
  35. *
  36. * @param resourceId
  37. * the Id of the resource.
  38. */
  39. public ThemeResource(String resourceId) {
  40. if (resourceId == null) {
  41. throw new NullPointerException("Resource ID must not be null");
  42. }
  43. if (resourceId.isEmpty()) {
  44. throw new IllegalArgumentException("Resource ID can not be empty");
  45. }
  46. if (resourceId.charAt(0) == '/') {
  47. throw new IllegalArgumentException(
  48. "Resource ID must be relative (can not begin with /)");
  49. }
  50. resourceID = resourceId;
  51. }
  52. /**
  53. * Tests if the given object equals this Resource.
  54. *
  55. * @param obj
  56. * the object to be tested for equality.
  57. * @return <code>true</code> if the given object equals this Icon,
  58. * <code>false</code> if not.
  59. * @see java.lang.Object#equals(Object)
  60. */
  61. @Override
  62. public boolean equals(Object obj) {
  63. return obj instanceof ThemeResource
  64. && resourceID.equals(((ThemeResource) obj).resourceID);
  65. }
  66. /**
  67. * @see java.lang.Object#hashCode()
  68. */
  69. @Override
  70. public int hashCode() {
  71. return resourceID.hashCode();
  72. }
  73. /**
  74. * @see java.lang.Object#toString()
  75. */
  76. @Override
  77. public String toString() {
  78. return resourceID;
  79. }
  80. /**
  81. * Gets the resource id.
  82. *
  83. * @return the resource id.
  84. */
  85. public String getResourceId() {
  86. return resourceID;
  87. }
  88. /**
  89. * @see com.vaadin.server.Resource#getMIMEType()
  90. */
  91. @Override
  92. public String getMIMEType() {
  93. return FileTypeResolver.getMIMEType(getResourceId());
  94. }
  95. }