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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright 2011 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.Application;
  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,
  35. * WrappedRequest, Application, Integer)
  36. *
  37. * @param handler
  38. * the bootstrap handler that is firing the event
  39. * @param request
  40. * the wrapped request for which the bootstrap page should be
  41. * generated
  42. * @param application
  43. * the application for which the bootstrap page should be
  44. * generated
  45. * @param uiId
  46. * the generated id of the UI that will be displayed on the
  47. * page
  48. * @param document
  49. * the DOM document making up the HTML page
  50. * @param headers
  51. * a map into which header data can be added
  52. */
  53. public BootstrapPageResponse(BootstrapHandler handler,
  54. WrappedRequest request, Application application, Integer uiId,
  55. Document document, Map<String, Object> headers) {
  56. super(handler, request, application, uiId);
  57. this.headers = headers;
  58. this.document = document;
  59. }
  60. /**
  61. * Sets a header value that will be added to the HTTP response. If the
  62. * header had already been set, the new value overwrites the previous one.
  63. *
  64. * @see WrappedResponse#setHeader(String, String)
  65. *
  66. * @param name
  67. * the name of the header
  68. * @param value
  69. * the header value
  70. */
  71. public void setHeader(String name, String value) {
  72. headers.put(name, value);
  73. }
  74. /**
  75. * Properly formats a timestamp as a date in a header that will be included
  76. * in the HTTP response. If the header had already been set, the new value
  77. * overwrites the previous one.
  78. *
  79. * @see #setHeader(String, String)
  80. * @see WrappedResponse#setDateHeader(String, long)
  81. *
  82. * @param name
  83. * the name of the header
  84. * @param timestamp
  85. * the number of milliseconds since epoch
  86. */
  87. public void setDateHeader(String name, long timestamp) {
  88. headers.put(name, Long.valueOf(timestamp));
  89. }
  90. /**
  91. * Gets the document node representing the root of the DOM hierarchy that
  92. * will be used to generate the HTML page. Changes to the document will be
  93. * reflected in the HTML.
  94. *
  95. * @return the document node
  96. */
  97. public Document getDocument() {
  98. return document;
  99. }
  100. }