Add cache file type to path resolver
[shibboleth/cpp-xmltooling.git] / xmltooling / QName.cpp
1 /**
2  * Licensed to the University Corporation for Advanced Internet
3  * Development, Inc. (UCAID) under one or more contributor license
4  * agreements. See the NOTICE file distributed with this work for
5  * additional information regarding copyright ownership.
6  *
7  * UCAID licenses this file to you under the Apache License,
8  * Version 2.0 (the "License"); you may not use this file except
9  * in compliance with the License. You may obtain a copy of the
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17  * either express or implied. See the License for the specific
18  * language governing permissions and limitations under the License.
19  */
20
21 /**
22  * QName.cpp
23  * 
24  * Representing XML QNames 
25  */
26
27 #include "internal.h"
28 #include "QName.h"
29
30 using namespace xmltooling;
31 using namespace std;
32
33 using xercesc::XMLString;
34
35 QName::QName(const XMLCh* uri, const XMLCh* localPart, const XMLCh* prefix)
36 {
37     setNamespaceURI(uri);
38     setLocalPart(localPart);
39     setPrefix(prefix);
40 }
41
42 QName::QName(const char* uri, const char* localPart, const char* prefix)
43 {
44     setNamespaceURI(uri);
45     setLocalPart(localPart);
46     setPrefix(prefix);
47 }
48
49 QName::~QName()
50 {
51 }
52
53 void QName::setPrefix(const XMLCh* prefix)
54 {
55     if (prefix)
56         m_prefix=prefix;
57     else
58         m_prefix.erase();
59 }
60
61 void QName::setNamespaceURI(const XMLCh* uri)
62 {
63     if (uri)
64         m_uri=uri;
65     else
66         m_uri.erase();
67 }
68
69 void QName::setLocalPart(const XMLCh* localPart)
70 {
71     if (localPart)
72         m_local=localPart;
73     else
74         m_local.erase();
75 }
76
77 void QName::setPrefix(const char* prefix)
78 {
79     if (prefix) {
80         auto_ptr_XMLCh temp(prefix);
81         m_prefix=temp.get();
82     }
83     else
84         m_prefix.erase();
85 }
86
87 void QName::setNamespaceURI(const char* uri)
88 {
89     if (uri) {
90         auto_ptr_XMLCh temp(uri);
91         m_uri=temp.get();
92     }
93     else
94         m_uri.erase();
95 }
96
97 void QName::setLocalPart(const char* localPart)
98 {
99     if (localPart) {
100         auto_ptr_XMLCh temp(localPart);
101         m_local=temp.get();
102     }
103     else
104         m_local.erase();
105 }
106
107 bool xmltooling::operator==(const QName& op1, const QName& op2)
108 {
109     if (&op1 == &op2)
110         return true;
111     return (!XMLString::compareString(op1.getNamespaceURI(),op2.getNamespaceURI()) &&
112             !XMLString::compareString(op1.getLocalPart(),op2.getLocalPart()));
113 }
114
115 bool xmltooling::operator!=(const QName& op1, const QName& op2)
116 {
117     return !(op1==op2);
118 }
119
120 bool xmltooling::operator<(const QName& op1, const QName& op2)
121 {
122     int i=XMLString::compareString(op1.getNamespaceURI(),op2.getNamespaceURI());
123     if (i<0)
124         return true;
125     else if (i==0)
126         return (XMLString::compareString(op1.getLocalPart(),op2.getLocalPart())<0);
127     else
128         return false;
129 }
130
131 string QName::toString() const
132 {
133     if (!hasLocalPart())
134         return "";
135     auto_ptr_char local(getLocalPart());
136     if (hasPrefix()) {
137         auto_ptr_char pre(getPrefix());
138         return string(pre.get()) + ':' + local.get(); 
139     }
140     else if (hasNamespaceURI()) {
141         auto_ptr_char ns(getNamespaceURI());
142         return string("{") + ns.get() + '}' + local.get(); 
143     }
144     else
145         return local.get();
146 }