Change license header.
[shibboleth/cpp-sp.git] / shibsp / util / DOMPropertySet.h
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  * @file shibsp/util/DOMPropertySet.h
23  * 
24  * DOM-based property set implementation.
25  */
26
27 #ifndef __shibsp_dompropset_h__
28 #define __shibsp_dompropset_h__
29
30 #include <shibsp/util/PropertySet.h>
31
32 #include <xmltooling/logging.h>
33
34 namespace shibsp {
35
36     /**
37      * DOM-based property set implementation.
38      */
39     class SHIBSP_API DOMPropertySet : public virtual PropertySet
40     {
41     public:
42         DOMPropertySet();
43         
44         virtual ~DOMPropertySet();
45
46         const PropertySet* getParent() const;
47         void setParent(const PropertySet* parent);
48         std::pair<bool,bool> getBool(const char* name, const char* ns=nullptr) const;
49         std::pair<bool,const char*> getString(const char* name, const char* ns=nullptr) const;
50         std::pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=nullptr) const;
51         std::pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=nullptr) const;
52         std::pair<bool,int> getInt(const char* name, const char* ns=nullptr) const;
53         void getAll(std::map<std::string,const char*>& properties) const;
54         const PropertySet* getPropertySet(const char* name, const char* ns=shibspconstants::ASCII_SHIB2SPCONFIG_NS) const;
55         const xercesc::DOMElement* getElement() const;
56
57         /**
58          * Loads the property set from a DOM element.
59          * 
60          * @param e         root element of property set
61          * @param log       optional log object for tracing
62          * @param filter    optional filter controls what child elements to include as nested PropertySets
63          * @param remapper  optional map of property rename rules for legacy property support
64          */
65         void load(
66             const xercesc::DOMElement* e,
67             xmltooling::logging::Category* log=nullptr,
68             xercesc::DOMNodeFilter* filter=nullptr,
69             const std::map<std::string,std::string>* remapper=nullptr
70             );
71
72     protected:
73         /**
74          * Post-load injection of a property, for use by subclasses.
75          *
76          * @param name  property name
77          * @param val   property value
78          * @param ns    property namespace
79          * @return  true iff the property was successfully set
80          */
81         bool setProperty(const char* name, const char* val, const char* ns=nullptr);
82
83     private:
84         const PropertySet* m_parent;
85         const xercesc::DOMElement* m_root;
86         std::map<std::string,std::pair<char*,const XMLCh*> > m_map;
87         std::map<std::string,DOMPropertySet*> m_nested;
88         std::vector<xmltooling::xstring> m_injected;
89     };
90
91 };
92
93 #endif /* __shibsp_dompropset_h__ */