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 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.terminal.gwt.server;
  17. import java.util.Map;
  18. import org.jsoup.nodes.Document;
  19. import com.vaadin.Application;
  20. import com.vaadin.terminal.WrappedRequest;
  21. import com.vaadin.terminal.WrappedResponse;
  22. /**
  23. * A representation of a bootstrap page being generated. The bootstrap page
  24. * contains of the full DOM of the HTML document as well as the HTTP headers
  25. * that will be included in the corresponding HTTP response.
  26. *
  27. * @author Vaadin Ltd
  28. * @since 7.0.0
  29. */
  30. public class BootstrapPageResponse extends BootstrapResponse {
  31. private final Map<String, Object> headers;
  32. private final Document document;
  33. /**
  34. * Crate a new bootstrap page response.
  35. *
  36. * @see BootstrapResponse#BootstrapResponse(BootstrapHandler,
  37. * WrappedRequest, Application, Integer)
  38. *
  39. * @param handler
  40. * the bootstrap handler that is firing the event
  41. * @param request
  42. * the wrapped request for which the bootstrap page should be
  43. * generated
  44. * @param application
  45. * the application for which the bootstrap page should be
  46. * generated
  47. * @param uiId
  48. * the generated id of the UI that will be displayed on the
  49. * page
  50. * @param document
  51. * the DOM document making up the HTML page
  52. * @param headers
  53. * a map into which header data can be added
  54. */
  55. public BootstrapPageResponse(BootstrapHandler handler,
  56. WrappedRequest request, Application application, Integer uiId,
  57. Document document, Map<String, Object> headers) {
  58. super(handler, request, application, uiId);
  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 WrappedResponse#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 WrappedResponse#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. }