Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/xercesc/util/XMLEntityResolver.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  * 
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  * 
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_XMLENTITYRESOLVER_HPP)
0023 #define XERCESC_INCLUDE_GUARD_XMLENTITYRESOLVER_HPP
0024 
0025 #include <xercesc/util/XercesDefs.hpp>
0026 #include <xercesc/util/XMemory.hpp>
0027 #include <xercesc/util/XMLResourceIdentifier.hpp>
0028 
0029 XERCES_CPP_NAMESPACE_BEGIN
0030 
0031 class InputSource;
0032 
0033 /**
0034   * Revised interface for resolving entities.
0035   *
0036   * <p>If an application needs to implement customized handling
0037   * for external entities, it can implement this interface and
0038   * register an instance with the parser using the parser's
0039   * setXMLEntityResolver method or it can use the basic SAX interface 
0040   * (EntityResolver).  The difference between the two interfaces is
0041   * the arguments to the resolveEntity() method.  With the SAX
0042   * EntityResolve the arguments are systemId and publicId.  With this
0043   * interface the argument is a XMLResourceIdentifier object.  <i>Only
0044   * one EntityResolver can be set using setEntityResolver() or 
0045   * setXMLEntityResolver, if both are set the last one set is 
0046   * used.</i></p>
0047   *
0048   * <p>The parser will then allow the application to intercept any
0049   * external entities (including the external DTD subset and external
0050   * parameter entities, if any) before including them.</p>
0051   *
0052   * <p>Many applications will not need to implement this interface,
0053   * but it will be especially useful for applications that build
0054   * XML documents from databases or other specialised input sources,
0055   * or for applications that use URI types other than URLs.</p>
0056   *
0057   * <p>The following resolver would provide the application
0058   * with a special character stream for the entity with the system
0059   * identifier "http://www.myhost.com/today":</p>
0060   *
0061   *<code>
0062   * \#include <xercesc/util/XMLEntityResolver.hpp><br>
0063   * \#include <xercesc/sax/InputSource.hpp><br>
0064   *<br>
0065   *&nbsp;class MyResolver : public XMLEntityResolver {<br>
0066   *&nbsp;&nbsp;public:<br>
0067   *&nbsp;&nbsp;&nbsp;InputSource* resolveEntity (XMLResourceIdentifier* xmlri);<br>
0068   *&nbsp;&nbsp;&nbsp;...<br>
0069   *&nbsp;&nbsp;};<br>
0070   *<br>
0071   *&nbsp;MyResolver::resolveEntity(XMLResourceIdentifier* xmlri) {<br>
0072   *&nbsp;&nbsp;switch(xmlri->getResourceIdentifierType()) {<br>
0073   *&nbsp;&nbsp;&nbsp;case XMLResourceIdentifier::SystemId:<br>
0074   *&nbsp;&nbsp;&nbsp;&nbsp;if (XMLString::compareString(xmlri->getSystemId(), "http://www.myhost.com/today")) {<br>
0075   *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyReader* reader = new MyReader();<br>
0076   *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return new InputSource(reader);<br>
0077   *&nbsp;&nbsp;&nbsp;&nbsp;} else {<br>
0078   *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return null;<br>
0079   *&nbsp;&nbsp;&nbsp;&nbsp;}<br>
0080   *&nbsp;&nbsp;&nbsp;&nbsp;break;<br>
0081   *&nbsp;&nbsp;&nbsp;default:<br>
0082   *&nbsp;&nbsp;&nbsp;&nbsp;return null;<br>
0083   *&nbsp;&nbsp;}<br>
0084   *&nbsp;}</code>
0085   *
0086   * <p>The application can also use this interface to redirect system
0087   * identifiers to local URIs or to look up replacements in a catalog
0088   * (possibly by using the public identifier).</p>
0089   *
0090   * <p>The HandlerBase class implements the default behaviour for
0091   * this interface, which is simply always to return null (to request
0092   * that the parser use the default system identifier).</p>
0093   *
0094   * @see XMLResourceIdentifier
0095   * @see Parser#setXMLEntityResolver
0096   * @see InputSource#InputSource
0097   * @see HandlerBase#HandlerBase
0098   */
0099 class XMLUTIL_EXPORT XMLEntityResolver
0100 {
0101 public:
0102     /** @name Constructors and Destructor */
0103     //@{
0104 
0105 
0106     /** Destructor */
0107     virtual ~XMLEntityResolver()
0108     {
0109     }
0110 
0111     //@}
0112 
0113     /** @name The XMLEntityResolver interface */
0114     //@{
0115 
0116   /**
0117     * Allow the application to resolve external entities.
0118     *
0119     * <p>The Parser will call this method before opening any external
0120     * entity except the top-level document entity (including the
0121     * external DTD subset, external entities referenced within the
0122     * DTD, and external entities referenced within the document
0123     * element): the application may request that the parser resolve
0124     * the entity itself, that it use an alternative URI, or that it
0125     * use an entirely different input source.</p>
0126     *
0127     * <p>Application writers can use this method to redirect external
0128     * system identifiers to secure and/or local URIs, to look up
0129     * public identifiers in a catalogue, or to read an entity from a
0130     * database or other input source (including, for example, a dialog
0131     * box).</p>
0132     *
0133     * <p>If the system identifier is a URL, the SAX parser must
0134     * resolve it fully before reporting it to the application.</p>
0135     *
0136     * @param resourceIdentifier An object containing the type of
0137     *        resource to be resolved and the associated data members
0138     *        corresponding to this type.
0139     * @return An InputSource object describing the new input source,
0140     *         or null to request that the parser open a regular
0141     *         URI connection to the system identifier.
0142     *         The returned InputSource is owned by the parser which is
0143     *         responsible to clean up the memory.
0144     * @exception SAXException Any SAX exception, possibly
0145     *            wrapping another exception.
0146     * @exception IOException An IO exception,
0147     *            possibly the result of creating a new InputStream
0148     *            or Reader for the InputSource.
0149     *
0150     * @see InputSource#InputSource
0151     * @see XMLResourceIdentifier
0152     */
0153     virtual InputSource* resolveEntity
0154     (
0155         XMLResourceIdentifier* resourceIdentifier
0156     ) = 0;
0157 
0158     //@}
0159 protected: 
0160     /** Default Constructor */
0161     XMLEntityResolver()
0162     {
0163     }
0164 
0165 private :
0166     /* Unimplemented constructors and operators */
0167 
0168     /* Copy constructor */
0169     XMLEntityResolver(const XMLEntityResolver&);
0170 
0171     /* Assignment operator */
0172     XMLEntityResolver& operator=(const XMLEntityResolver&);
0173 
0174 };
0175 
0176 XERCES_CPP_NAMESPACE_END
0177 
0178 #endif