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.

JavaScript.java 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright 2000-2018 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.annotations;
  17. import java.lang.annotation.Documented;
  18. import java.lang.annotation.ElementType;
  19. import java.lang.annotation.Repeatable;
  20. import java.lang.annotation.Retention;
  21. import java.lang.annotation.RetentionPolicy;
  22. import java.lang.annotation.Target;
  23. import com.vaadin.server.ClientConnector;
  24. /**
  25. * If this annotation is present on a {@link ClientConnector} class, the
  26. * framework ensures the referenced JavaScript files are loaded before the init
  27. * method for the corresponding client-side connector is invoked.
  28. * <p>
  29. * Absolute URLs including protocol and host are used as is on the client-side.
  30. * Relative URLs are mapped to APP/PUBLISHED/[url] which are by default served
  31. * from the classpath relative to the class where the annotation is defined.
  32. * <p>
  33. * The file is only loaded if it has not already been loaded, determined as
  34. * follows:
  35. * <ul>
  36. * <li>For absolute URLs, the URL is considered loaded if the same URL has
  37. * previously been loaded using {@code @JavaScript} or if a script tag loaded
  38. * from the same URL was present in the DOM when the Vaadin client-side was
  39. * initialized.
  40. * <li>For relative URLs, the URL is considered loaded if another file with the
  41. * same name has already been loaded using {@code @JavaScript}, even if that
  42. * file was loaded from a different folder.
  43. * </ul>
  44. * <p>
  45. * Special Vaadin urls are also supported. The most useful is vaadin:// which
  46. * maps to the location of the automatically published VAADIN folder located on
  47. * your classpath in your resources. Using the VAADIN folder and vaadin:// you
  48. * can publish JavaScript files which use images or other files with relative
  49. * paths. Another example is the theme:// url which maps to the location of your
  50. * current theme.
  51. * <p>
  52. * Example: <code>@JavaScript({"https://host.com/file1.js", "file2.js"})</code>
  53. * on the class com.example.MyConnector would load the file
  54. * https://host.com/file1.js as is and file2.js from /com/example/file2.js on
  55. * the server's classpath using the ClassLoader that was used to load
  56. * com.example.MyConnector.
  57. * <p>
  58. * For adding multiple JavaScript files for a single component, you can use this
  59. * annotation multiple times.
  60. *
  61. * @author Vaadin Ltd
  62. * @since 7.0.0
  63. */
  64. @Retention(RetentionPolicy.RUNTIME)
  65. @Target(ElementType.TYPE)
  66. @Documented
  67. @Repeatable(InternalContainerAnnotationForJS.class)
  68. public @interface JavaScript {
  69. /**
  70. * JavaScript files to load before initializing the client-side connector.
  71. *
  72. * @return an array of JavaScript file URLs
  73. */
  74. public String[] value();
  75. }