Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:27:02

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_DOMNORMALIZER_HPP)
0023 #define XERCESC_INCLUDE_GUARD_DOMNORMALIZER_HPP
0024 
0025 //
0026 //  This file is part of the internal implementation of the C++ XML DOM.
0027 //  It should NOT be included or used directly by application programs.
0028 //
0029 //  Applications should include the file <xercesc/dom/DOM.hpp> for the entire
0030 //  DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
0031 //  name is substituded for the *.
0032 //
0033 
0034 #include <xercesc/util/XercesDefs.hpp>
0035 #include <xercesc/util/RefHashTableOf.hpp>
0036 #include <xercesc/util/RefVectorOf.hpp>
0037 #include <xercesc/framework/XMLErrorCodes.hpp>
0038 
0039 
0040 XERCES_CPP_NAMESPACE_BEGIN
0041 
0042 class DOMConfigurationImpl;
0043 class DOMErrorHandler;
0044 class DOMDocumentImpl;
0045 class DOMNode;
0046 class DOMElementImpl;
0047 class DOMAttr;
0048 class DOMNamedNodeMap;
0049 
0050 class DOMNormalizer : public XMemory {
0051 
0052     //the following are the data structures maintain the stack of namespace information
0053     class InScopeNamespaces : public XMemory {
0054         class Scope : public XMemory {
0055         public:
0056             Scope(Scope *baseScopeWithBindings);
0057             ~Scope();
0058             void addOrChangeBinding(const XMLCh *prefix, const XMLCh *uri,
0059                                     MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0060             const XMLCh* getUri(const XMLCh *prefix) const;
0061             const XMLCh* getPrefix(const XMLCh* uri) const;
0062             Scope *fBaseScopeWithBindings;
0063 
0064         private:
0065             RefHashTableOf<XMLCh> *fPrefixHash;
0066             RefHashTableOf<XMLCh> *fUriHash;
0067             // unimplemented
0068             Scope ( const Scope& toCopy);
0069             Scope& operator= (const Scope& other);
0070         };
0071 
0072     public:
0073         InScopeNamespaces(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0074         ~InScopeNamespaces();
0075         void addOrChangeBinding(const XMLCh *prefix, const XMLCh *uri,
0076                                 MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
0077         void addScope(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0078         void removeScope();
0079         bool isValidBinding(const XMLCh* prefix, const XMLCh* uri) const;
0080         const XMLCh* getOrDeclarePrefix(const XMLCh* uri);
0081         const XMLCh* getPrefix(const XMLCh* uri) const;
0082         const XMLCh* getUri(const XMLCh* prefix) const;
0083         XMLSize_t size();
0084 
0085     private:
0086         RefVectorOf<Scope> *fScopes;
0087         Scope *lastScopeWithBindings;
0088         // unimplemented
0089         InScopeNamespaces ( const InScopeNamespaces& toCopy);
0090         InScopeNamespaces& operator= (const InScopeNamespaces& other);
0091     };
0092 
0093 public:
0094     DOMNormalizer(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0095     ~DOMNormalizer();
0096 
0097     /**
0098      * Main entry method to normalize a document
0099      */
0100     void normalizeDocument(DOMDocumentImpl *doc);
0101 
0102 private:
0103     // unimplemented
0104     DOMNormalizer ( const DOMNormalizer& toCopy);
0105     DOMNormalizer& operator= (const DOMNormalizer& other);
0106 
0107 protected:
0108     /**
0109      * Recursively normalizes a node
0110      */
0111     DOMNode * normalizeNode(DOMNode *node) const;
0112 
0113     /**
0114      * Helper method that fixes up the namespace declarations according to the
0115      * DOM Level 3 psydocode
0116      */
0117     void namespaceFixUp(DOMElementImpl *ele) const;
0118 
0119     /**
0120      * Converts an integer to an XMLCh - max 15 digits long.
0121      */
0122     const XMLCh * integerToXMLCh(unsigned int i) const;
0123 
0124     /**
0125      * Adds a namespace attribute or replaces the value of existing namespace
0126      * attribute with the given prefix and value for URI.
0127      * In case prefix is empty will add/update default namespace declaration.
0128      */
0129     void addOrChangeNamespaceDecl(const XMLCh* prefix, const XMLCh* uri, DOMElementImpl *element) const;
0130 
0131     /**
0132      * Adds a custom namespace in the form "NSx" where x is an integer that
0133      * has not yet used in the document
0134      */
0135     const XMLCh* addCustomNamespaceDecl(const XMLCh* uri, DOMElementImpl *element) const;
0136 
0137 
0138     /**
0139      * Report an error
0140      */
0141     void error(const XMLErrs::Codes code, const DOMNode *node) const;
0142 
0143     //
0144     // fDocument - the document we are operating on
0145     //
0146     // fDOMConfiguration - the configuration from the document
0147     //
0148     // fErrorHandler - the errorhandler to be used when reporting errors during normalization
0149     //
0150     // fNSScope - the data stucture that holds the prefix-uri information
0151     //
0152     // fNewNamespaceCount - the number of custom namespace declarations we have created
0153     //
0154     DOMDocumentImpl *fDocument;
0155     DOMConfigurationImpl *fConfiguration;
0156     DOMErrorHandler *fErrorHandler;
0157     InScopeNamespaces *fNSScope;
0158     unsigned int fNewNamespaceCount;
0159     MemoryManager* fMemoryManager;
0160 };
0161 
0162 
0163 
0164 XERCES_CPP_NAMESPACE_END
0165 
0166 #endif