1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * As a special exception, you may use this file as part of a free
8  * software library without restriction. Specifically, if other files
9  * instantiate templates or use macros or inline functions from this
10  * file, or you compile this file and link it with other files to
11  * produce an executable, this file does not by itself cause the
12  * resulting executable to be covered by the GNU General Public
13  * License. This exception does not however invalidate any other
14  * reasons why the executable file might be covered by the GNU Library
15  * General Public License.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with this library; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
25  */
26 #ifndef cxxtools_Xml_Namespace_h
27 #define cxxtools_Xml_Namespace_h
28 
29 #include <cxxtools/xml/api.h>
30 #include <cxxtools/string.h>
31 
32 #include <iosfwd>
33 
34 namespace cxxtools {
35 
36 namespace xml {
37 
38     /**
39      * @brief A Namespace element (Node) of an XML document.
40      *
41      * A namespace element stores a namespace uri which describes the namespace URI and a locally
42      * usable prefix which can be added before a tag name to specify that this particular tag
43      * is part of that namespace.
44      *
45      * Use namespaceUri() to get the namespace URI. Use prefix() to get the prefix.
46      *
47      * @see Node
48      * @see NamespaceContext
49      */
50     class CXXTOOLS_XML_API Namespace {
51         public:
52             /**
53              * @brief Constructs a new Namespace object with the given namespace URI and prefix.
54              *
55              * @param namespaceURI The unique URI of this namespace.
56              * @param prefix The namespace prefix which can be added to a tag name to specify that
57              * this tag belongs to that namespace.
58              */
Namespace(const String & namespaceUri,const String & prefix)59             Namespace(const String& namespaceUri, const String& prefix)
60             : _prefix(prefix), _namespaceUri(namespaceUri)
61             { }
62 
63             /**
64              * @brief Returns the prefix of this namespace.
65              *
66              * The namespace prefix can be added to a tag name to specify that this tag belongs
67              * to that namespace.
68              *
69              * @return The namespace prefix of this Namespace object.
70              */
prefix()71             const String& prefix() const
72             { return _prefix; }
73 
74             /**
75              * @brief Sets the prefix of this namespace.
76              *
77              * The namespace prefix can be added to a tag name to specify that this tag belongs
78              * to that namespace.
79              *
80              * @param prefix The namespace prefix for this Namespace object.
81              */
setPrefix(const String & prefix)82             void setPrefix(const String& prefix)
83             { _prefix = prefix; }
84 
85             /**
86              * @brief Returns the URI of this namespace.
87              *
88              * The URI is unique and identifies the namespace.
89              *
90              * @return The namespace URI of this Namespace object.
91              */
namespaceUri()92             const String& namespaceUri() const
93             { return _namespaceUri; }
94 
95             /**
96              * @brief Sets the URI of this namespace.
97              *
98              * The URI is unique and identifies the namespace.
99              *
100              * @param namespaceUri The namespace URI for this Namespace object.
101              */
setNamespaceUri(const String & namespaceUri)102             void setNamespaceUri(const String& namespaceUri)
103             { _namespaceUri = namespaceUri; }
104 
105             /**
106              * @brief Returns $true$ if this is the default namespace in the current XML document. Otherwise
107              * $false$ is returned.
108              *
109              * @return $true$ if this is the default namespace; $false$ otherwise.
110              */
111             bool isDefaultNamespaceDeclaration();
112 
113         private:
114             //! The prefix of this namespace.
115             String _prefix;
116 
117             //! The namespace URI of this namespace.
118             String _namespaceUri;
119     };
120 
121 }
122 
123 }
124 
125 #endif
126