Added replaceParams() to XML fragment, document, element and text.

git-svn-id: http://voip.null.ro/svn/yate@6305 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2018-04-10 10:33:00 +00:00
parent 035a758980
commit 131f8ca07c
2 changed files with 65 additions and 0 deletions

View File

@ -1455,6 +1455,13 @@ XmlElement* XmlFragment::findElement(ObjList* list, const String* name, const St
return e;
}
// Replaces all ${paramname} in fragment's children with the corresponding parameters
void XmlFragment::replaceParams(const NamedList& params)
{
for (ObjList* o = m_list.skipNull(); o; o = o->skipNext())
static_cast<XmlChild*>(o->get())->replaceParams(params);
}
/*
* XmlDocument
@ -1663,6 +1670,15 @@ int XmlDocument::saveFile(const char* file, bool esc, const String& indent,
return f.error();
}
// Replaces all ${paramname} in document's components with the corresponding parameters
void XmlDocument::replaceParams(const NamedList& params)
{
if (m_root)
m_root->replaceParams(params);
m_beforeRoot.replaceParams(params);
m_afterRoot.replaceParams(params);
}
/*
* XmlChild
@ -1994,6 +2010,15 @@ bool XmlElement::setXmlns(const String& name, bool addAttr, const String& value)
return true;
}
// Replaces all ${paramname} in element's attributes and children with the
// corresponding parameters
void XmlElement::replaceParams(const NamedList& params)
{
m_children.replaceParams(params);
for (ObjList* o = m_element.paramList()->skipNull(); o; o = o->skipNext())
params.replaceParams(*static_cast<String*>(o->get()));
}
// Build an XML element from a list parameter
XmlElement* XmlElement::param2xml(NamedString* param, const String& tag, bool copyXml)
{
@ -2203,6 +2228,13 @@ bool XmlText::onlySpaces()
return true;
}
// Replaces all ${paramname} in text with the corresponding parameters
void XmlText::replaceParams(const NamedList& params)
{
params.replaceParams(m_text);
}
/*
* XmlDoctype
*/

View File

@ -777,6 +777,13 @@ public:
*/
virtual XmlDoctype* xmlDoctype()
{ return 0; }
/**
* Replaces all ${paramname} with the corresponding parameters
* @param params List of parameters
*/
virtual void replaceParams(const NamedList& params)
{}
};
@ -938,6 +945,12 @@ public:
const String& origIndent = String::empty(), bool completeOnly = true,
const String* auth = 0, const XmlElement* parent = 0) const;
/**
* Replaces all ${paramname} in fragment's children with the corresponding parameters
* @param params List of parameters
*/
void replaceParams(const NamedList& params);
/**
* Find a completed xml element in a list
* @param list The list to search for the element
@ -1086,6 +1099,12 @@ public:
void toString(String& dump, bool escape = true, const String& indent = String::empty(),
const String& origIndent = String::empty()) const;
/**
* Replaces all ${paramname} in document's components with the corresponding parameters
* @param params List of parameters
*/
void replaceParams(const NamedList& params);
private:
XmlElement* m_root; // The root element
XmlFragment m_beforeRoot; // XML children before root (declaration ...)
@ -1537,6 +1556,13 @@ public:
bool setXmlns(const String& name = String::empty(), bool addAttr = false,
const String& value = String::empty());
/**
* Replaces all ${paramname} in element's attributes and children with the
* corresponding parameters
* @param params List of parameters
*/
virtual void replaceParams(const NamedList& params);
/**
* Check if a string represents a namespace attribute name
* @param str The string to check
@ -1782,6 +1808,13 @@ public:
* @return False if the text contains non space characters.
*/
bool onlySpaces();
/**
* Replaces all ${paramname} in text with the corresponding parameters
* @param params List of parameters
*/
virtual void replaceParams(const NamedList& params);
private:
String m_text; // The text
};