source: icXML/icXML-devel/src/xercesc/dom/impl/DOMXPathNSResolverImpl.cpp @ 2777

Last change on this file since 2777 was 2777, checked in by cameron, 7 years ago

Set up to use xercesc/icxercesc root-relative paths for all includes

File size: 3.2 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#include <xercesc/dom/impl/DOMXPathNSResolverImpl.hpp>
19#include <xercesc/dom/DOMNode.hpp>
20#include <icxercesc/util/XMLString.hpp>
21#include <xercesc/util/Janitor.hpp>
22#include <icxercesc/util/XMLString.hpp>
23
24XERCES_CPP_NAMESPACE_BEGIN
25
26DOMXPathNSResolverImpl::DOMXPathNSResolverImpl(const DOMNode *nodeResolver, MemoryManager* const manager) :
27    fNamespaceBindings(0),
28    fResolverNode(nodeResolver),
29    fManager(manager)
30{
31    fNamespaceBindings = new (fManager) RefHashTableOf<KVStringPair>(7, true, fManager);
32}
33
34DOMXPathNSResolverImpl::~DOMXPathNSResolverImpl()
35{
36    delete fNamespaceBindings;
37}
38
39const XMLCh* DOMXPathNSResolverImpl::lookupNamespaceURI(const XMLCh* prefix) const
40{
41    if(prefix == 0) prefix = XMLUni::fgZeroLenString;
42
43    if(XMLString::equals(prefix, XMLUni::fgXMLString))
44        return XMLUni::fgXMLURIName;
45
46    const KVStringPair *pair = fNamespaceBindings->get((void*)prefix);
47    if(pair) {
48
49        // An empty namespace URI indicated that this binding was removed
50        // by the user.
51        //
52        if(*pair->getValue() == 0) return NULL;
53
54        return pair->getValue();
55    }
56
57    if(fResolverNode)
58      return fResolverNode->lookupNamespaceURI(
59        *prefix == 0 ? 0 : prefix); // Expects 0 for default namespace.
60
61    return NULL;
62}
63
64const XMLCh* DOMXPathNSResolverImpl::lookupPrefix(const XMLCh* uri) const
65{
66    if (uri == 0 || *uri == 0)
67        return 0;
68
69    if(XMLString::equals(uri, XMLUni::fgXMLURIName))
70        return XMLUni::fgXMLString;
71
72    RefHashTableOfEnumerator<KVStringPair> enumerator((RefHashTableOf<KVStringPair>*)fNamespaceBindings);
73    while(enumerator.hasMoreElements()) {
74        KVStringPair &pair = enumerator.nextElement();
75        if(XMLString::equals(pair.getValue(), uri)) {
76            return pair.getKey();
77        }
78    }
79
80    if(fResolverNode)
81    {
82      const XMLCh* r = fResolverNode->lookupPrefix(uri);
83
84      if (r == 0 && fResolverNode->isDefaultNamespace(uri))
85        r = XMLUni::fgZeroLenString;
86
87      return r;
88    }
89
90    return 0;
91}
92
93void DOMXPathNSResolverImpl::addNamespaceBinding(const XMLCh* prefix, const XMLCh* uri)
94{
95    if(prefix == 0) prefix = XMLUni::fgZeroLenString;
96    if(uri == 0) uri = XMLUni::fgZeroLenString;
97
98    KVStringPair* pair = new (fManager) KVStringPair(prefix, uri, fManager);
99
100    fNamespaceBindings->put((void*)pair->getKey(), pair);
101}
102
103void DOMXPathNSResolverImpl::release()
104{
105    DOMXPathNSResolverImpl* me=(DOMXPathNSResolverImpl*)this;
106    delete me;
107}
108
109XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.