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