EntityResolver.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // EntityResolver.h
  3. //
  4. // Library: XML
  5. // Package: SAX
  6. // Module: SAX
  7. //
  8. // SAX EntityResolver Interface.
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef SAX_EntityResolver_INCLUDED
  16. #define SAX_EntityResolver_INCLUDED
  17. #include "Poco/XML/XML.h"
  18. #include "Poco/XML/XMLString.h"
  19. namespace Poco {
  20. namespace XML {
  21. class InputSource;
  22. class XML_API EntityResolver
  23. /// If a SAX application needs to implement customized handling for external entities,
  24. /// it must implement this interface and register an instance with the SAX driver using
  25. /// the setEntityResolver method.
  26. ///
  27. /// The XML reader will then allow the application to intercept any external entities
  28. /// (including the external DTD subset and external parameter entities, if any) before
  29. /// including them.
  30. ///
  31. /// Many SAX applications will not need to implement this interface, but it will be
  32. /// especially useful for applications that build XML documents from databases or other
  33. /// specialised input sources, or for applications that use URI types other than URLs.
  34. ///
  35. /// The application can also use this interface to redirect system identifiers to local
  36. /// URIs or to look up replacements in a catalog (possibly by using the public identifier).
  37. {
  38. public:
  39. virtual InputSource* resolveEntity(const XMLString* publicId, const XMLString& systemId) = 0;
  40. /// Allow the application to resolve external entities.
  41. ///
  42. /// The parser will call this method before opening any external entity except the
  43. /// top-level document entity. Such entities include the external DTD subset and
  44. /// external parameter entities referenced within the DTD (in either case, only
  45. /// if the parser reads external parameter entities), and external general entities
  46. /// referenced within the document element (if the parser reads external general entities).
  47. /// The application may request that the parser locate the entity itself, that it use an
  48. /// alternative URI, or that it use data provided by the application (as a character or
  49. /// byte input stream).
  50. ///
  51. /// Application writers can use this method to redirect external system identifiers to
  52. /// secure and/or local URIs, to look up public identifiers in a catalogue, or to read an
  53. /// entity from a database or other input source (including, for example, a dialog box).
  54. /// Neither XML nor SAX specifies a preferred policy for using public or system IDs to resolve
  55. /// resources. However, SAX specifies how to interpret any InputSource returned by this method,
  56. /// and that if none is returned, then the system ID will be dereferenced as a URL.
  57. ///
  58. /// If the system identifier is a URL, the SAX parser must resolve it fully before reporting it to
  59. /// the application.
  60. ///
  61. /// Note that publicId maybe null, therefore we pass a pointer rather than a reference.
  62. virtual void releaseInputSource(InputSource* pSource) = 0;
  63. /// This is a non-standard extension to SAX!
  64. /// Called by the parser when the input source returned by ResolveEntity is
  65. /// no longer needed. Should free any resources used by the input source.
  66. protected:
  67. virtual ~EntityResolver();
  68. };
  69. } } // namespace Poco::XML
  70. #endif // SAX_EntityResolver_INCLUDED