/src/lib/xml/xml_dtd_public_repository.e

http://github.com/tybor/Liberty · Specman e · 108 lines · 64 code · 10 blank · 34 comment · 2 complexity · 30d494ffce234e97e35ae808cb552eb2 MD5 · raw file

  1. -- See the Copyright notice at the end of this file.
  2. --
  3. expanded class XML_DTD_PUBLIC_REPOSITORY
  4. --
  5. -- This class allows you to register public DTD files as local files (useful when the network is not
  6. -- available, or for performance reasons, or for any other reason).
  7. --
  8. insert
  9. URL_VALIDITY
  10. feature {ANY}
  11. register (public_id: UNICODE_STRING; a_url: STRING)
  12. -- Register the public DTD `public_id' as having a local counterpart file in the given `local_path'.
  13. require
  14. valid_public_id: not public_id.is_empty
  15. valid_url: valid_url(a_url)
  16. not_registered: not is_registered(public_id)
  17. local
  18. url: URL
  19. do
  20. create url.absolute(a_url)
  21. -- We twin the `public_id' string to be sure the client cannot modify the registered version (the
  22. -- hashed dictionary would not like that)
  23. dtd.add(url, public_id.twin)
  24. ensure
  25. registered: is_registered(public_id)
  26. end
  27. is_registered (public_id: UNICODE_STRING): BOOLEAN
  28. -- Does the given `public_id' have a registered URL?
  29. require
  30. valid_public_id: not public_id.is_empty
  31. do
  32. Result := dtd.has(public_id)
  33. end
  34. feature {XML_DTD_PARSER}
  35. public_dtd (public_id: UNICODE_STRING; a_url: URL): URL
  36. -- Opens the given `public_id' either by network connection to the `url' or, if the `public_id'
  37. -- `is_registered', by reading the registered URL.
  38. require
  39. not public_id.is_empty
  40. not is_registered(public_id) implies a_url /= Void
  41. do
  42. last_error_memory.set_item(Void)
  43. if is_registered(public_id) then
  44. Result := dtd.at(public_id)
  45. else
  46. Result := a_url
  47. end
  48. if Result /= Void then
  49. Result.set_error_handler(agent_error)
  50. end
  51. ensure
  52. Result = Void implies last_error /= Void
  53. not is_registered(public_id) implies Result = a_url
  54. end
  55. last_error: STRING
  56. -- Meaningful only if the last call to `public_dtd' returned Void
  57. do
  58. Result := last_error_memory.item
  59. end
  60. feature {}
  61. last_error_memory: REFERENCE[STRING]
  62. once
  63. create Result
  64. end
  65. dtd: HASHED_DICTIONARY[URL, UNICODE_STRING]
  66. -- The registered URLs
  67. once
  68. create Result.make
  69. end
  70. agent_error: PROCEDURE[TUPLE[STRING]]
  71. once
  72. Result := agent set_error(?)
  73. end
  74. set_error (a_error: STRING)
  75. do
  76. last_error_memory.set_item(a_error)
  77. end
  78. end -- class XML_DTD_PUBLIC_REPOSITORY
  79. --
  80. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  81. --
  82. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  83. -- of this software and associated documentation files (the "Software"), to deal
  84. -- in the Software without restriction, including without limitation the rights
  85. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  86. -- copies of the Software, and to permit persons to whom the Software is
  87. -- furnished to do so, subject to the following conditions:
  88. --
  89. -- The above copyright notice and this permission notice shall be included in
  90. -- all copies or substantial portions of the Software.
  91. --
  92. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  93. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  94. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  95. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  96. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  97. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  98. -- THE SOFTWARE.