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