From 1229b07588cac5a33fa44a2a410f0cffe2c961ae Mon Sep 17 00:00:00 2001 From: marian Date: Fri, 10 Jan 2014 11:55:36 +0000 Subject: [PATCH] Added setText function to XML object. Added optional third argument to XML constructor used to take the xml from list parameter instead of making a copy. git-svn-id: http://yate.null.ro/svn/yate/trunk@5712 acf43c95-373e-0410-b603-e72c3f656dc1 --- modules/javascript.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/javascript.cpp b/modules/javascript.cpp index c9a45f62..4cabdb54 100644 --- a/modules/javascript.cpp +++ b/modules/javascript.cpp @@ -432,6 +432,7 @@ public: params().addParam(new ExpFunction("clearChildren")); params().addParam(new ExpFunction("addText")); params().addParam(new ExpFunction("getText")); + params().addParam(new ExpFunction("setText")); params().addParam(new ExpFunction("getChildText")); params().addParam(new ExpFunction("xmlText")); } @@ -1848,6 +1849,14 @@ bool JsXML::runNative(ObjList& stack, const ExpOperation& oper, GenObject* conte else ExpEvaluator::pushOne(stack,JsParser::nullClone()); } + else if (oper.name() == YSTRING("setText")) { + if (argc != 1) + return false; + ExpOperation* text = static_cast(args[0]); + if (!(m_xml && text)) + return false; + m_xml->setText(*text); + } else if (oper.name() == YSTRING("getChildText")) { if (argc > 2) return false; @@ -1880,7 +1889,8 @@ JsObject* JsXML::runConstructor(ObjList& stack, const ExpOperation& oper, GenObj XDebug(&__plugin,DebugAll,"JsXML::runConstructor '%s'("FMT64") [%p]",oper.name().c_str(),oper.number(),this); JsXML* obj = 0; ObjList args; - switch (extractArgs(stack,oper,context,args)) { + int n = extractArgs(stack,oper,context,args); + switch (n) { case 1: { ExpOperation* text = static_cast(args[0]); @@ -1891,12 +1901,15 @@ JsObject* JsXML::runConstructor(ObjList& stack, const ExpOperation& oper, GenObj } break; case 2: + case 3: { JsObject* jso = YOBJECT(JsObject,args[0]); ExpOperation* name = static_cast(args[1]); if (!jso || !name) return 0; - XmlElement* xml = getXml(jso->getField(stack,*name,context),false); + ExpOperation* tmp = static_cast(args[2]); + bool take = tmp && tmp->valBoolean(); + XmlElement* xml = getXml(jso->getField(stack,*name,context),take); if (!xml) return 0; obj = new JsXML(mutex(),xml);