[80] | 1 | // |
---|
| 2 | // EntityResolver.h |
---|
| 3 | // |
---|
| 4 | // $Id: //poco/1.3/XML/include/Poco/SAX/EntityResolver.h#1 $ |
---|
| 5 | // |
---|
| 6 | // Library: XML |
---|
| 7 | // Package: SAX |
---|
| 8 | // Module: SAX |
---|
| 9 | // |
---|
| 10 | // SAX EntityResolver Interface. |
---|
| 11 | // |
---|
| 12 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
---|
| 13 | // and Contributors. |
---|
| 14 | // |
---|
| 15 | // Permission is hereby granted, free of charge, to any person or organization |
---|
| 16 | // obtaining a copy of the software and accompanying documentation covered by |
---|
| 17 | // this license (the "Software") to use, reproduce, display, distribute, |
---|
| 18 | // execute, and transmit the Software, and to prepare derivative works of the |
---|
| 19 | // Software, and to permit third-parties to whom the Software is furnished to |
---|
| 20 | // do so, all subject to the following: |
---|
| 21 | // |
---|
| 22 | // The copyright notices in the Software and this entire statement, including |
---|
| 23 | // the above license grant, this restriction and the following disclaimer, |
---|
| 24 | // must be included in all copies of the Software, in whole or in part, and |
---|
| 25 | // all derivative works of the Software, unless such copies or derivative |
---|
| 26 | // works are solely in the form of machine-executable object code generated by |
---|
| 27 | // a source language processor. |
---|
| 28 | // |
---|
| 29 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 30 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 31 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
---|
| 32 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
---|
| 33 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
---|
| 34 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
| 35 | // DEALINGS IN THE SOFTWARE. |
---|
| 36 | // |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | #ifndef SAX_EntityResolver_INCLUDED |
---|
| 40 | #define SAX_EntityResolver_INCLUDED |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | #include "Poco/XML/XML.h" |
---|
| 44 | #include "Poco/XML/XMLString.h" |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | namespace Poco { |
---|
| 48 | namespace XML { |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | class InputSource; |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | class XML_API EntityResolver |
---|
| 55 | /// If a SAX application needs to implement customized handling for external entities, |
---|
| 56 | /// it must implement this interface and register an instance with the SAX driver using |
---|
| 57 | /// the setEntityResolver method. |
---|
| 58 | /// |
---|
| 59 | /// The XML reader will then allow the application to intercept any external entities |
---|
| 60 | /// (including the external DTD subset and external parameter entities, if any) before |
---|
| 61 | /// including them. |
---|
| 62 | /// |
---|
| 63 | /// Many SAX applications will not need to implement this interface, but it will be |
---|
| 64 | /// especially useful for applications that build XML documents from databases or other |
---|
| 65 | /// specialised input sources, or for applications that use URI types other than URLs. |
---|
| 66 | /// |
---|
| 67 | /// The application can also use this interface to redirect system identifiers to local |
---|
| 68 | /// URIs or to look up replacements in a catalog (possibly by using the public identifier). |
---|
| 69 | { |
---|
| 70 | public: |
---|
| 71 | virtual InputSource* resolveEntity(const XMLString* publicId, const XMLString& systemId) = 0; |
---|
| 72 | /// Allow the application to resolve external entities. |
---|
| 73 | /// |
---|
| 74 | /// The parser will call this method before opening any external entity except the |
---|
| 75 | /// top-level document entity. Such entities include the external DTD subset and |
---|
| 76 | /// external parameter entities referenced within the DTD (in either case, only |
---|
| 77 | /// if the parser reads external parameter entities), and external general entities |
---|
| 78 | /// referenced within the document element (if the parser reads external general entities). |
---|
| 79 | /// The application may request that the parser locate the entity itself, that it use an |
---|
| 80 | /// alternative URI, or that it use data provided by the application (as a character or |
---|
| 81 | /// byte input stream). |
---|
| 82 | /// |
---|
| 83 | /// Application writers can use this method to redirect external system identifiers to |
---|
| 84 | /// secure and/or local URIs, to look up public identifiers in a catalogue, or to read an |
---|
| 85 | /// entity from a database or other input source (including, for example, a dialog box). |
---|
| 86 | /// Neither XML nor SAX specifies a preferred policy for using public or system IDs to resolve |
---|
| 87 | /// resources. However, SAX specifies how to interpret any InputSource returned by this method, |
---|
| 88 | /// and that if none is returned, then the system ID will be dereferenced as a URL. |
---|
| 89 | /// |
---|
| 90 | /// If the system identifier is a URL, the SAX parser must resolve it fully before reporting it to |
---|
| 91 | /// the application. |
---|
| 92 | /// |
---|
| 93 | /// Note that publicId maybe null, therefore we pass a pointer rather than a reference. |
---|
| 94 | |
---|
| 95 | virtual void releaseInputSource(InputSource* pSource) = 0; |
---|
| 96 | /// This is a non-standard extension to SAX! |
---|
| 97 | /// Called by the parser when the input source returned by ResolveEntity is |
---|
| 98 | /// no longer needed. Should free any resources used by the input source. |
---|
| 99 | |
---|
| 100 | protected: |
---|
| 101 | virtual ~EntityResolver(); |
---|
| 102 | }; |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | } } // namespace Poco::XML |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | #endif // SAX_EntityResolver_INCLUDED |
---|