1 | /*
|
---|
2 | * Copyright 1999-2000,2004 The Apache Software Foundation.
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | */
|
---|
16 |
|
---|
17 | /*
|
---|
18 | * $Log: XMLEntityResolver.hpp,v $
|
---|
19 | * Revision 1.3 2004/09/26 01:06:31 cargilld
|
---|
20 | * Fix documentation generation problem. Replace <pre> with <code>. Patch from James Littlejohn.
|
---|
21 | *
|
---|
22 | * Revision 1.2 2004/09/08 13:56:24 peiyongz
|
---|
23 | * Apache License Version 2.0
|
---|
24 | *
|
---|
25 | * Revision 1.1 2003/10/30 21:37:32 knoaman
|
---|
26 | * Enhanced Entity Resolver Support. Thanks to David Cargill.
|
---|
27 | *
|
---|
28 | *
|
---|
29 | * Revision 1.1 1999/11/09 01:07:44 twl
|
---|
30 | * Initial checkin
|
---|
31 | *
|
---|
32 | */
|
---|
33 |
|
---|
34 | #ifndef XMLENTITYRESOLVER_HPP
|
---|
35 | #define XMLENTITYRESOLVER_HPP
|
---|
36 |
|
---|
37 | #include <xercesc/util/XercesDefs.hpp>
|
---|
38 | #include <xercesc/util/XMemory.hpp>
|
---|
39 | #include <xercesc/util/XMLResourceIdentifier.hpp>
|
---|
40 |
|
---|
41 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
42 |
|
---|
43 | class InputSource;
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Revised interface for resolving entities.
|
---|
47 | *
|
---|
48 | * <p>If an application needs to implement customized handling
|
---|
49 | * for external entities, it can implement this interface and
|
---|
50 | * register an instance with the parser using the parser's
|
---|
51 | * setXMLEntityResolver method or it can use the basic SAX interface
|
---|
52 | * (EntityResolver). The difference between the two interfaces is
|
---|
53 | * the arguments to the resolveEntity() method. With the SAX
|
---|
54 | * EntityResolve the arguments are systemId and publicId. With this
|
---|
55 | * interface the argument is a XMLResourceIdentifier object. <i>Only
|
---|
56 | * one EntityResolver can be set using setEntityResolver() or
|
---|
57 | * setXMLEntityResolver, if both are set the last one set is
|
---|
58 | * used.</i></p>
|
---|
59 | *
|
---|
60 | * <p>The parser will then allow the application to intercept any
|
---|
61 | * external entities (including the external DTD subset and external
|
---|
62 | * parameter entities, if any) before including them.</p>
|
---|
63 | *
|
---|
64 | * <p>Many applications will not need to implement this interface,
|
---|
65 | * but it will be especially useful for applications that build
|
---|
66 | * XML documents from databases or other specialised input sources,
|
---|
67 | * or for applications that use URI types other than URLs.</p>
|
---|
68 | *
|
---|
69 | * <p>The following resolver would provide the application
|
---|
70 | * with a special character stream for the entity with the system
|
---|
71 | * identifier "http://www.myhost.com/today":</p>
|
---|
72 | *
|
---|
73 | *<code>
|
---|
74 | * #include <xercesc/util/XMLEntityResolver.hpp><br>
|
---|
75 | * #include <xercesc/sax/InputSource.hpp><br>
|
---|
76 | *<br>
|
---|
77 | * class MyResolver : public XMLEntityResolver {<br>
|
---|
78 | * public:<br>
|
---|
79 | * InputSource resolveEntity (XMLResourceIdentifier* xmlri);<br>
|
---|
80 | * ...<br>
|
---|
81 | * };<br>
|
---|
82 | *<br>
|
---|
83 | * MyResolver::resolveEntity(XMLResourceIdentifier* xmlri) {<br>
|
---|
84 | * switch(xmlri->getResourceIdentifierType()) {<br>
|
---|
85 | * case XMLResourceIdentifier::SystemId:<br>
|
---|
86 | * if (XMLString::compareString(xmlri->getSystemId(), "http://www.myhost.com/today")) {<br>
|
---|
87 | * MyReader* reader = new MyReader();<br>
|
---|
88 | * return new InputSource(reader);<br>
|
---|
89 | * } else {<br>
|
---|
90 | * return null;<br>
|
---|
91 | * }<br>
|
---|
92 | * break;<br>
|
---|
93 | * default:<br>
|
---|
94 | * return null;<br>
|
---|
95 | * }<br>
|
---|
96 | * }</code>
|
---|
97 | *
|
---|
98 | * <p>The application can also use this interface to redirect system
|
---|
99 | * identifiers to local URIs or to look up replacements in a catalog
|
---|
100 | * (possibly by using the public identifier).</p>
|
---|
101 | *
|
---|
102 | * <p>The HandlerBase class implements the default behaviour for
|
---|
103 | * this interface, which is simply always to return null (to request
|
---|
104 | * that the parser use the default system identifier).</p>
|
---|
105 | *
|
---|
106 | * @see XMLResourceIdentifier
|
---|
107 | * @see Parser#setXMLEntityResolver
|
---|
108 | * @see InputSource#InputSource
|
---|
109 | * @see HandlerBase#HandlerBase
|
---|
110 | */
|
---|
111 | class XMLUTIL_EXPORT XMLEntityResolver
|
---|
112 | {
|
---|
113 | public:
|
---|
114 | /** @name Constructors and Destructor */
|
---|
115 | //@{
|
---|
116 |
|
---|
117 |
|
---|
118 | /** Destructor */
|
---|
119 | virtual ~XMLEntityResolver()
|
---|
120 | {
|
---|
121 | }
|
---|
122 |
|
---|
123 | //@}
|
---|
124 |
|
---|
125 | /** @name The XMLEntityResolver interface */
|
---|
126 | //@{
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * Allow the application to resolve external entities.
|
---|
130 | *
|
---|
131 | * <p>The Parser will call this method before opening any external
|
---|
132 | * entity except the top-level document entity (including the
|
---|
133 | * external DTD subset, external entities referenced within the
|
---|
134 | * DTD, and external entities referenced within the document
|
---|
135 | * element): the application may request that the parser resolve
|
---|
136 | * the entity itself, that it use an alternative URI, or that it
|
---|
137 | * use an entirely different input source.</p>
|
---|
138 | *
|
---|
139 | * <p>Application writers can use this method to redirect external
|
---|
140 | * system identifiers to secure and/or local URIs, to look up
|
---|
141 | * public identifiers in a catalogue, or to read an entity from a
|
---|
142 | * database or other input source (including, for example, a dialog
|
---|
143 | * box).</p>
|
---|
144 | *
|
---|
145 | * <p>If the system identifier is a URL, the SAX parser must
|
---|
146 | * resolve it fully before reporting it to the application.</p>
|
---|
147 | *
|
---|
148 | * @param resourceIdentifier An object containing the type of
|
---|
149 | * resource to be resolved and the associated data members
|
---|
150 | * corresponding to this type.
|
---|
151 | * @return An InputSource object describing the new input source,
|
---|
152 | * or null to request that the parser open a regular
|
---|
153 | * URI connection to the system identifier.
|
---|
154 | * The returned InputSource is owned by the parser which is
|
---|
155 | * responsible to clean up the memory.
|
---|
156 | * @exception SAXException Any SAX exception, possibly
|
---|
157 | * wrapping another exception.
|
---|
158 | * @exception IOException An IO exception,
|
---|
159 | * possibly the result of creating a new InputStream
|
---|
160 | * or Reader for the InputSource.
|
---|
161 | *
|
---|
162 | * @see InputSource#InputSource
|
---|
163 | * @see XMLResourceIdentifier
|
---|
164 | */
|
---|
165 | virtual InputSource* resolveEntity
|
---|
166 | (
|
---|
167 | XMLResourceIdentifier* resourceIdentifier
|
---|
168 | ) = 0;
|
---|
169 |
|
---|
170 | //@}
|
---|
171 | protected:
|
---|
172 | /** Default Constructor */
|
---|
173 | XMLEntityResolver()
|
---|
174 | {
|
---|
175 | }
|
---|
176 |
|
---|
177 | private :
|
---|
178 | /* Unimplemented constructors and operators */
|
---|
179 |
|
---|
180 | /* Copy constructor */
|
---|
181 | XMLEntityResolver(const XMLEntityResolver&);
|
---|
182 |
|
---|
183 | /* Assignment operator */
|
---|
184 | XMLEntityResolver& operator=(const XMLEntityResolver&);
|
---|
185 |
|
---|
186 | };
|
---|
187 |
|
---|
188 | XERCES_CPP_NAMESPACE_END
|
---|
189 |
|
---|
190 | #endif
|
---|