ebb942f8531d12750dc80eda584308d4191e2429
[shibboleth/cpp-xmltooling.git] / xmltooling / Namespace.cpp
1 /*
2  *  Copyright 2001-2009 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * Namespace.cpp
19  * 
20  * Representing XML namespace attributes 
21  */
22
23 #include "internal.h"
24 #include "Namespace.h"
25
26 using namespace xmltooling;
27
28 using xercesc::XMLString;
29
30 Namespace::Namespace(const XMLCh* uri, const XMLCh* prefix, bool alwaysDeclare) : m_pinned(alwaysDeclare)
31 {
32     setNamespaceURI(uri);
33     setNamespacePrefix(prefix);
34 }
35
36 Namespace::~Namespace()
37 {
38 }
39
40 void Namespace::setNamespacePrefix(const XMLCh* prefix)
41 {
42     if (prefix)
43         m_prefix=prefix;
44     else
45         m_prefix.erase();
46 }
47
48 void Namespace::setNamespaceURI(const XMLCh* uri)
49 {
50     if (uri)
51         m_uri=uri;
52     else
53         m_uri.erase();
54 }
55
56 bool xmltooling::operator<(const Namespace& op1, const Namespace& op2)
57 {
58     int i=XMLString::compareString(op1.getNamespaceURI(),op2.getNamespaceURI());
59     if (i<0)
60         return true;
61     else if (i==0)
62         return (XMLString::compareString(op1.getNamespacePrefix(),op2.getNamespacePrefix())<0);
63     else
64         return false;
65 }
66
67 bool xmltooling::operator==(const Namespace& op1, const Namespace& op2)
68 {
69     return (XMLString::equals(op1.getNamespacePrefix(), op2.getNamespacePrefix()) &&
70             XMLString::equals(op1.getNamespaceURI(), op2.getNamespaceURI()));
71 }