source: NonGTP/Xerces/xercesc/util/XMLEntityResolver.hpp @ 188

Revision 188, 8.3 KB checked in by mattausch, 19 years ago (diff)

added xercesc to support

Line 
1/*
2 * The Apache Software License, Version 1.1
3 *
4 * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
5 * reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in
16 *    the documentation and/or other materials provided with the
17 *    distribution.
18 *
19 * 3. The end-user documentation included with the redistribution,
20 *    if any, must include the following acknowledgment:
21 *       "This product includes software developed by the
22 *        Apache Software Foundation (http://www.apache.org/)."
23 *    Alternately, this acknowledgment may appear in the software itself,
24 *    if and wherever such third-party acknowledgments normally appear.
25 *
26 * 4. The names "Xerces" and "Apache Software Foundation" must
27 *    not be used to endorse or promote products derived from this
28 *    software without prior written permission. For written
29 *    permission, please contact apache\@apache.org.
30 *
31 * 5. Products derived from this software may not be called "Apache",
32 *    nor may "Apache" appear in their name, without prior written
33 *    permission of the Apache Software Foundation.
34 *
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation, and was
51 * originally based on software copyright (c) 1999, International
52 * Business Machines, Inc., http://www.ibm.com .  For more information
53 * on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57/*
58 * $Log: XMLEntityResolver.hpp,v $
59 * Revision 1.1  2003/10/30 21:37:32  knoaman
60 * Enhanced Entity Resolver Support. Thanks to David Cargill.
61 *
62 *
63 * Revision 1.1    1999/11/09 01:07:44  twl
64 * Initial checkin
65 *
66 */
67
68#ifndef XMLENTITYRESOLVER_HPP
69#define XMLENTITYRESOLVER_HPP
70
71#include <xercesc/util/XercesDefs.hpp>
72#include <xercesc/util/XMemory.hpp>
73#include <xercesc/util/XMLResourceIdentifier.hpp>
74
75XERCES_CPP_NAMESPACE_BEGIN
76
77class InputSource;
78
79/**
80  * Revised interface for resolving entities.
81  *
82  * <p>If an application needs to implement customized handling
83  * for external entities, it can implement this interface and
84  * register an instance with the parser using the parser's
85  * setXMLEntityResolver method or it can use the basic SAX interface
86  * (EntityResolver).  The difference between the two interfaces is
87  * the arguments to the resolveEntity() method.  With the SAX
88  * EntityResolve the arguments are systemId and publicId.  With this
89  * interface the argument is a XMLResourceIdentifier object.  <i>Only
90  * one EntityResolver can be set using setEntityResolver() or
91  * setXMLEntityResolver, if both are set the last one set is
92  * used.</i></p>
93  *
94  * <p>The parser will then allow the application to intercept any
95  * external entities (including the external DTD subset and external
96  * parameter entities, if any) before including them.</p>
97  *
98  * <p>Many applications will not need to implement this interface,
99  * but it will be especially useful for applications that build
100  * XML documents from databases or other specialised input sources,
101  * or for applications that use URI types other than URLs.</p>
102  *
103  * <p>The following resolver would provide the application
104  * with a special character stream for the entity with the system
105  * identifier "http://www.myhost.com/today":</p>
106  *
107  *<pre>
108  * #include <xercesc/util/XMLEntityResolver.hpp>
109  * #include <xercesc/sax/InputSource.hpp>
110  *
111  * class MyResolver : public XMLEntityResolver {
112  *  public:
113  *    InputSource resolveEntity (XMLResourceIdentifier* xmlri);
114  *   ...
115  *   };
116  *
117  *  MyResolver::resolveEntity(XMLResourceIdentifier* xmlri) {
118  *    switch(xmlri->getResourceIdentifierType()) {
119  *      case XMLResourceIdentifier::SystemId:
120  *        if (XMLString::compareString(xmlri->getSystemId(), "http://www.myhost.com/today")) {
121  *          MyReader* reader = new MyReader();
122  *          return new InputSource(reader);
123  *        } else {
124  *          return null;
125  *        }
126  *        break;
127  *      default:
128  *        return null;
129  *    }
130  *  }</pre>
131  *
132  * <p>The application can also use this interface to redirect system
133  * identifiers to local URIs or to look up replacements in a catalog
134  * (possibly by using the public identifier).</p>
135  *
136  * <p>The HandlerBase class implements the default behaviour for
137  * this interface, which is simply always to return null (to request
138  * that the parser use the default system identifier).</p>
139  *
140  * @see XMLResourceIdentifier
141  * @see Parser#setXMLEntityResolver
142  * @see InputSource#InputSource
143  * @see HandlerBase#HandlerBase
144  */
145class XMLUTIL_EXPORT XMLEntityResolver
146{
147public:
148    /** @name Constructors and Destructor */
149    //@{
150
151
152    /** Destructor */
153    virtual ~XMLEntityResolver()
154    {
155    }
156
157    //@}
158
159    /** @name The XMLEntityResolver interface */
160    //@{
161
162  /**
163    * Allow the application to resolve external entities.
164    *
165    * <p>The Parser will call this method before opening any external
166    * entity except the top-level document entity (including the
167    * external DTD subset, external entities referenced within the
168    * DTD, and external entities referenced within the document
169    * element): the application may request that the parser resolve
170    * the entity itself, that it use an alternative URI, or that it
171    * use an entirely different input source.</p>
172    *
173    * <p>Application writers can use this method to redirect external
174    * system identifiers to secure and/or local URIs, to look up
175    * public identifiers in a catalogue, or to read an entity from a
176    * database or other input source (including, for example, a dialog
177    * box).</p>
178    *
179    * <p>If the system identifier is a URL, the SAX parser must
180    * resolve it fully before reporting it to the application.</p>
181    *
182    * @param resourceIdentifier An object containing the type of
183    *        resource to be resolved and the associated data members
184    *        corresponding to this type.
185    * @return An InputSource object describing the new input source,
186    *         or null to request that the parser open a regular
187    *         URI connection to the system identifier.
188    *         The returned InputSource is owned by the parser which is
189    *         responsible to clean up the memory.
190    * @exception SAXException Any SAX exception, possibly
191    *            wrapping another exception.
192    * @exception IOException An IO exception,
193    *            possibly the result of creating a new InputStream
194    *            or Reader for the InputSource.
195    *
196    * @see InputSource#InputSource
197    * @see XMLResourceIdentifier
198    */
199    virtual InputSource* resolveEntity
200    (
201        XMLResourceIdentifier* resourceIdentifier
202    ) = 0;
203
204    //@}
205protected:
206    /** Default Constructor */
207    XMLEntityResolver()
208    {
209    }
210
211private :
212    /* Unimplemented constructors and operators */
213
214    /* Copy constructor */
215    XMLEntityResolver(const XMLEntityResolver&);
216
217    /* Assignment operator */
218    XMLEntityResolver& operator=(const XMLEntityResolver&);
219
220};
221
222XERCES_CPP_NAMESPACE_END
223
224#endif
Note: See TracBrowser for help on using the repository browser.