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.

DependencyFilter.java 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.server;
  17. import java.io.Serializable;
  18. import java.util.List;
  19. import com.vaadin.annotations.HtmlImport;
  20. import com.vaadin.annotations.JavaScript;
  21. import com.vaadin.annotations.StyleSheet;
  22. import com.vaadin.ui.Dependency;
  23. /**
  24. * Filter for dependencies loaded using {@link StyleSheet @StyleSheet},
  25. * {@link JavaScript @JavaScript} and {@link HtmlImport @HtmlImport}.
  26. *
  27. * @see ServiceInitEvent#addDependencyFilter(DependencyFilter)
  28. *
  29. * @since 8.1
  30. */
  31. @FunctionalInterface
  32. public interface DependencyFilter extends Serializable {
  33. /**
  34. * Filters the list of dependencies and returns a (possibly) updated
  35. * version.
  36. * <p>
  37. * Called whenever dependencies are about to be sent to the client side for
  38. * loading.
  39. *
  40. * @param dependencies
  41. * the collected dependencies, possibly already modified by other
  42. * filters
  43. * @param filterContext
  44. * context information, e.g about the target UI
  45. * @return a list of dependencies to load
  46. */
  47. public List<Dependency> filter(List<Dependency> dependencies,
  48. FilterContext filterContext);
  49. /**
  50. * Provides context information for the dependency filter operation.
  51. *
  52. * @since 8.1
  53. */
  54. public static class FilterContext implements Serializable {
  55. private VaadinSession session;
  56. /**
  57. * Creates a new context for the given session.
  58. *
  59. * @param session
  60. * the session which is loading dependencies
  61. */
  62. public FilterContext(VaadinSession session) {
  63. this.session = session;
  64. }
  65. /**
  66. * Gets the related Vaadin session.
  67. *
  68. * @return the Vaadin session
  69. */
  70. public VaadinSession getSession() {
  71. return session;
  72. }
  73. /**
  74. * Gets the related Vaadin service.
  75. *
  76. * @return the Vaadin service
  77. */
  78. public VaadinService getService() {
  79. return session.getService();
  80. }
  81. }
  82. }