/*
- * Copyright 2001-2006 Internet2
+ * Copyright 2001-2007 Internet2
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
{
for (map<string,pair<char*,const XMLCh*> >::iterator i=m_map.begin(); i!=m_map.end(); i++)
XMLString::release(&(i->second.first));
- for_each(m_nested.begin(),m_nested.end(),xmltooling::cleanup_pair<string,DOMPropertySet>());
+ for_each(m_nested.begin(),m_nested.end(),cleanup_pair<string,DOMPropertySet>());
}
void DOMPropertySet::load(
auto_ptr_char ns(a->getNamespaceURI());
auto_ptr_char name(a->getLocalName());
const char* realname=name.get();
+ map<string,string>::const_iterator remap;
if (remapper) {
- map<string,string>::const_iterator remap=remapper->find(realname);
+ remap=remapper->find(realname);
if (remap!=remapper->end()) {
log.warn("remapping property (%s) to (%s)",realname,remap->second.c_str());
realname=remap->second.c_str();
}
}
if (ns.get()) {
- m_map[string("{") + ns.get() + '}' + realname]=pair<char*,const XMLCh*>(val,a->getNodeValue());
+ if (remapper && (remap=remapper->find(ns.get()))!=remapper->end())
+ m_map[string("{") + remap->second.c_str() + '}' + realname]=pair<char*,const XMLCh*>(val,a->getNodeValue());
+ else
+ m_map[string("{") + ns.get() + '}' + realname]=pair<char*,const XMLCh*>(val,a->getNodeValue());
log.debug("added property {%s}%s (%s)",ns.get(),realname,val);
}
else {
auto_ptr_char ns(e->getNamespaceURI());
auto_ptr_char name(e->getLocalName());
const char* realname=name.get();
+ map<string,string>::const_iterator remap;
if (remapper) {
- map<string,string>::const_iterator remap=remapper->find(realname);
+ remap=remapper->find(realname);
if (remap!=remapper->end()) {
log.warn("remapping property set (%s) to (%s)",realname,remap->second.c_str());
realname=remap->second.c_str();
}
}
string key;
- if (ns.get())
- key=string("{") + ns.get() + '}' + realname;
+ if (ns.get()) {
+ if (remapper && (remap=remapper->find(ns.get()))!=remapper->end())
+ key=string("{") + remap->second.c_str() + '}' + realname;
+ else
+ key=string("{") + ns.get() + '}' + realname;
+ }
else
key=realname;
if (m_nested.find(key)!=m_nested.end())
pair<bool,bool> DOMPropertySet::getBool(const char* name, const char* ns) const
{
- pair<bool,bool> ret(false,false);
map<string,pair<char*,const XMLCh*> >::const_iterator i;
if (ns)
else
i=m_map.find(name);
- if (i!=m_map.end()) {
- ret.first=true;
- ret.second=(!strcmp(i->second.first,"true") || !strcmp(i->second.first,"1"));
- }
- return ret;
+ if (i!=m_map.end())
+ return make_pair(true,(!strcmp(i->second.first,"true") || !strcmp(i->second.first,"1")));
+ else if (m_parent)
+ return m_parent->getBool(name,ns);
+ return make_pair(false,false);
}
pair<bool,const char*> DOMPropertySet::getString(const char* name, const char* ns) const
else
i=m_map.find(name);
- if (i!=m_map.end()) {
- ret.first=true;
- ret.second=i->second.first;
- }
- return ret;
+ if (i!=m_map.end())
+ return make_pair(true,i->second.first);
+ else if (m_parent)
+ return m_parent->getString(name,ns);
+ return pair<bool,const char*>(false,NULL);
}
pair<bool,const XMLCh*> DOMPropertySet::getXMLString(const char* name, const char* ns) const
{
- pair<bool,const XMLCh*> ret(false,NULL);
map<string,pair<char*,const XMLCh*> >::const_iterator i;
if (ns)
else
i=m_map.find(name);
- if (i!=m_map.end()) {
- ret.first=true;
- ret.second=i->second.second;
- }
- return ret;
+ if (i!=m_map.end())
+ return make_pair(true,i->second.second);
+ else if (m_parent)
+ return m_parent->getXMLString(name,ns);
+ return pair<bool,const XMLCh*>(false,NULL);
}
pair<bool,unsigned int> DOMPropertySet::getUnsignedInt(const char* name, const char* ns) const
{
- pair<bool,unsigned int> ret(false,0);
map<string,pair<char*,const XMLCh*> >::const_iterator i;
if (ns)
else
i=m_map.find(name);
- if (i!=m_map.end()) {
- ret.first=true;
- ret.second=strtol(i->second.first,NULL,10);
- }
- return ret;
+ if (i!=m_map.end())
+ return pair<bool,unsigned int>(true,strtol(i->second.first,NULL,10));
+ else if (m_parent)
+ return m_parent->getUnsignedInt(name,ns);
+ return pair<bool,unsigned int>(false,0);
}
pair<bool,int> DOMPropertySet::getInt(const char* name, const char* ns) const
{
- pair<bool,int> ret(false,0);
map<string,pair<char*,const XMLCh*> >::const_iterator i;
if (ns)
else
i=m_map.find(name);
- if (i!=m_map.end()) {
- ret.first=true;
- ret.second=atoi(i->second.first);
- }
- return ret;
+ if (i!=m_map.end())
+ return pair<bool,int>(true,atoi(i->second.first));
+ else if (m_parent)
+ return m_parent->getInt(name,ns);
+ return pair<bool,int>(false,0);
}
const PropertySet* DOMPropertySet::getPropertySet(const char* name, const char* ns) const
else
i=m_nested.find(name);
- return (i!=m_nested.end()) ? i->second : NULL;
+ return (i!=m_nested.end()) ? i->second : (m_parent ? m_parent->getPropertySet(name,ns) : NULL);
}