PageRenderTime 21ms CodeModel.GetById 16ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/net/example_http_client.e

http://github.com/tybor/Liberty
Specman e | 120 lines | 99 code | 14 blank | 7 comment | 4 complexity | 3d65029d7f2911f9b6351bda6711ca75 MD5 | raw file
  1class EXAMPLE_HTTP_CLIENT
  2   --
  3   -- Some ideas and first draft of this class kindly provided by Serge [mailto:se@sir.nensi.net]
  4   --
  5
  6inherit
  7   XML_NODE_VISITOR
  8      undefine
  9         default_create
 10      end
 11
 12insert
 13   PROTOCOLS
 14
 15create {ANY}
 16   make
 17
 18feature {}
 19   proxy: HTTP_PROXY
 20
 21   make
 22      do
 23         test_socket(create {URL}.absolute("http://noc.nensi.net/se/test.xml"))
 24         --| --8<--| TODO |--8<--
 25         --| test_socket(create {URL}.absolute("http://et.liberty-eiffel.org/Liberty/tutorial/xml/sax/example.xml"))
 26         --| -->8------------>8--
 27      end
 28
 29   test_socket (url: URL)
 30      local
 31         input: INPUT_STREAM; tree: XML_TREE; version: UNICODE_STRING
 32      do
 33         url.set_error_handler(agent (err: STRING) do std_error.put_line("**** Error: #(1)" # err) end (?))
 34         url.connect
 35         if url.is_connected then
 36            input := url.input
 37            create tree.with_error_handler(input.url, agent error(?, ?))
 38            version := tree.attribute_at(once U"version")
 39            if version /= Void then
 40               io.put_string(once "XML version: ")
 41               io.put_string(version.as_utf8)
 42               io.put_new_line
 43            end
 44
 45            check
 46               indent = 0
 47            end
 48            tree.root.accept(Current)
 49            url.disconnect
 50         else
 51            std_error.put_line("URL not connected!")
 52         end
 53      end
 54
 55   error (line, column: INTEGER)
 56      do
 57         std_error.put_string("Error at ")
 58         std_error.put_integer(line)
 59         std_error.put_string(", ")
 60         std_error.put_integer(column)
 61         std_error.put_string("!%N")
 62         die_with_code(1)
 63      end
 64
 65feature {XML_COMPOSITE_NODE}
 66   visit_composite_node (node: XML_COMPOSITE_NODE)
 67      local
 68         i: INTEGER
 69      do
 70         from
 71            i := 1
 72         until
 73            i > indent
 74         loop
 75            io.put_string(once "  ")
 76            i := i + 1
 77         end
 78         io.put_string(node.name.as_utf8)
 79         if node.attributes_count > 0 then
 80            io.put_character('(')
 81            from
 82               i := 1
 83            until
 84               i > node.attributes_count
 85            loop
 86               if i > 1 then
 87                  io.put_string(once ", ")
 88               end
 89               -- if
 90               io.put_string(node.attribute_name(i).as_utf8)
 91               io.put_character('=')
 92               io.put_string(node.attribute_value(i).as_utf8)
 93               i := i + 1
 94            end
 95
 96            io.put_character(')')
 97         end
 98
 99         io.put_new_line
100         indent := indent + 1
101         from
102            i := 1
103         until
104            i > node.children_count
105         loop
106            node.child(i).accept(Current)
107            i := i + 1
108         end
109         indent := indent - 1
110      end
111
112feature {XML_DATA_NODE}
113   visit_data_node (node: XML_DATA_NODE)
114      do
115      end
116
117feature {}
118   indent: INTEGER
119
120end -- class EXAMPLE_HTTP_CLIENT