source: icXML/icXML-devel/src/xercesc/dom/impl/DOMNormalizer.hpp

Last change on this file was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 5.5 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: DOMNormalizer.hpp 676911 2008-07-15 13:27:32Z amassari $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_DOMNORMALIZER_HPP)
23#define XERCESC_INCLUDE_GUARD_DOMNORMALIZER_HPP
24
25//
26//  This file is part of the internal implementation of the C++ XML DOM.
27//  It should NOT be included or used directly by application programs.
28//
29//  Applications should include the file <xercesc/dom/DOM.hpp> for the entire
30//  DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
31//  name is substituded for the *.
32//
33
34#include <xercesc/util/XercesDefs.hpp>
35#include <icxercesc/util/RefHashTableOf.hpp>
36#include <xercesc/util/RefVectorOf.hpp>
37#include <xercesc/framework/XMLErrorCodes.hpp>
38
39
40XERCES_CPP_NAMESPACE_BEGIN
41
42class DOMConfigurationImpl;
43class DOMErrorHandler;
44class DOMDocumentImpl;
45class DOMNode;
46class DOMElementImpl;
47class DOMAttr;
48class DOMNamedNodeMap;
49
50class DOMNormalizer : public XMemory {
51
52    //the following are the data structures maintain the stack of namespace information
53    class InScopeNamespaces : public XMemory {
54        class Scope : public XMemory {
55        public:
56            Scope(Scope *baseScopeWithBindings);
57            ~Scope();
58            void addOrChangeBinding(const XMLCh *prefix, const XMLCh *uri,
59                                    MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
60            const XMLCh* getUri(const XMLCh *prefix) const;
61            const XMLCh* getPrefix(const XMLCh* uri) const;
62            Scope *fBaseScopeWithBindings;
63
64        private:
65            RefHashTableOf<XMLCh> *fPrefixHash;
66            RefHashTableOf<XMLCh> *fUriHash;
67            // unimplemented
68            Scope ( const Scope& toCopy);
69            Scope& operator= (const Scope& other);
70        };
71
72    public:
73        InScopeNamespaces(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
74        ~InScopeNamespaces();
75        void addOrChangeBinding(const XMLCh *prefix, const XMLCh *uri,
76                                MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
77        void addScope(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
78        void removeScope();
79        bool isValidBinding(const XMLCh* prefix, const XMLCh* uri) const;
80        const XMLCh* getOrDeclarePrefix(const XMLCh* uri);
81        const XMLCh* getPrefix(const XMLCh* uri) const;
82        const XMLCh* getUri(const XMLCh* prefix) const;
83        XMLSize_t size();
84
85    private:
86        RefVectorOf<Scope> *fScopes;
87        Scope *lastScopeWithBindings;
88        // unimplemented
89        InScopeNamespaces ( const InScopeNamespaces& toCopy);
90        InScopeNamespaces& operator= (const InScopeNamespaces& other);
91    };
92
93public:
94    DOMNormalizer(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
95    ~DOMNormalizer();
96
97    /**
98     * Main entry method to normalize a document
99     */
100    void normalizeDocument(DOMDocumentImpl *doc);
101
102private:
103    // unimplemented
104    DOMNormalizer ( const DOMNormalizer& toCopy);
105    DOMNormalizer& operator= (const DOMNormalizer& other);
106
107protected:
108    /**
109     * Recursively normalizes a node
110     */
111    DOMNode * normalizeNode(DOMNode *node) const;
112
113    /**
114     * Helper method that fixes up the namespace declarations according to the
115     * DOM Level 3 psydocode
116     */
117    void namespaceFixUp(DOMElementImpl *ele) const;
118
119    /**
120     * Converts an integer to an XMLCh - max 15 digits long.
121     */
122    const XMLCh * integerToXMLCh(unsigned int i) const;
123
124    /**
125     * Adds a namespace attribute or replaces the value of existing namespace
126     * attribute with the given prefix and value for URI.
127     * In case prefix is empty will add/update default namespace declaration.
128     */
129    void addOrChangeNamespaceDecl(const XMLCh* prefix, const XMLCh* uri, DOMElementImpl *element) const;
130
131    /**
132     * Adds a custom namespace in the form "NSx" where x is an integer that
133     * has not yet used in the document
134     */
135    const XMLCh* addCustomNamespaceDecl(const XMLCh* uri, DOMElementImpl *element) const;
136
137
138    /**
139     * Report an error
140     */
141    void error(const XMLErrs::Codes code, const DOMNode *node) const;
142
143    //
144    // fDocument - the document we are operating on
145    //
146    // fDOMConfiguration - the configuration from the document
147    //
148    // fErrorHandler - the errorhandler to be used when reporting errors during normalization
149    //
150    // fNSScope - the data stucture that holds the prefix-uri information
151    //
152    // fNewNamespaceCount - the number of custom namespace declarations we have created
153    //
154    DOMDocumentImpl *fDocument;
155    DOMConfigurationImpl *fConfiguration;
156    DOMErrorHandler *fErrorHandler;
157    InScopeNamespaces *fNSScope;
158    unsigned int fNewNamespaceCount;
159    MemoryManager* fMemoryManager;
160};
161
162
163
164XERCES_CPP_NAMESPACE_END
165
166#endif
Note: See TracBrowser for help on using the repository browser.