home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / exml.lha / exml / examples / ebook / ebook_page.e < prev    next >
Text File  |  1999-04-13  |  6KB  |  302 lines

  1. indexing
  2.     description:"Object that represent a eBook page"
  3.     status:        "See notice at end of class."
  4.     author:        "Andreas Leitner"
  5. class
  6.     EBOOK_PAGE
  7. inherit    
  8.     KL_INPUT_STREAM_ROUTINES
  9.     EBOOK_GLOBALS
  10. creation
  11.     make_from_xml_element
  12.  
  13. feature -- Initialization
  14.  
  15.     make_from_xml_element (e: XML_ELEMENT; a_ebook_root: DS_LINKED_TREE [EBOOK_PAGE]) is
  16.             -- takes a 'page' node and converts it to a object
  17.             -- of the type EBOOK_PAGE
  18.         require
  19.             good_element: e /= Void and then e.name.is_equal ("page")
  20.             a_ebook_root_not_void: a_ebook_root /= Void
  21.         local
  22.             topic_el: XML_ELEMENT
  23.             text_el: XML_ELEMENT
  24.             topic_text: XML_TEXT
  25.             text_text: XML_TEXT
  26.         do
  27.                 -- get the topic node
  28.             topic_el ?= e.item (1)
  29.  
  30.                 -- get the text node
  31.             text_el ?= e.item (2)
  32.  
  33.             if 
  34.                 text_el /= Void and topic_el /= Void
  35.             then
  36.                     -- join all text nodes                
  37.                 topic_el.join_text_nodes
  38.                 text_el.join_text_nodes
  39.  
  40.                     -- now get the text nodes
  41.                 topic_text ?= topic_el.first
  42.                 text_text ?= text_el.first
  43.  
  44.                 check
  45.                     topic_text /= Void and text_text /= Void
  46.                 end
  47.                 
  48.                     -- copy the text
  49.                 topic := clone (topic_text.string)
  50.                 text := clone (text_text.string)
  51.  
  52.                 ebook_root := a_ebook_root
  53.  
  54.                 level := e.level - 1
  55.  
  56.             end
  57.             make_key (e.attributes)
  58.  
  59.         end
  60. feature {NONE}
  61.     key_generator: STRING_KEY_GENERATOR is
  62.         once
  63.             !! Result.make
  64.         end
  65.     make_key (attributes: XML_ATTRIBUTE_TABLE) is
  66.             -- get the key from the "key" attribute
  67.             -- of the "page" tag.
  68.             -- if the value of "key" is "auto"
  69.             -- then use `key_generator' to
  70.             -- automatically generate a key.
  71.         require
  72.             key_exists: attributes.has ("key")
  73.         local
  74.         do
  75.             key := clone (attributes.item ("key")).value
  76.             if
  77.                 key.is_equal ("auto")                
  78.             then
  79.                 key_generator.next_key
  80.                 key := clone (key_generator.last_key)
  81.                 key.append (html_page_extension)
  82.             end
  83.         end
  84.  
  85. feature -- access
  86.     topic: STRING
  87.     text: STRING
  88.     ebook_root: DS_LINKED_TREE [EBOOK_PAGE]
  89.  
  90.     key: STRING
  91.  
  92.     file_name: STRING is
  93.         do
  94.             Result := clone (key)
  95.             Result.prepend (directory_seperator)
  96.             Result.prepend (output_directory)
  97.         ensure
  98.             Result_not_void: Result /= Void
  99.         end
  100.  
  101.     level: INTEGER
  102.         -- page recursion level
  103.  
  104. feature
  105.     ready_for_output: BOOLEAN is
  106.         do
  107.             Result := (topic /= Void) and    (text /= Void)
  108.         end
  109.  
  110. feature -- output generation
  111.     html_page: STRING is
  112.         require
  113.             ready_for_output
  114.         do
  115.             !! Result.make (0)
  116.             Result.append ("<HTML>")
  117.  
  118.             Result.append (html_title)
  119.  
  120.             Result.append (html_pre_body)
  121.  
  122.             Result.append (html_body)
  123.  
  124.             Result.append ("</HTML>")
  125.         end
  126.  
  127.  
  128.     html_pre_body: STRING is
  129.         do
  130.             !! Result.make (0)
  131.             Result.append (html_css_definitions)
  132.         end
  133.  
  134.     html_css_definitions: STRING is
  135.         local
  136.             file: like INPUT_STREAM_TYPE
  137.         do
  138.             file := make_file_open_read (ccs_definitions_file)
  139.             check
  140.                 file_open: is_open_read (file)
  141.             end
  142.  
  143.             !! Result.make (0)
  144.             from
  145.             until
  146.                 end_of_input (file)
  147.             loop
  148.                 Result.append (read_string (file, 1000))
  149.             end
  150.         end
  151.  
  152.  
  153.     html_body: STRING is
  154.         local
  155.             cs: DS_LINKED_TREE_CURSOR [EBOOK_PAGE]
  156.         do
  157.             !! Result.make (0)
  158.             Result.append ("<BODY>")
  159.  
  160.             Result.append (html_pre_body_title)
  161.  
  162.             Result.append (html_body_title)
  163.  
  164.                 -- the menu
  165.             cs := ebook_root.new_cursor
  166.             cs.to_root
  167.             Result.append (html_menu (cs))
  168.  
  169.                 -- the actual text
  170.             Result.append (html_body_text)
  171.  
  172.             Result.append ("</BODY>")
  173.         end
  174.  
  175.     html_pre_body_title: STRING is
  176.         local
  177.             file: like INPUT_STREAM_TYPE
  178.         do
  179.             file := make_file_open_read (pre_body_title_file)
  180.             check
  181.                 file_open: is_open_read (file)
  182.             end
  183.  
  184.             !! Result.make (0)
  185.             from
  186.             until
  187.                 end_of_input (file)
  188.             loop
  189.                 -- Result.append (file.last_string)
  190.                 -- file.read_line
  191.                 Result.append (read_string (file, 1000))
  192.             end
  193.         end
  194.  
  195.  
  196.  
  197.     html_body_text: STRING is
  198.         do
  199.             !! Result.make (0)
  200.             Result.append ("<DIV class=%"BodyText%">")
  201.             Result.append (text)
  202.             Result.append ("</DIV>")
  203.         end
  204.  
  205.     html_body_title: STRING is
  206.         do
  207.             !! Result.make (0)
  208.             Result.append ("<H1 class=%"BodyTitle")
  209.             Result.append (level.out)
  210.             Result.append ("%">")
  211.             Result.append (topic)
  212.             Result.append ("</H1>")
  213.         end
  214.  
  215.  
  216.     html_title: STRING is
  217.         do
  218.             !! Result.make (0)
  219.             Result.append ("<TITLE>")
  220.             Result.append (topic)
  221.             Result.append ("</TITLE>")
  222.         end
  223.  
  224.     
  225.     html_menu (cs: DS_LINKED_TREE_CURSOR [EBOOK_PAGE]): STRING is
  226.         require
  227.             cs_not_void: cs /= Void
  228.         local
  229.  
  230.         do
  231.  
  232.             !! Result.make (0)
  233.  
  234.             if
  235.                 cs.item = Void
  236.             then
  237.                 Result.append ("<DIV class=%"Menu%">")
  238.             end
  239.  
  240.             from
  241.                 cs.child_start
  242.             until
  243.                  cs.child_off
  244.             loop
  245.                     -- generate this page
  246.                 if
  247.                     cs.child_item = Current
  248.                 then
  249.                     Result.append ("<A class=%"SelectedMenuLink")    
  250.                 else
  251.                     Result.append ("<A class=%"MenuLink")    
  252.                 end
  253.  
  254.                 Result.append (cs.child_item.level.out)
  255.  
  256.                 Result.append ("%" HREF=%"")
  257.                 Result.append (cs.child_item.key)
  258.                 Result.append ("%">")
  259.                 Result.append (cs.child_item.topic)
  260.                 Result.append ("</A><br>")
  261.  
  262.                 cs.down
  263.                     -- process recursive pages if page is current.
  264.                     -- only show sub menus when the current page
  265.                     -- is listed in it somewhere
  266.                 if
  267.                     cs.has (Current)
  268.                 then
  269.                     Result.append (html_menu (cs))
  270.                 end
  271.                 cs.up
  272.  
  273.                 cs.child_forth
  274.             end
  275.  
  276.             if
  277.                 cs.item = Void
  278.             then
  279.                 Result.append ("</DIV>")
  280.             end
  281.  
  282.  
  283.         end
  284.  
  285.  
  286.         
  287.  
  288. end -- class EBOOK_PAGE
  289. --|-------------------------------------------------------------------------
  290. --| eXML, Eiffel XML Parser Toolkit
  291. --| Copyright (C) 1999  Andreas Leitner
  292. --| See the file forum.txt included in this package for licensing info.
  293. --|
  294. --| Comments, Questions, Additions to this library? please contact:
  295. --|
  296. --| Andreas Leitner
  297. --| Arndtgasse 1/3/5
  298. --| 8010 Graz
  299. --| Austria
  300. --| email: andreas.leitner@teleweb.at
  301. --| web: http://exml.dhs.org
  302. --|-------------------------------------------------------------------------