indexing description:"Object that represent a eBook page" status: "See notice at end of class." author: "Andreas Leitner" class EBOOK_PAGE inherit KL_INPUT_STREAM_ROUTINES EBOOK_GLOBALS creation make_from_xml_element feature -- Initialization make_from_xml_element (e: XML_ELEMENT; a_ebook_root: DS_LINKED_TREE [EBOOK_PAGE]) is -- takes a 'page' node and converts it to a object -- of the type EBOOK_PAGE require good_element: e /= Void and then e.name.is_equal ("page") a_ebook_root_not_void: a_ebook_root /= Void local topic_el: XML_ELEMENT text_el: XML_ELEMENT topic_text: XML_TEXT text_text: XML_TEXT do -- get the topic node topic_el ?= e.item (1) -- get the text node text_el ?= e.item (2) if text_el /= Void and topic_el /= Void then -- join all text nodes topic_el.join_text_nodes text_el.join_text_nodes -- now get the text nodes topic_text ?= topic_el.first text_text ?= text_el.first check topic_text /= Void and text_text /= Void end -- copy the text topic := clone (topic_text.string) text := clone (text_text.string) ebook_root := a_ebook_root level := e.level - 1 end make_key (e.attributes) end feature {NONE} key_generator: STRING_KEY_GENERATOR is once !! Result.make end make_key (attributes: XML_ATTRIBUTE_TABLE) is -- get the key from the "key" attribute -- of the "page" tag. -- if the value of "key" is "auto" -- then use `key_generator' to -- automatically generate a key. require key_exists: attributes.has ("key") local do key := clone (attributes.item ("key")).value if key.is_equal ("auto") then key_generator.next_key key := clone (key_generator.last_key) key.append (html_page_extension) end end feature -- access topic: STRING text: STRING ebook_root: DS_LINKED_TREE [EBOOK_PAGE] key: STRING file_name: STRING is do Result := clone (key) Result.prepend (directory_seperator) Result.prepend (output_directory) ensure Result_not_void: Result /= Void end level: INTEGER -- page recursion level feature ready_for_output: BOOLEAN is do Result := (topic /= Void) and (text /= Void) end feature -- output generation html_page: STRING is require ready_for_output do !! Result.make (0) Result.append ("") Result.append (html_title) Result.append (html_pre_body) Result.append (html_body) Result.append ("") end html_pre_body: STRING is do !! Result.make (0) Result.append (html_css_definitions) end html_css_definitions: STRING is local file: like INPUT_STREAM_TYPE s: STRING do file := make_file_open_read (ccs_definitions_file) if not is_open_read (file) then s := clone ("Unable to open file ") s.append_string (ccs_definitions_file) s.append_string (" in read mode") report_error_and_exit (s) end !! Result.make (0) from until end_of_input (file) loop Result.append (read_string (file, 1000)) end end html_body: STRING is local cs: DS_LINKED_TREE_CURSOR [EBOOK_PAGE] do !! Result.make (0) Result.append ("
") Result.append (html_pre_body_title) Result.append (html_body_title) -- the menu cs := ebook_root.new_cursor cs.to_root Result.append (html_menu (cs)) -- the actual text Result.append (html_body_text) Result.append ("") end html_pre_body_title: STRING is local file: like INPUT_STREAM_TYPE do file := make_file_open_read (pre_body_title_file) check file_open: is_open_read (file) end !! Result.make (0) from until end_of_input (file) loop -- Result.append (file.last_string) -- file.read_line Result.append (read_string (file, 1000)) end end html_body_text: STRING is do !! Result.make (0) Result.append ("