static void readPlugins(const string& id, DOMElement* element, FreeAX25::Runtime::UniquePointerDict<FreeAX25::Runtime::Plugin>& plugins) { if (element == nullptr) return; auto nodeList = element->getElementsByTagName(toX("Plugin")); for (uint32_t i = 0; i < nodeList->getLength(); ++i) { auto pluginNode = static_cast<DOMElement*>(nodeList->item(i)); string name = fmX(pluginNode->getAttribute(toX("name"))); auto _file = pluginNode->getAttribute(toX("file")); string file = (_file != nullptr) ? fmX(_file) : ""; FreeAX25::Runtime::env().logDebug( "Define plugin " + id + "/" + name + "(" + file + ")"); auto plugin = new FreeAX25::Runtime::Plugin(name, file); { // Get settings: auto nodeList = pluginNode->getElementsByTagName(toX("Settings")); if (nodeList->getLength() > 0) readSettings( id + "/" + name, static_cast<DOMElement*>(nodeList->item(0)), plugin->settings); } { // Get instances: auto nodeList = pluginNode->getElementsByTagName(toX("Instances")); if (nodeList->getLength() > 0) readInstances( id + "/" + name, static_cast<DOMElement*>(nodeList->item(0)), plugin->instances); } plugins.insertNew(name, plugin); } // end for // }
static void readInstances(const string& id, DOMElement* element, FreeAX25::Runtime::UniquePointerDict<FreeAX25::Runtime::Instance>& instances) { if (element == nullptr) return; auto nodeList = element->getElementsByTagName(toX("Instance")); for (uint32_t i = 0; i < nodeList->getLength(); ++i) { auto instanceNode = static_cast<DOMElement*>(nodeList->item(i)); string name = fmX(instanceNode->getAttribute(toX("name"))); FreeAX25::Runtime::env().logDebug( "Define instance " + id + "/" + name); auto instance = new FreeAX25::Runtime::Instance(name); { // Get client endpoints: auto nodeList = instanceNode->getElementsByTagName(toX("ClientEndPoint")); for (uint32_t i = 0; i < nodeList->getLength(); ++i) { auto instanceNode = static_cast<DOMElement*>(nodeList->item(i)); string name = fmX(instanceNode->getAttribute(toX("name"))); string url = fmX(instanceNode->getAttribute(toX("url"))); FreeAX25::Runtime::env().logDebug( "Define client endpoint " + id + "/" + name + " as " + url); auto endpoint = new FreeAX25::Runtime::ClientEndPoint(name, url); instance->clientEndPoints.insertNew(name, endpoint); } // end for // } { // Get server endpoints: auto nodeList = instanceNode->getElementsByTagName(toX("ServerEndPoint")); for (uint32_t i = 0; i < nodeList->getLength(); ++i) { auto instanceNode = static_cast<DOMElement*>(nodeList->item(i)); string name = fmX(instanceNode->getAttribute(toX("name"))); string url = fmX(instanceNode->getAttribute(toX("url"))); FreeAX25::Runtime::env().logDebug( "Define server endpoint " + id + "/" + name + " as " + url); auto endpoint = new FreeAX25::Runtime::ServerEndPoint(name, url); instance->serverEndPoints.insertNew(name, endpoint); } // end for // } { // Get settings: auto nodeList = instanceNode->getElementsByTagName(toX("Settings")); if (nodeList->getLength() > 0) readSettings( id + "/" + name, static_cast<DOMElement*>(nodeList->item(0)), instance->settings); } instances.insertNew(name, instance); } // end for // }
result_t XmlElement::getElementsByTagName(exlib::string tagName, obj_ptr<XmlNodeList_base>& retVal) { obj_ptr<XmlNodeList> ret = new XmlNodeList(NULL); getElementsByTagName(tagName, ret); retVal = ret; return 0; }
void XMLRuntime::read(const string& filename, FreeAX25::Runtime::Configuration& config) { XercesDOMParser parser; parser.setValidationScheme(XercesDOMParser::Val_Always); parser.setDoNamespaces(true); parser.setDoSchema(true); parser.setDoXInclude(true); parser.setHandleMultipleImports(true); parser.setValidationSchemaFullChecking(true); parser.setCreateEntityReferenceNodes(false); parser.setIncludeIgnorableWhitespace(false); DOMTreeErrorReporter errReporter; parser.setErrorHandler(&errReporter); parser.parse(filename.c_str()); if (errReporter.getSawErrors()) throw exception(); // Now read configuration from the DOM Tree: XERCES_CPP_NAMESPACE::DOMDocument* doc = parser.getDocument(); assert(doc != nullptr); auto rootElement = doc->getDocumentElement(); auto configName = rootElement->getAttribute(toX("name")); config.setId(fmX(configName)); { // Get settings: auto nodeList = rootElement->getElementsByTagName(toX("Settings")); if (nodeList->getLength() > 0) readSettings( "", static_cast<DOMElement*>(nodeList->item(0)), config.settings); } { // Get plugins: auto nodeList = rootElement->getElementsByTagName(toX("Plugins")); if (nodeList->getLength() > 0) readPlugins( "", static_cast<DOMElement*>(nodeList->item(0)), config.plugins); } }
PassRefPtr<NodeList> ContainerNode::getElementsByTagNameNS(const AtomicString& namespaceURI, const AtomicString& localName) { if (localName.isNull()) return 0; if (namespaceURI == starAtom) return getElementsByTagName(localName); return ensureRareData().ensureNodeLists().addCacheWithQualifiedName(*this, namespaceURI.isEmpty() ? nullAtom : namespaceURI, localName); }
/** * Private, recursive function that gets called by the getElementsByTagName function that is exposed to users. It does a DFS * * @param node The current node at this level of recursion. * @param tagName The tag name being searched for. * @param nodes A vector to hold the list of ElementNode that has a name matching 'tagName' */ void Document::getElementsByTagName (Node* node, const std::string& tagName, vector<ElementNode*>& nodes) { if (node != nullptr) { if (static_cast<ElementNode*>(node)->getName() == tagName) { nodes.push_back(static_cast<ElementNode*>(node)); } vector<Node*> children = node->getChildren(); for (int i = 0; i < children.size(); ++i) { if (dynamic_cast<ElementNode*>(children[i]) == NULL) continue; getElementsByTagName(static_cast<ElementNode*>(children[i]), tagName, nodes); } } return; }
/** * Function exposed to the user, used to get a vector of ElementNode whose name is same as the value passed to the function * * @param tagName The name being searched for, in all the element nodes. * @return A vector of ElementNode* which points to all the element nodes that have a name equal to the value passed to the function */ vector<ElementNode*> Document::getElementsByTagName (const std::string& tagName) { vector<ElementNode*> outputNodes; getElementsByTagName (this->rootElement, tagName, outputNodes); return outputNodes; }