source: icXML/icXML-devel/src/xercesc/dom/impl/DOMImplementationImpl.cpp @ 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.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: DOMImplementationImpl.cpp 671894 2008-06-26 13:29:21Z borisk $
20 */
21
22#include "DOMImplementationImpl.hpp"
23#include "DOMDocumentImpl.hpp"
24#include "DOMDocumentTypeImpl.hpp"
25#include "DOMLSSerializerImpl.hpp"
26#include "DOMLSInputImpl.hpp"
27#include "DOMLSOutputImpl.hpp"
28#include "DOMImplementationListImpl.hpp"
29
30#include <xercesc/dom/DOMDocument.hpp>
31#include <xercesc/dom/DOMDocumentType.hpp>
32#include <xercesc/dom/DOMException.hpp>
33#include <icxercesc/util/PlatformUtils.hpp>
34#include <xercesc/util/XMLInitializer.hpp>
35#include <xercesc/util/XMLUniDefs.hpp>
36#include <xercesc/util/XMLChar.hpp>
37#include <xercesc/util/XMLStringTokenizer.hpp>
38#include <xercesc/util/XMLDOMMsg.hpp>
39#include <xercesc/util/XMLMsgLoader.hpp>
40#include <xercesc/parsers/DOMLSParserImpl.hpp>
41
42XERCES_CPP_NAMESPACE_BEGIN
43
44
45// ------------------------------------------------------------
46//  Static constants
47// ------------------------------------------------------------
48static const XMLCh  g1_0[] =     // Points to "1.0"
49        {chDigit_1, chPeriod, chDigit_0, chNull};
50static const XMLCh  g2_0[] =      // Points to "2.0"
51        {chDigit_2, chPeriod, chDigit_0, chNull};
52static const XMLCh  g3_0[] =      // Points to "3.0"
53        {chDigit_3, chPeriod, chDigit_0, chNull};
54static const XMLCh  gTrav[] =     // Points to "Traversal"
55        {chLatin_T, chLatin_r, chLatin_a, chLatin_v, chLatin_e, chLatin_r,
56            chLatin_s, chLatin_a, chLatin_l, chNull};
57static const XMLCh  gCore[] =     // Points to "Core"
58        {chLatin_C, chLatin_o, chLatin_r, chLatin_e, chNull};
59static const XMLCh  gRange[] =     // Points to "Range"
60        {chLatin_R, chLatin_a, chLatin_n, chLatin_g, chLatin_e, chNull};
61static const XMLCh  gLS[] =     // Points to "LS"
62        {chLatin_L, chLatin_S, chNull};
63static const XMLCh  gXPath[] =     // Points to "XPath"
64        {chLatin_X, chLatin_P, chLatin_a, chLatin_t, chLatin_h, chNull};
65
66
67static XMLMsgLoader *sMsgLoader = 0;
68static DOMImplementationImpl *gDomimp = 0;
69
70void XMLInitializer::initializeDOMImplementationImpl()
71{
72    sMsgLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgXMLDOMMsgDomain);
73
74    if (!sMsgLoader)
75      XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain);
76
77    gDomimp = new DOMImplementationImpl;
78}
79
80void XMLInitializer::terminateDOMImplementationImpl()
81{
82    delete gDomimp;
83    gDomimp = 0;
84
85    delete sMsgLoader;
86    sMsgLoader = 0;
87}
88
89//
90//
91XMLMsgLoader* DOMImplementationImpl::getMsgLoader4DOM()
92{
93    return sMsgLoader;
94}
95
96DOMImplementationImpl *DOMImplementationImpl::getDOMImplementationImpl()
97{
98    return gDomimp;
99}
100
101// ------------------------------------------------------------
102// DOMImplementation Virtual interface
103// ------------------------------------------------------------
104bool  DOMImplementationImpl::hasFeature(const  XMLCh * feature,  const  XMLCh * version) const
105{
106    if (!feature)
107        return false;
108
109    // ignore the + modifier
110    if(*feature==chPlus)
111        feature++;
112
113    bool anyVersion = (version == 0 || !*version);
114    bool version1_0 = XMLString::equals(version, g1_0);
115    bool version2_0 = XMLString::equals(version, g2_0);
116    bool version3_0 = XMLString::equals(version, g3_0);
117
118    // Currently, we support only XML Level 1 version 1.0
119    if (XMLString::compareIStringASCII(feature, XMLUni::fgXMLString) == 0
120        && (anyVersion || version1_0 || version2_0))
121        return true;
122
123    if (XMLString::compareIStringASCII(feature, gCore) == 0
124        && (anyVersion || version1_0 || version2_0 || version3_0))
125        return true;
126
127    if (XMLString::compareIStringASCII(feature, gTrav) == 0
128        && (anyVersion || version2_0))
129        return true;
130
131    if (XMLString::compareIStringASCII(feature, gRange) == 0
132        && (anyVersion || version2_0))
133        return true;
134
135    if (XMLString::compareIStringASCII(feature, gLS) == 0
136        && (anyVersion || version3_0))
137        return true;
138
139    if (XMLString::compareIStringASCII(feature, gXPath) == 0
140        && (anyVersion || version3_0))
141        return true;
142
143    return false;
144}
145
146
147//Introduced in DOM Level 2
148DOMDocumentType *DOMImplementationImpl::createDocumentType(const XMLCh *qualifiedName,
149        const XMLCh * publicId, const XMLCh *systemId)
150{
151    // assume XML 1.0 since we do not know its version yet.
152    if(!XMLChar1_0::isValidName(qualifiedName))
153        throw DOMException(DOMException::INVALID_CHARACTER_ERR, 0);
154
155    //to do: do we need to create with user's memorymanager???
156    DOMDocumentTypeImpl* docType = new DOMDocumentTypeImpl(0, qualifiedName, publicId, systemId, true);
157    return docType;
158}
159
160DOMDocument *DOMImplementationImpl::createDocument(const XMLCh *namespaceURI,
161        const XMLCh *qualifiedName, DOMDocumentType *doctype,
162    MemoryManager* const manager)
163{
164    return new (manager) DOMDocumentImpl(namespaceURI, qualifiedName, doctype, this, manager);
165}
166
167
168//Introduced in DOM Level 3
169void* DOMImplementationImpl::getFeature(const XMLCh*, const XMLCh*) const {
170    return 0;
171}
172
173// Non-standard extension
174DOMDocument *DOMImplementationImpl::createDocument(MemoryManager* const manager)
175{
176        return new (manager) DOMDocumentImpl(this, manager);
177}
178
179//
180//  DOMImplementation::getImplementation.  DOMImplementation is supposed to
181//                                              be a pure interface class.  This one static
182//                                              function is the hook that lets things get started.
183DOMImplementation *DOMImplementation::getImplementation()
184{
185    return (DOMImplementation*) DOMImplementationImpl::getDOMImplementationImpl();
186}
187
188bool DOMImplementation::loadDOMExceptionMsg
189(
190      const short                        msgToLoad
191    ,       XMLCh* const                 toFill
192    , const XMLSize_t                    maxChars
193)
194{
195  // Figure out which exception range this code is and load the corresponding
196  // message.
197  //
198  if (msgToLoad <= 50)
199  {
200    // DOMException
201    return sMsgLoader->loadMsg(XMLDOMMsg::DOMEXCEPTION_ERRX+msgToLoad, toFill, maxChars);
202  }
203  else if (msgToLoad <= 80)
204  {
205    // DOMXPathException
206    return sMsgLoader->loadMsg(XMLDOMMsg::DOMXPATHEXCEPTION_ERRX+msgToLoad-DOMXPathException::INVALID_EXPRESSION_ERR+1, toFill, maxChars);
207  }
208  else if (msgToLoad <= 110)
209  {
210    // DOMXLSException
211    return sMsgLoader->loadMsg(XMLDOMMsg::DOMLSEXCEPTION_ERRX+msgToLoad-DOMLSException::PARSE_ERR+1, toFill, maxChars);
212  }
213  else
214  {
215    // DOMRangeException
216    return sMsgLoader->loadMsg(XMLDOMMsg::DOMRANGEEXCEPTION_ERRX+msgToLoad-DOMRangeException::BAD_BOUNDARYPOINTS_ERR+1, toFill, maxChars);
217  }
218}
219
220// ------------------------------------------------------------
221// DOMImplementationLS Virtual interface
222// ------------------------------------------------------------
223//Introduced in DOM Level 3
224DOMLSParser* DOMImplementationImpl::createLSParser( const DOMImplementationLSMode   mode,
225                                                    const XMLCh* const     /*schemaType*/,
226                                                    MemoryManager* const  manager,
227                                                    XMLGrammarPool* const gramPool)
228{
229    if (mode == DOMImplementationLS::MODE_ASYNCHRONOUS)
230        throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, manager);
231
232    // TODO: schemaType
233    return new (manager) DOMLSParserImpl(0, manager, gramPool);
234}
235
236
237DOMLSSerializer* DOMImplementationImpl::createLSSerializer(MemoryManager* const manager)
238{
239    return new (manager) DOMLSSerializerImpl(manager);
240}
241
242DOMLSInput* DOMImplementationImpl::createLSInput(MemoryManager* const manager)
243{
244    return new (manager) DOMLSInputImpl(manager);
245}
246
247DOMLSOutput* DOMImplementationImpl::createLSOutput(MemoryManager* const manager)
248{
249    return new (manager) DOMLSOutputImpl(manager);
250}
251
252// ------------------------------------------------------------
253// DOMImplementationSource Virtual interface
254// ------------------------------------------------------------
255DOMImplementation* DOMImplementationImpl::getDOMImplementation(const XMLCh* features) const
256{
257    DOMImplementation* impl = DOMImplementation::getImplementation();
258
259    XMLStringTokenizer tokenizer(features, XMLPlatformUtils::fgMemoryManager);
260    const XMLCh* feature = 0;
261
262    while (feature || tokenizer.hasMoreTokens()) {
263
264        if (!feature)
265            feature = tokenizer.nextToken();
266
267        const XMLCh* version = 0;
268        const XMLCh* token = tokenizer.nextToken();
269
270        if (token && XMLString::isDigit(token[0]))
271            version = token;
272
273        if (!impl->hasFeature(feature, version))
274            return 0;
275
276        if (!version)
277            feature = token;
278    }
279    return impl;
280}
281
282DOMImplementationList* DOMImplementationImpl::getDOMImplementationList(const XMLCh* features) const
283{
284    DOMImplementationListImpl* list = new DOMImplementationListImpl;
285    DOMImplementation* myImpl=getDOMImplementation(features);
286    if(myImpl)
287        list->add(myImpl);
288    return list;
289}
290
291XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.