From 131f8ca07cdfd85131a762999e09f9ece8e89d78 Mon Sep 17 00:00:00 2001 From: marian Date: Tue, 10 Apr 2018 10:33:00 +0000 Subject: [PATCH] Added replaceParams() to XML fragment, document, element and text. git-svn-id: http://voip.null.ro/svn/yate@6305 acf43c95-373e-0410-b603-e72c3f656dc1 --- engine/XML.cpp | 32 ++++++++++++++++++++++++++++++++ yatexml.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/engine/XML.cpp b/engine/XML.cpp index badf06c1..5a3014d7 100644 --- a/engine/XML.cpp +++ b/engine/XML.cpp @@ -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(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(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 */ diff --git a/yatexml.h b/yatexml.h index 8e94668b..f43d53c2 100644 --- a/yatexml.h +++ b/yatexml.h @@ -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 };