1 | /* |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | * contributor license agreements. See the NOTICE file distributed with |
---|
4 | * this work for additional information regarding copyright ownership. |
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | * (the "License"); you may not use this file except in compliance with |
---|
7 | * the License. You may obtain a copy of the License at |
---|
8 | * |
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | * |
---|
11 | * Unless required by applicable law or agreed to in writing, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | */ |
---|
17 | |
---|
18 | /* |
---|
19 | * $Id: EntityResolver.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
20 | */ |
---|
21 | |
---|
22 | |
---|
23 | #ifndef ENTITYRESOLVER_HPP |
---|
24 | #define ENTITYRESOLVER_HPP |
---|
25 | |
---|
26 | #include <xercesc/util/XercesDefs.hpp> |
---|
27 | |
---|
28 | XERCES_CPP_NAMESPACE_BEGIN |
---|
29 | |
---|
30 | class InputSource; |
---|
31 | |
---|
32 | /** |
---|
33 | * Basic interface for resolving entities. |
---|
34 | * |
---|
35 | * <p>If a SAX application needs to implement customized handling |
---|
36 | * for external entities, it must implement this interface and |
---|
37 | * register an instance with the SAX parser using the parser's |
---|
38 | * setEntityResolver method.</p> |
---|
39 | * |
---|
40 | * <p>The parser will then allow the application to intercept any |
---|
41 | * external entities (including the external DTD subset and external |
---|
42 | * parameter entities, if any) before including them.</p> |
---|
43 | * |
---|
44 | * <p>Many SAX applications will not need to implement this interface, |
---|
45 | * but it will be especially useful for applications that build |
---|
46 | * XML documents from databases or other specialised input sources, |
---|
47 | * or for applications that use URI types other than URLs.</p> |
---|
48 | * |
---|
49 | * <p>The following resolver would provide the application |
---|
50 | * with a special character stream for the entity with the system |
---|
51 | * identifier "http://www.myhost.com/today":</p> |
---|
52 | * |
---|
53 | *<code> |
---|
54 | *#include <xercesc/sax/EntityResolver.hpp><br> |
---|
55 | *#include <xercesc/sax/InputSource.hpp><br> |
---|
56 | *<br> |
---|
57 | *class MyResolver : public EntityResolver {<br> |
---|
58 | * public:<br> |
---|
59 | * InputSource resolveEntity (const XMLCh* const publicId, const XMLCh* const systemId);<br> |
---|
60 | * <br> |
---|
61 | * ...<br> |
---|
62 | * };<br> |
---|
63 | *<br> |
---|
64 | * MyResolver::resolveEntity {<br> |
---|
65 | * if (XMLString::compareString(systemId, "http://www.myhost.com/today")) {<br> |
---|
66 | * MyReader* reader = new MyReader();<br> |
---|
67 | * return new InputSource(reader);<br> |
---|
68 | * } else {<br> |
---|
69 | * return null;<br> |
---|
70 | * }<br> |
---|
71 | * }<br> |
---|
72 | *<br> |
---|
73 | *</code> |
---|
74 | * |
---|
75 | * <p>The application can also use this interface to redirect system |
---|
76 | * identifiers to local URIs or to look up replacements in a catalog |
---|
77 | * (possibly by using the public identifier).</p> |
---|
78 | * |
---|
79 | * <p>The HandlerBase class implements the default behaviour for |
---|
80 | * this interface, which is simply always to return null (to request |
---|
81 | * that the parser use the default system identifier).</p> |
---|
82 | * |
---|
83 | * @see Parser#setEntityResolver |
---|
84 | * @see InputSource#InputSource |
---|
85 | * @see HandlerBase#HandlerBase |
---|
86 | */ |
---|
87 | class SAX_EXPORT EntityResolver |
---|
88 | { |
---|
89 | public: |
---|
90 | /** @name Constructors and Destructor */ |
---|
91 | //@{ |
---|
92 | |
---|
93 | /** Default Constructor */ |
---|
94 | EntityResolver() |
---|
95 | { |
---|
96 | } |
---|
97 | |
---|
98 | /** Destructor */ |
---|
99 | virtual ~EntityResolver() |
---|
100 | { |
---|
101 | } |
---|
102 | |
---|
103 | //@} |
---|
104 | |
---|
105 | /** @name The EntityResolver interface */ |
---|
106 | //@{ |
---|
107 | |
---|
108 | /** |
---|
109 | * Allow the application to resolve external entities. |
---|
110 | * |
---|
111 | * <p>The Parser will call this method before opening any external |
---|
112 | * entity except the top-level document entity (including the |
---|
113 | * external DTD subset, external entities referenced within the |
---|
114 | * DTD, and external entities referenced within the document |
---|
115 | * element): the application may request that the parser resolve |
---|
116 | * the entity itself, that it use an alternative URI, or that it |
---|
117 | * use an entirely different input source.</p> |
---|
118 | * |
---|
119 | * <p>Application writers can use this method to redirect external |
---|
120 | * system identifiers to secure and/or local URIs, to look up |
---|
121 | * public identifiers in a catalogue, or to read an entity from a |
---|
122 | * database or other input source (including, for example, a dialog |
---|
123 | * box).</p> |
---|
124 | * |
---|
125 | * <p>If the system identifier is a URL, the SAX parser must |
---|
126 | * resolve it fully before reporting it to the application.</p> |
---|
127 | * |
---|
128 | * @param publicId The public identifier of the external entity |
---|
129 | * being referenced, or null if none was supplied. |
---|
130 | * @param systemId The system identifier of the external entity |
---|
131 | * being referenced. |
---|
132 | * @return An InputSource object describing the new input source, |
---|
133 | * or null to request that the parser open a regular |
---|
134 | * URI connection to the system identifier. |
---|
135 | * The returned InputSource is owned by the parser which is |
---|
136 | * responsible to clean up the memory. |
---|
137 | * @exception SAXException Any SAX exception, possibly |
---|
138 | * wrapping another exception. |
---|
139 | * @exception IOException An IO exception, |
---|
140 | * possibly the result of creating a new InputStream |
---|
141 | * or Reader for the InputSource. |
---|
142 | * @see InputSource#InputSource |
---|
143 | */ |
---|
144 | virtual InputSource* resolveEntity |
---|
145 | ( |
---|
146 | const XMLCh* const publicId |
---|
147 | , const XMLCh* const systemId |
---|
148 | ) = 0; |
---|
149 | |
---|
150 | //@} |
---|
151 | |
---|
152 | private : |
---|
153 | /* Unimplemented constructors and operators */ |
---|
154 | |
---|
155 | |
---|
156 | /* Copy constructor */ |
---|
157 | EntityResolver(const EntityResolver&); |
---|
158 | |
---|
159 | /* Assignment operator */ |
---|
160 | EntityResolver& operator=(const EntityResolver&); |
---|
161 | |
---|
162 | }; |
---|
163 | |
---|
164 | XERCES_CPP_NAMESPACE_END |
---|
165 | |
---|
166 | #endif |
---|