source: icXML/icXML-devel/src/xercesc/xinclude/XIncludeUtils.hpp @ 2722

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

Original Xerces files with import mods for icxercesc

File size: 9.9 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: XIncludeUtils.hpp 673949 2008-07-04 08:04:44Z borisk $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_XINCLUDEUTILS_HPP)
23#define XERCESC_INCLUDE_GUARD_XINCLUDEUTILS_HPP
24
25#include <xercesc/util/XercesDefs.hpp>
26#include <xercesc/util/XMLException.hpp>
27#include <xercesc/dom/DOMNode.hpp>
28#include <xercesc/dom/DOMDocument.hpp>
29#include <xercesc/dom/DOMErrorHandler.hpp>
30#include <icxercesc/framework/XMLElementDecl.hpp>
31#include <xercesc/xinclude/XIncludeLocation.hpp>
32#include <xercesc/framework/XMLErrorCodes.hpp>
33
34XERCES_CPP_NAMESPACE_BEGIN
35
36class XMLEntityHandler;
37
38typedef struct XIncludeHistoryNode{
39    XMLCh *URI;
40    struct XIncludeHistoryNode *next;
41}XIncludeHistoryNode;
42
43/**
44  * Class implementing all the utility functions required by an XInclude parser.
45  *
46  * This class is designed primarily for internal use. This class implements
47  * utility methods to be called by an XInclude parser. It is intended to encapsulate
48  * the actual processing and recognition of XInclude components.
49  */
50class XINCLUDE_EXPORT XIncludeUtils
51{
52private:
53
54    /** Constructor
55     *
56     */
57    XIncludeUtils(XMLErrorReporter *errorReporter);
58
59    /** Destructor
60     *
61     */
62    ~XIncludeUtils();
63
64     /** Parse the supplied XInclude element performing relevant XInclude functionality
65      *
66      * @param xincludeNode The XInclude node to parse and action
67      * @param parsedDocument The DOMDocument to which the results of the XInclude are to be added
68      *
69      * @return true if the XInclude processing was successful, false if not. Note that an
70      * XInclude that fails resulting in a successful fallback action would return true.
71      */
72    bool doDOMNodeXInclude(DOMNode *xincludeNode, DOMDocument *parsedDocument, XMLEntityHandler* entityResolver);
73
74     /** Parse an XInclude xml file into a DOMDocument node.
75      *
76      * @param href the location of the document to include
77      * @param relativeHref
78      * @param parsedDocument
79      *
80      * @return a newly created DOMDocument containing the parsed and actioned
81      * href, or NULL if the document could not be loaded.
82      */
83    DOMDocument *doXIncludeXMLFileDOM(const XMLCh *href,
84        const XMLCh *relativeHref,
85        DOMNode *xincludeNode,
86        DOMDocument *parsedDocument,
87        XMLEntityHandler* entityResolver);
88
89     /** Parse an XInclude text file into a DOMText node.
90      *
91      * @param href the location of the document to include
92      * @param relativeHref
93      * @param encoding
94      * @param parsedDocument
95      *
96      * @return a newly created DOMText containing the parsed and actioned
97      * href, or NULL if the document could not be loaded.
98      */
99    DOMText *doXIncludeTEXTFileDOM(const XMLCh *href,
100        const XMLCh *relativeHref,
101        const XMLCh *encoding,
102        DOMNode *xincludeNode,
103        DOMDocument *parsedDocument,
104        XMLEntityHandler* entityResolver);
105
106     /** Detect whether the supplied details are correct for an xi:include element
107      *
108      * @param name the element name
109      * @param namespaceURI the element namespace
110      *
111      * @return true if details are valid for an xi:include element, false
112      * if not.
113      */
114    static bool isXIIncludeElement(const XMLCh *name, const XMLCh *namespaceURI);
115
116     /** Detect whether the supplied details are correct for an xi:fallback element
117      *
118      * @param name the element name
119      * @param namespaceURI the element namespace
120      *
121      * @return true if details are valid for an xi:fallback element, false
122      * if not.
123      */
124    static bool isXIFallbackElement(const XMLCh *name, const XMLCh *namespaceURI);
125
126     /** Detect whether the supplied DOMNode is an xi:include element
127      *
128      * @param node The node to check
129      *
130      * @return true if node is an xi:include element, false
131      * if not.
132      */
133    static bool isXIIncludeDOMNode(DOMNode *node);
134
135     /** Detect whether the supplied DOMNode is an xi:fallback element
136      *
137      * @param node The DOMNode to check
138      *
139      * @return true if node is an xi:fallback element, false
140      * if not.
141      */
142    static bool isXIFallbackDOMNode(DOMNode *node);
143
144     /** Walk the content of the supplied source node, performing any xinclude actions
145      * that are encountered.
146      *
147      * @param source A DOMNode to parse, this node may be modified by the method
148      * @param parsedDocument the DOMDocument to which the parsed results are to be copied.
149      *
150      * @return true if XInclude behaviour was successfully performed on source, false if not.
151      */
152    bool parseDOMNodeDoingXInclude(DOMNode *source, DOMDocument *parsedDocument, XMLEntityHandler* entityResolver);
153
154     /** Parse the supplied URI and escape all characters as specified by
155      * the XINclusions specification.
156      *
157      * @param hrefAttrValue the href to parse and escape.
158      * @param needsDeallocating set to true if the return value needs deallocating
159      * by the caller after use, false if the value returned is the same as the
160      * hrefAttrValue passed in.
161      *
162      * @return an escaped version of hrefAttrValue or hrefAttrValue itself if
163      * hrefAttrValue contains only valid characters.
164      */
165    /* 4.1.1 */
166    const XMLCh *getEscapedHRefAttrValue(const XMLCh *hrefAttrValue, bool &needsDeallocating);
167
168     /** Set the accept and accept-lang parameters on HTTP requests generated while
169      * XIncluding.
170      *
171      * @param acceptAttrValue
172      * @param acceptLangAttrValue
173      *
174      * @return true if the values were successfully added to the HTTP request, false
175      * if not.
176      */
177    /* 4.1.2 */
178    bool setContentNegotiation(const XMLCh *acceptAttrValue, const XMLCh *acceptLangAttrValue);
179
180     /** Check the characters passed in are all valid characters for XInclusion
181      * as specified at http://www.w3.org/TR/xinclude/#text-included-items
182      *
183      * @param includeChars the characters to parse for validity
184      *
185      * @return true if the includeChars parameter contains only valid characters
186      * for inclusion, false if there are invalid characters in includeChars.
187      */
188    bool checkTextIsValidForInclude(XMLCh *includeChars);
189
190     /** Add the supplied parameter to the InclusionHistoryStack
191      *
192      * @param URItoAdd the URI to add to the InclusionHistoryStack/
193      *
194      * @return true if the URI was added, false if a problem prevented
195      * the URI being added.
196      */
197    bool addDocumentURIToCurrentInclusionHistoryStack(const XMLCh *URItoAdd);
198
199     /** Check the XInclude InclusionHistoryStack to see if the supplied URI
200      * has already been included. This is used to ensure that circular inclusion
201      * chains are detected and that the inclusion mechanism does not get stuck in
202      * a loop.
203      *
204      * @param toFind the URI to look up.
205      *
206      * @return true if the toFind parameter is found in the InclusionHistortStack,
207      * false if the parameter is not in the stack or the stack is empty.
208      */
209    bool isInCurrentInclusionHistoryStack(const XMLCh *toFind);
210
211     /** Pop (i.e. remove and return) the top value from the InclusionHistoryStack
212      *
213      * @param toPop the value that is expected to be at the top of the stack, or
214      * NULL if no checking is required.
215      *
216      * @return the element at the top of the stack
217      */
218    XIncludeHistoryNode * popFromCurrentInclusionHistoryStack(const XMLCh *toPop);
219
220     /** Free the internal inclusion history list.
221      *
222      * @return nothing
223      */
224    void freeInclusionHistory();
225
226     /** Construct and pass on an error description
227      *
228      * @param errorNode The DOMNode that was being parsed when the error occurred
229      * @param errorType The severity of the error
230      * @param errorMsg An optional message to include in the error report
231      * @param href The URI of the document being parsed.
232      *
233      * @return true if the errorHandler requests continuation of parsing despite error
234      * false if the errorHandler requests parsing end on encountering error, or it
235      * there is no error handler.
236      */
237    bool reportError(const DOMNode* const errorNode
238                     , XMLErrs::Codes errorType
239                     , const XMLCh* const errorMsg
240                     , const XMLCh*    const href);
241
242public:
243    /* temporarily public to facilitate helper func getBaseAttrValue */
244    static const XMLCh fgXIBaseAttrName[];
245private:
246    XIncludeHistoryNode *fIncludeHistoryHead;
247    XMLSize_t fErrorCount;
248    XMLErrorReporter *fErrorReporter;
249    static const XMLCh fgXIIncludeQName[];
250    static const XMLCh fgXIFallbackQName[];
251    static const XMLCh fgXIIncludeHREFAttrName[];
252    static const XMLCh fgXIIncludeParseAttrName[];
253    static const XMLCh fgXIIncludeParseAttrXMLValue[];
254    static const XMLCh fgXIIncludeParseAttrTextValue[];
255    static const XMLCh fgXIIncludeXPointerAttrName[];
256    static const XMLCh fgXIIncludeEncodingAttrName[];
257    static const XMLCh fgXIIncludeAcceptAttrName[];
258    static const XMLCh fgXIIncludeAcceptLanguageAttrName[];
259    static const XMLCh fgXIIIncludeNamespaceURI[];
260
261    friend class XIncludeDOMDocumentProcessor;
262    friend class AbstractDOMParser;
263};
264
265XERCES_CPP_NAMESPACE_END
266
267#endif
Note: See TracBrowser for help on using the repository browser.