PageRenderTime 23ms CodeModel.GetById 17ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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