/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

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