Пример #1
0
Data::Data(const Arabica::DOM::Node<std::string>& dom) {
	// we may need to convert some keys to arrays if we have the same name as an element
	std::map<std::string, std::list<Data> > arrays;
//  Interpreter::dump(dom);

	if (dom.hasAttributes()) {
		Arabica::DOM::NamedNodeMap<std::string> attributes = dom.getAttributes();
		for (size_t i = 0; i < attributes.getLength(); i++) {
			Arabica::DOM::Node<std::string> attribute = attributes.item(i);
//      Interpreter::dump(attribute);

			assert(attribute.getNodeType() == Arabica::DOM::Node_base::ATTRIBUTE_NODE);
			std::string key = attribute.getLocalName();
			std::string value = attribute.getNodeValue();
			compound[key] = Data(value, VERBATIM);
		}
	}

	if (dom.hasChildNodes()) {
		Arabica::DOM::NodeList<std::string> children = dom.getChildNodes();
		for (size_t i = 0; i < children.getLength(); i++) {
			Arabica::DOM::Node<std::string> child = children.item(i);
//      Interpreter::dump(child);
			std::string key;
			switch (child.getNodeType()) {
			case Arabica::DOM::Node_base::ELEMENT_NODE:
				key = TAGNAME_CAST(child);
				break;
			case Arabica::DOM::Node_base::ATTRIBUTE_NODE:
				key = ((Arabica::DOM::Attr<std::string>)child).getName();
				break;
			case Arabica::DOM::Node_base::TEXT_NODE:
			default:
				break;
			}
			if (key.length() == 0)
				continue;

			if (compound.find(key) != compound.end()) {
				// we already have such a key .. make it an array after we processed all children
				arrays[key].push_back(Data(child));
			} else {
				compound[key] = Data(child);
			}
		}
	} else {
		atom = dom.getNodeValue();
		type = VERBATIM;
	}

	std::map<std::string, std::list<Data> >::iterator arrayIter = arrays.begin();
	while(arrayIter != arrays.end()) {
		assert(compound.find(arrayIter->first) != compound.end());
		Data arrayData;
		arrays[arrayIter->first].push_front(compound[arrayIter->first]);
		arrayData.array = arrays[arrayIter->first];
		compound[arrayIter->first] = arrayData;
	}
}
Пример #2
0
void MMISessionManager::MMIIOProcessor::send(const SendRequest& req) {
	SendRequest reqCopy(req);

	if (req.dom) {
		Arabica::DOM::Node<std::string> mmiEvent = MMIEvent::getEventNode(req.dom);
		if (!mmiEvent || !mmiEvent.getNodeType() == Node_base::ELEMENT_NODE)
			return;

		Arabica::DOM::Element<std::string> mmiElem = Arabica::DOM::Element<std::string>(mmiEvent);
		switch (MMIEvent::getType(mmiEvent)) {
		case MMIEvent::STARTRESPONSE:
		case MMIEvent::PREPARERESPONSE:
		case MMIEvent::PAUSERESPONSE:
		case MMIEvent::RESUMERESPONSE:
		case MMIEvent::CANCELRESPONSE:
		case MMIEvent::DONENOTIFICATION:
		case MMIEvent::NEWCONTEXTRESPONSE:
		case MMIEvent::CLEARCONTEXTRESPONSE:
		case MMIEvent::STATUSRESPONSE: {
			// all of the above have a status
			if (!mmiElem.hasAttributeNS(MMIEvent::nameSpace, "Status")) {
				mmiElem.setAttributeNS(MMIEvent::nameSpace, "Status", "Success");
			}
		}
		case MMIEvent::PAUSEREQUEST:
		case MMIEvent::RESUMEREQUEST:
		case MMIEvent::CANCELREQUEST:
		case MMIEvent::CLEARCONTEXTREQUEST:
		case MMIEvent::STATUSREQUEST: {
			// all of the above have a context
			if (!mmiElem.hasAttributeNS(MMIEvent::nameSpace, "Context")) {
				mmiElem.setAttributeNS(MMIEvent::nameSpace, "Context", _interpreter->getName());
			}
		}
		default: {
			if (!mmiElem.hasAttributeNS(MMIEvent::nameSpace, "Source")) {
				mmiElem.setAttributeNS(MMIEvent::nameSpace, "Source", _sessionManager->getURL());
			}
			if (!mmiElem.hasAttributeNS(MMIEvent::nameSpace, "Target")) {
				if (boost::starts_with(_interpreter->getCurrentEvent().name, "mmi.")) {
					mmiElem.setAttributeNS(MMIEvent::nameSpace, "Target", _interpreter->getCurrentEvent().origin);
				}
			}
			if (!mmiElem.hasAttributeNS(MMIEvent::nameSpace, "RequestID")) {
				if (boost::starts_with(_interpreter->getCurrentEvent().name, "mmi.")) {
					mmiElem.setAttributeNS(MMIEvent::nameSpace, "RequestID", _interpreter->getCurrentEvent().sendid);
				}
			}
		}
		}

		if (MMIEvent::getType(mmiEvent) == MMIEvent::EXTENSIONNOTIFICATION && !mmiElem.hasAttribute("Name") && req.name.length() > 0) {
			mmiElem.setAttribute("Name", req.name);
		}
		// use session mgr to dispatch to session

		_sessionManager->send(_interpreter->getName(), reqCopy);
	}

}
Пример #3
0
NistXmlTestset::NistXmlTestset(const std::string &file)
		: logger_(logkw::channel = "NistXmlTestset") {
	Arabica::SAX2DOM::Parser<std::string> domParser;
	Arabica::SAX::InputSource<std::string> is(file);
	Arabica::SAX::CatchErrorHandler<std::string> errh;
	domParser.setErrorHandler(errh);
	domParser.parse(is);
	if(errh.errorsReported())
		BOOST_LOG_SEV(logger_, error) << errh.errors();

	Arabica::DOM::Document<std::string> doc = domParser.getDocument();
	if(doc == 0) {
		BOOST_LOG_SEV(logger_, error) << "Error parsing input file: " << file;
		exit(1);
	}

	doc.getDocumentElement().normalize();

	Arabica::XPath::XPath<std::string> xp;

	Arabica::XPath::NodeSet<std::string> docnodes =
		xp.compile("/mteval/srcset/doc").evaluateAsNodeSet(doc.getDocumentElement());
	docnodes.to_document_order();
	BOOST_FOREACH(Arabica::DOM::Node<std::string> n, docnodes)
		documents_.push_back(boost::make_shared<NistXmlDocument>(n));

	outdoc_ = static_cast<Arabica::DOM::Document<std::string> >(doc.cloneNode(true));
	Arabica::DOM::Element<std::string> srcset =
		static_cast<Arabica::DOM::Element<std::string> >(
			xp.compile("/mteval/srcset").evaluateAsNodeSet(outdoc_.getDocumentElement())[0]);

	Arabica::DOM::Element<std::string> tstset = outdoc_.createElement("tstset");
	int docno = 0;
	while(srcset.hasChildNodes()) {
		Arabica::DOM::Node<std::string> n = srcset.removeChild(srcset.getFirstChild());
		tstset.appendChild(n);
		if(n.getNodeType() == Arabica::DOM::Node<std::string>::ELEMENT_NODE &&
				n.getNodeName() == "doc")
			documents_[docno++]->setOutputNode(n);
	}
	tstset.setAttribute("setid", srcset.getAttribute("setid"));
	tstset.setAttribute("srclang", srcset.getAttribute("srclang"));
	tstset.setAttribute("trglang", "TRGLANG");
	tstset.setAttribute("sysid", "SYSID");

	srcset.getParentNode().replaceChild(tstset, srcset);
}