/library/server/httpd/interface/response/html/html_page.e

http://github.com/jocelyn/EiffelWebReloaded · Specman e · 158 lines · 118 code · 32 blank · 8 comment · 4 complexity · ee9de277d8c61f2546ac359d6a2f8e9f MD5 · raw file

  1. note
  2. description: "Summary description for {HTML_PAGE}."
  3. date: "$Date$"
  4. revision: "$Revision$"
  5. class
  6. HTML_PAGE
  7. inherit
  8. HTML_UTILITIES
  9. HTTPD_RESPONSE
  10. redefine
  11. initialize,
  12. recycle
  13. end
  14. create
  15. make
  16. feature {NONE} -- Initialization
  17. make (a_title: like title)
  18. do
  19. create {ARRAYED_LIST [like html_attributes.item]} html_attributes.make (0)
  20. create head.make (a_title)
  21. create {ARRAYED_LIST [like body_attributes.item]} body_attributes.make (0)
  22. create body.make_empty
  23. initialize
  24. end
  25. initialize
  26. -- Initialize
  27. do
  28. Precursor
  29. end
  30. feature -- Recycle
  31. recycle
  32. do
  33. html_attributes.wipe_out
  34. headers.recycle
  35. head.recycle
  36. body_attributes.wipe_out
  37. body.wipe_out
  38. internal_string := Void
  39. end
  40. feature -- Access
  41. html_attributes: LIST [TUPLE [name: STRING; value: STRING]]
  42. head: HTML_PAGE_HEAD
  43. body_attributes: LIST [TUPLE [name: STRING; value: STRING]]
  44. body: STRING
  45. feature -- Query
  46. title: detachable STRING
  47. do
  48. Result := head.title
  49. end
  50. add_html_ttribute (a: like html_attributes.item)
  51. do
  52. html_attributes.force (a)
  53. end
  54. add_body_attribute (a: like body_attributes.item)
  55. do
  56. body_attributes.force (a)
  57. end
  58. set_body (s: like body)
  59. -- Set `body' to `s'
  60. do
  61. body := s
  62. end
  63. feature -- Element change
  64. set_title (t: like title)
  65. do
  66. head.title := t
  67. end
  68. feature -- Output
  69. compute
  70. -- Compute the string output
  71. local
  72. s, h, t: STRING
  73. do
  74. --| HTML beginning
  75. create s.make (128)
  76. s.append_string ("<html")
  77. s.append_string (attributes_to_string (html_attributes))
  78. s.append_string (">%N")
  79. --| Head
  80. head.compute --| Be sure to have a fresh string
  81. t := head.string
  82. if not t.is_empty then
  83. s.append_string (t)
  84. s.append_character ('%N')
  85. end
  86. --| Body
  87. s.append_string ("<body")
  88. s.append_string (attributes_to_string (body_attributes))
  89. s.append_string (">%N")
  90. s.append_string (body)
  91. s.append_string ("</body>")
  92. --| End
  93. s.append_string ("</html>")
  94. --| Http headers
  95. headers.put_content_length (s.count)
  96. create h.make_from_string (headers.string)
  97. internal_string := h + s
  98. end
  99. string: STRING
  100. local
  101. o: like internal_string
  102. do
  103. o := internal_string
  104. if o = Void then
  105. compute
  106. o := internal_string
  107. if o = Void then
  108. check output_computed: False end
  109. create o.make_empty
  110. end
  111. end
  112. Result := o
  113. end
  114. feature {NONE} -- Implementation: output
  115. internal_string: detachable like string
  116. ;note
  117. copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
  118. license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
  119. source: "[
  120. Eiffel Software
  121. 5949 Hollister Ave., Goleta, CA 93117 USA
  122. Telephone 805-685-1006, Fax 805-685-6869
  123. Website http://www.eiffel.com
  124. Customer support http://support.eiffel.com
  125. ]"
  126. end