/*
- * Copyright 2001-2009 Internet2
+ * Copyright 2001-2010 Internet2
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
{
}
-DOMPropertySet::DOMPropertySet() : m_parent(NULL), m_root(NULL)
+DOMPropertySet::DOMPropertySet() : m_parent(nullptr), m_root(nullptr)
{
}
pair<bool,const char*> DOMPropertySet::getString(const char* name, const char* ns) const
{
- pair<bool,const char*> ret(false,NULL);
+ pair<bool,const char*> ret(false,nullptr);
map<string,pair<char*,const XMLCh*> >::const_iterator i;
if (ns)
return pair<bool,const char*>(true,i->second.first);
else if (m_parent)
return m_parent->getString(name,ns);
- return pair<bool,const char*>(false,NULL);
+ return pair<bool,const char*>(false,nullptr);
}
pair<bool,const XMLCh*> DOMPropertySet::getXMLString(const char* name, const char* ns) const
return make_pair(true,i->second.second);
else if (m_parent)
return m_parent->getXMLString(name,ns);
- return pair<bool,const XMLCh*>(false,NULL);
+ return pair<bool,const XMLCh*>(false,nullptr);
}
pair<bool,unsigned int> DOMPropertySet::getUnsignedInt(const char* name, const char* ns) const
i=m_map.find(name);
if (i!=m_map.end())
- return pair<bool,unsigned int>(true,strtol(i->second.first,NULL,10));
+ return pair<bool,unsigned int>(true,strtol(i->second.first,nullptr,10));
else if (m_parent)
return m_parent->getUnsignedInt(name,ns);
return pair<bool,unsigned int>(false,0);
else
i=m_nested.find(name);
- return (i!=m_nested.end()) ? i->second : (m_parent ? m_parent->getPropertySet(name,ns) : NULL);
+ return (i!=m_nested.end()) ? i->second : (m_parent ? m_parent->getPropertySet(name,ns) : nullptr);
+}
+
+bool DOMPropertySet::setProperty(const char* name, const char* val, const char* ns)
+{
+ string propname = ns ? (string("{") + ns + "}" + name) : name;
+
+ // Erase existing property.
+ if (m_map.count(propname) > 0) {
+ XMLString::release(&m_map[propname].first);
+ m_map.erase(propname);
+ }
+
+ char* dup = XMLString::replicate(val);
+ auto_ptr_XMLCh widedup(val);
+ m_injected.push_back(widedup.get());
+ m_map[propname] = make_pair(dup, m_injected.back().c_str());
+
+ return true;
}