diff --git a/samples/Redirect/Redirect.cpp b/samples/Redirect/Redirect.cpp index 410e98f09aa4a0d7b725c412a998b7ae9357ebae..8029f47afe156940e18455d0138061a751312f4f 100644 --- a/samples/Redirect/Redirect.cpp +++ b/samples/Redirect/Redirect.cpp @@ -35,6 +35,9 @@ * to read the contents of 'personal.dtd'. * * $Log$ + * Revision 1.12 2005/04/05 15:16:36 cargilld + * Update Redirect sample to use newer entity resolver callback. + * * Revision 1.11 2004/09/08 13:55:33 peiyongz * Apache License Version 2.0 * @@ -139,7 +142,9 @@ int main(int argc, char* args[]) RedirectHandlers handler; parser->setDocumentHandler(&handler); parser->setErrorHandler(&handler); - parser->setEntityResolver(&handler); + //Use the new XML Entity Resolver + //parser->setEntityResolver(&handler); + parser->setXMLEntityResolver(&handler); // // Get the starting time and kick off the parse of the indicated file. diff --git a/samples/Redirect/RedirectHandlers.cpp b/samples/Redirect/RedirectHandlers.cpp index ce82caf94515aaa65414840d4ab830325b1f1e15..8a352ff08450a70b5e95c970867e56869e1221a8 100644 --- a/samples/Redirect/RedirectHandlers.cpp +++ b/samples/Redirect/RedirectHandlers.cpp @@ -133,6 +133,8 @@ void RedirectHandlers::warning(const SAXParseException& e) } +#if 0 +// This is the old resolveEntity interface... // ----------------------------------------------------------------------- // Handlers for the SAX EntityResolver interface // ----------------------------------------------------------------------- @@ -167,3 +169,38 @@ InputSource* RedirectHandlers::resolveEntity(const XMLCh* const /* publicId // They were equal, so redirect to our other file return new LocalFileInputSource(gRedirectToFile); } +#endif +// ----------------------------------------------------------------------- +// Handlers for the XMLEntityResolver interface +// ----------------------------------------------------------------------- + +InputSource* RedirectHandlers::resolveEntity(XMLResourceIdentifier* resourceIdentifier) +{ + // + // If its our file, then create a new URL input source for the file that + // we want to really be used. Otherwise, just return zero to let the + // default action occur. + // + // We cannot assume that the XMLCh type is ok to pass to wcscmp(), so + // just do a comparison ourselves. + // + const XMLCh* s1 = gFileToTrap; + const XMLCh* s2 = resourceIdentifier->getSystemId(); + while (true) + { + // Break out on any difference + if (*s1 != *s2) + return 0; + + // If one is null, then both were null, so they are equal + if (!*s1) + break; + + // Else get the next char + s1++; + s2++; + } + + // They were equal, so redirect to our other file + return new LocalFileInputSource(gRedirectToFile); +} diff --git a/samples/Redirect/RedirectHandlers.hpp b/samples/Redirect/RedirectHandlers.hpp index 7f9dd20deac897ca5dbce342b8e0b69fe53edce2..5b7bde6f758b06e90bc1148dbf47c04d7ed81e8f 100644 --- a/samples/Redirect/RedirectHandlers.hpp +++ b/samples/Redirect/RedirectHandlers.hpp @@ -16,6 +16,9 @@ /* * $Log$ + * Revision 1.9 2005/04/05 15:16:36 cargilld + * Update Redirect sample to use newer entity resolver callback. + * * Revision 1.8 2004/09/08 13:55:33 peiyongz * Apache License Version 2.0 * @@ -52,6 +55,7 @@ // Includes // --------------------------------------------------------------------------- #include <xercesc/sax/HandlerBase.hpp> +#include <xercesc/util/XMLEntityResolver.hpp> XERCES_CPP_NAMESPACE_USE @@ -60,7 +64,7 @@ class AttributeList; XERCES_CPP_NAMESPACE_END -class RedirectHandlers : public HandlerBase +class RedirectHandlers : public HandlerBase, public XMLEntityResolver { public: // ----------------------------------------------------------------------- @@ -111,6 +115,8 @@ public: void fatalError(const SAXParseException& exc); +#if 0 + // This is the old resolveEntity interface // ----------------------------------------------------------------------- // Handlers for the SAX EntityResolver interface // ----------------------------------------------------------------------- @@ -119,7 +125,14 @@ public: const XMLCh* const publicId , const XMLCh* const systemId ); - +#endif + // ----------------------------------------------------------------------- + // Handlers for the XMLEntityResolver interface + // ----------------------------------------------------------------------- + InputSource* resolveEntity + ( + XMLResourceIdentifier* resourceIdentifier + ); private: // -----------------------------------------------------------------------