Xerces 3 revisions.
[shibboleth/cpp-xmltooling.git] / xmltooling / util / ParserPool.h
index f4f9a8f..248645d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2006 Internet2
+ *  Copyright 2001-2008 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 
 /**
- * @file ParserPool.h
+ * @file xmltooling/util/ParserPool.h
  * 
- * XML parsing
+ * A thread-safe pool of parsers that share characteristics.
  */
 
-#if !defined(__xmltooling_pool_h__)
+#ifndef __xmltooling_pool_h__
 #define __xmltooling_pool_h__
 
 #include <xmltooling/unicode.h>
 #include <xercesc/dom/DOM.hpp>
 #include <xercesc/sax/InputSource.hpp>
 #include <xercesc/util/BinInputStream.hpp>
+#include <xercesc/util/SecurityManager.hpp>
 
-using namespace xercesc;
+#ifndef XMLTOOLING_NO_XMLSEC\r
+# include <xsec/framework/XSECDefs.hpp>\r
+#endif
 
 #if defined (_MSC_VER)
     #pragma warning( push )
@@ -43,9 +46,14 @@ using namespace xercesc;
 namespace xmltooling {
 
     /**
-     * A thread-safe pool of DOMBuilders that share characteristics
+     * A thread-safe pool of DOMBuilders that share characteristics.
      */
-    class XMLTOOL_API ParserPool : public DOMEntityResolver, DOMErrorHandler
+    class XMLTOOL_API ParserPool : xercesc::DOMErrorHandler,
+#ifdef XMLTOOLING_XERCESC_COMPLIANT_DOMLS
+        public xercesc::DOMLSResourceResolver
+#else
+        public xercesc::DOMEntityResolver
+#endif
     {
         MAKE_NONCOPYABLE(ParserPool);
     public:
@@ -64,16 +72,22 @@ namespace xmltooling {
          * @return new XML document
          * 
          */
-        DOMDocument* newDocument();
+        xercesc::DOMDocument* newDocument();
 
         /**
          * Parses a document using a pooled parser with the proper settings
          * 
-         * @param domsrc A DOM source containing the content to be parsed
+         * @param domsrc An input source containing the content to be parsed
          * @return The DOM document resulting from the parse
          * @throws XMLParserException thrown if there was a problem reading, parsing, or validating the XML
          */
-        DOMDocument* parse(DOMInputSource& domsrc);
+        xercesc::DOMDocument* parse(
+#ifdef XMLTOOLING_XERCESC_COMPLIANT_DOMLS
+            xercesc::DOMLSInput& domsrc
+#else
+            xercesc::DOMInputSource& domsrc
+#endif
+            );
 
         /**
          * Parses a document using a pooled parser with the proper settings
@@ -82,7 +96,7 @@ namespace xmltooling {
          * @return The DOM document resulting from the parse
          * @throws XMLParserException thrown if there was a problem reading, parsing, or validating the XML
          */
-        DOMDocument* parse(std::istream& is);
+        xercesc::DOMDocument* parse(std::istream& is);
 
         /**
          * Load an OASIS catalog file to map schema namespace URIs to filenames.
@@ -110,17 +124,35 @@ namespace xmltooling {
         /**
          * Supplies all external entities (primarily schemas) to the parser
          */
-        DOMInputSource* resolveEntity(const XMLCh* const publicId, const XMLCh* const systemId, const XMLCh* const baseURI);
+#ifdef XMLTOOLING_XERCESC_COMPLIANT_DOMLS
+        xercesc::DOMLSInput* resolveResource(
+            const XMLCh *const resourceType,
+            const XMLCh *const namespaceUri,
+            const XMLCh *const publicId,
+            const XMLCh *const systemId,
+            const XMLCh *const baseURI
+            );
+#else
+        xercesc::DOMInputSource* resolveEntity(
+            const XMLCh* const publicId, const XMLCh* const systemId, const XMLCh* const baseURI
+            );
+#endif
 
         /**
          * Handles parsing errors
          */
-        bool handleError(const DOMError& e);
+        bool handleError(const xercesc::DOMError& e);
 
     private:
-        DOMBuilder* createBuilder();
-        DOMBuilder* checkoutBuilder();
-        void checkinBuilder(DOMBuilder* builder);
+#ifdef XMLTOOLING_XERCESC_COMPLIANT_DOMLS
+        xercesc::DOMLSParser* createBuilder();
+        xercesc::DOMLSParser* checkoutBuilder();
+        void checkinBuilder(xercesc::DOMLSParser* builder);
+#else
+        xercesc::DOMBuilder* createBuilder();
+        xercesc::DOMBuilder* checkoutBuilder();
+        void checkinBuilder(xercesc::DOMBuilder* builder);
+#endif
 
 #ifdef HAVE_GOOD_STL
         xstring m_schemaLocations;
@@ -130,14 +162,19 @@ namespace xmltooling {
         std::map<std::string,std::string> m_schemaLocMap;
 #endif
         bool m_namespaceAware,m_schemaAware;
-        std::stack<DOMBuilder*> m_pool;
+#ifdef XMLTOOLING_XERCESC_COMPLIANT_DOMLS
+        std::stack<xercesc::DOMLSParser*> m_pool;
+#else
+        std::stack<xercesc::DOMBuilder*> m_pool;
+#endif
         Mutex* m_lock;
+        xercesc::SecurityManager* m_security;
     };
 
     /**
      * A parser source that wraps a C++ input stream
      */
-    class XMLTOOL_API StreamInputSource : public InputSource
+    class XMLTOOL_API StreamInputSource : public xercesc::InputSource
     {
     MAKE_NONCOPYABLE(StreamInputSource);
     public:
@@ -147,30 +184,38 @@ namespace xmltooling {
          * @param is        reference to an input stream
          * @param systemId  optional system identifier to attach to the stream
          */
-        StreamInputSource(std::istream& is, const char* systemId=NULL) : InputSource(systemId), m_is(is) {}
+        StreamInputSource(std::istream& is, const char* systemId=NULL) : xercesc::InputSource(systemId), m_is(is) {}
         /// @cond off
-        virtual BinInputStream* makeStream() const { return new StreamBinInputStream(m_is); }
+        virtual xercesc::BinInputStream* makeStream() const { return new StreamBinInputStream(m_is); }
         /// @endcond
 
         /**
          * A Xerces input stream that wraps a C++ input stream
          */
-        class XMLTOOL_API StreamBinInputStream : public BinInputStream
+        class XMLTOOL_API StreamBinInputStream : public xercesc::BinInputStream
         {
         public:
             /**
              * Constructs a Xerces input stream around a C++ input stream reference.
              * 
-             * @param is        reference to an input stream
+             * @param is            reference to an input stream
              */
             StreamBinInputStream(std::istream& is) : m_is(is), m_pos(0) {}
             /// @cond off
-            virtual unsigned int curPos() const { return m_pos; }
-            virtual unsigned int readBytes(XMLByte* const toFill, const unsigned int maxToRead);
+#ifdef XMLTOOLING_XERCESC_64BITSAFE
+            XMLFilePos
+#else
+            unsigned int
+#endif
+                curPos() const { return m_pos; }
+            xsecsize_t readBytes(XMLByte* const toFill, const xsecsize_t maxToRead);
+#ifdef XMLTOOLING_XERCESC_64BITSAFE
+            const XMLCh* getContentType() const { return NULL; }
+#endif
             /// @endcond
         private:
             std::istream& m_is;
-            unsigned int m_pos;
+            xsecsize_t m_pos;
         };
 
     private: