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.

BootstrapPageResponse.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.util.Map;
  18. import org.jsoup.nodes.Document;
  19. import com.vaadin.ui.UI;
  20. /**
  21. * A representation of a bootstrap page being generated. The bootstrap page
  22. * contains of the full DOM of the HTML document as well as the HTTP headers
  23. * that will be included in the corresponding HTTP response.
  24. *
  25. * @author Vaadin Ltd
  26. * @since 7.0.0
  27. */
  28. public class BootstrapPageResponse extends BootstrapResponse {
  29. private final Map<String, Object> headers;
  30. private final Document document;
  31. /**
  32. * Crate a new bootstrap page response.
  33. *
  34. * @see BootstrapResponse#BootstrapResponse(BootstrapHandler, VaadinRequest,
  35. * VaadinSession, Class, UIProvider)
  36. *
  37. * @param handler
  38. * the bootstrap handler that is firing the event
  39. * @param request
  40. * the Vaadin request for which the bootstrap page should be
  41. * generated
  42. * @param session
  43. * the service session for which the bootstrap page should be
  44. * generated
  45. * @param uiClass
  46. * the class of the UI that will be displayed on the page
  47. * @param document
  48. * the DOM document making up the HTML page
  49. * @param headers
  50. * a map into which header data can be added
  51. * @param uiProvider
  52. * the UI provider for the bootstrap
  53. */
  54. public BootstrapPageResponse(BootstrapHandler handler,
  55. VaadinRequest request, VaadinSession session,
  56. Class<? extends UI> uiClass, Document document,
  57. Map<String, Object> headers, UIProvider uiProvider) {
  58. super(handler, request, session, uiClass, uiProvider);
  59. this.headers = headers;
  60. this.document = document;
  61. }
  62. /**
  63. * Sets a header value that will be added to the HTTP response. If the
  64. * header had already been set, the new value overwrites the previous one.
  65. *
  66. * @see VaadinResponse#setHeader(String, String)
  67. *
  68. * @param name
  69. * the name of the header
  70. * @param value
  71. * the header value
  72. */
  73. public void setHeader(String name, String value) {
  74. headers.put(name, value);
  75. }
  76. /**
  77. * Properly formats a timestamp as a date in a header that will be included
  78. * in the HTTP response. If the header had already been set, the new value
  79. * overwrites the previous one.
  80. *
  81. * @see #setHeader(String, String)
  82. * @see VaadinResponse#setDateHeader(String, long)
  83. *
  84. * @param name
  85. * the name of the header
  86. * @param timestamp
  87. * the number of milliseconds since epoch
  88. */
  89. public void setDateHeader(String name, long timestamp) {
  90. headers.put(name, Long.valueOf(timestamp));
  91. }
  92. /**
  93. * Gets the document node representing the root of the DOM hierarchy that
  94. * will be used to generate the HTML page. Changes to the document will be
  95. * reflected in the HTML.
  96. *
  97. * @return the document node
  98. */
  99. public Document getDocument() {
  100. return document;
  101. }
  102. }